What is the Log Gamma Function?
The log gamma function, written \(\ln\Gamma(a)\) or \(\ln(\Gamma(a))\), is the natural logarithm of the gamma function \(\Gamma(a)\). The gamma function generalises the factorial to real and complex numbers: for a positive integer \(n\), \(\Gamma(n) = (n-1)!\). Because \(\Gamma(a)\) grows extremely fast, scientists and statisticians almost always work with its logarithm to avoid numerical overflow. lnGamma appears throughout probability (beta and gamma distributions, the chi-squared test), combinatorics, and numerical analysis.
How to use this calculator
Enter the argument \(a\) (any real number) and press calculate. The tool returns \(\ln\Gamma(a)\) in natural log form, plus the base-10 version (Log10 Gamma). For \(a\) greater than 0 the result is a real number. At \(a = 0, -1, -2, -3, \ldots\) the gamma function has poles, so lnGamma is undefined and the calculator reports this. For non-integer negative \(a\), \(\Gamma\) can be negative; the calculator reports the real principal value via the reflection formula.
The formula explained
This calculator uses the Lanczos approximation (\(g = 7\), nine coefficients), a fast and highly accurate closed-form method. With \(x = a - 1\) and \(t = x + 7.5\), it computes a weighted sum \(A\) of the Lanczos coefficients and evaluates
$$\ln\Gamma(a) = \tfrac{1}{2}\ln(2\pi) + \left(x+\tfrac{1}{2}\right)\ln(t) - t + \ln(A).$$For \(a\) less than or equal to 0.5, the reflection formula
$$\Gamma(a)\,\Gamma(1-a) = \frac{\pi}{\sin(\pi a)}$$maps the problem to a value where the Lanczos series converges well.
Worked example
For \(a = 3.5\):
$$\Gamma(3.5) = 2.5 \times 1.5 \times 0.5 \times \sqrt{\pi} = 1.875 \times 1.7724538509 = 3.32335097045.$$Therefore
$$\ln\Gamma(3.5) = \ln(3.32335097045) = 1.20097360234707.$$As a second check, for \(a = 5\) we have \(\Gamma(5) = 4! = 24\), so
$$\ln\Gamma(5) = \ln(24) = 3.17805383034795.$$FAQ
Why use the log of gamma instead of gamma itself? \(\Gamma(a)\) overflows standard floating-point numbers for moderate \(a\) (\(\Gamma(171)\) already exceeds the double range), while lnGamma stays manageable, so log form is the practical choice.
What is lnGamma(1) and lnGamma(2)? Both are 0, because \(\Gamma(1) = \Gamma(2) = 1\) and \(\ln(1) = 0\). The function has a minimum near \(a = 1.4616\).
Is the result exact? The Lanczos approximation is accurate to roughly 15 significant digits for typical arguments, which matches double-precision floating point.