Skip to content

GammaLn ​

The natural logarithm of Γ(z)\Gamma(z), avoiding the overflow of computing Gamma directly for large z.

✓ checked against that system · ! checked, with disagreements (hover a chip)WikipediaGamma functionMathWorldLogGammaFunctionGammaFunctionWikidataQ190573Encyclopedia of MathematicsGamma-functionnLabGamma functionBritannicascience/gamma-functionDLMF5.2.E1FungrimLogGammaFungrim entryWolfram LanguageLogGamma!
GammaLn(z)ln⁡Γ(z)\ln \Gamma(z), useful where Γ(z)\Gamma(z) itself would overflow.
SageMathlog(gamma(z))!SymPylog(gamma(z))mpmathlog(gamma(z))Juliaenumeratio_ball(z -> log(gamma(z)), z)Rustln_gamma(z)
Typed signatures
TypePackageApplies
(complex | infinity) -> numberanalyticreplaces compute-enginealways
(complex | infinity) -> numbercompute-enginealways

Domain: Special functions

Details
  • Defined via Gamma: GammaLn⁡(z)=ln⁡Γ(z)\operatorname{GammaLn}(z) = \ln \Gamma(z) for z>0z > 0, where Γ\Gamma is positive so no branch-cut ambiguity arises.
  • Called gammaln in MATLAB and SciPy, lgamma in C's math library.
  • Inherits Gamma's recurrence in log form: GammaLn⁡(z+1)=GammaLn⁡(z)+ln⁡z\operatorname{GammaLn}(z+1) = \operatorname{GammaLn}(z) + \ln z.
  • GammaLn⁡(1/2)=12ln⁡π\operatorname{GammaLn}(1/2) = \frac{1}{2}\ln \pi, from Γ(1/2)=π\Gamma(1/2) = \sqrt{\pi}.
  • Diverges to +∞+\infty at the nonpositive integers, the poles of Gamma -- the log of a diverging magnitude, rather than the ComplexInfinity that Gamma itself returns there.
  • GammaLn is the real log-magnitude, not the complex log: for real z<0z<0 it is ln⁡∣Γ(z)∣\ln|\Gamma(z)|, so GammaLn⁡(−0.5)=ln⁡(2π)≈1.2655\operatorname{GammaLn}(-0.5) = \ln(2\sqrt\pi) \approx 1.2655 with no imaginary part, though Γ(−0.5)=−2π<0\Gamma(-0.5) = -2\sqrt\pi < 0. LogGamma is the principal continuation, ln⁡Γ(z)\ln\Gamma(z) analytic off (−∞,0](-\infty, 0]: LogGamma⁡(−0.5)≈1.2655−πi\operatorname{LogGamma}(-0.5) \approx 1.2655 - \pi i (Wolfram's LogGamma[-0.5] and mpmath's loggamma(-0.5), both 1.2655−3.1416i1.2655 - 3.1416i; the principal logarithm of the negative real Γ(−0.5)\Gamma(-0.5) itself would be +πi+\pi i, so it is a third value). Use GammaLn for the magnitude of a real gamma ratio, LogGamma where continuity in zz matters.
  • For complex zz it is ln⁡(Γ(z))\ln(\Gamma(z)) with a PRINCIPAL logarithm, which is not Wolfram's LogGamma\mathrm{LogGamma}: the two differ by multiples of 2πi2\pi i off the positive axis.

Plot

ComplexPlot
real slice

Examples

6 more kept as data, checked against the oracles
Basic #

A pole of Gamma, in log form

live ↗
InGammaLn(0)\mathrm{GammaLn}(0)Out∞∞

A floating-point argument evaluates directly to a high-precision decimal

live ↗
InGammaLn(2.5)\mathrm{GammaLn}(2.5)Out0.284 682 870 472 919 159 6320.284\,682\,870\,472\,919\,159\,632

ln⁡Γ(100.5)\ln\Gamma(100.5), where Γ(100.5)\Gamma(100.5) itself is about 1015710^{157}

live ↗
InGammaLn(100.5)\mathrm{GammaLn}(100.5)Out361.435 540 467 777 621 555361.435\,540\,467\,777\,621\,555
Scope #

At a pole of Gamma, compute-engine gives the real log-magnitude's divergence, PositiveInfinity, rather than treating GammaLn as complex-analytic

live ↗
InGammaLn(−1)\mathrm{GammaLn}(-1)Out∞∞

Complex arguments; here the principal ln⁡Γ(z)\ln\Gamma(z) and Wolfram's LogGamma\mathrm{LogGamma} agree, as the imaginary part stays inside (−π,π](-\pi, \pi]

live ↗
InGammaLn(2.5+3i)\mathrm{GammaLn}(2.5+3i)Out−1.470 954 610 348 842 5+2.822 615 638 260 8i-1.470\,954\,610\,348\,842\,5+2.822\,615\,638\,260\,8i

A huge inexact argument, far past a double, from Stirling's series: ln⁡Γ(101000)≈2.3016×101003\ln\Gamma(10^{1000}) \approx 2.3016 \times 10^{1003}

live ↗
InGammaLn(1.0⋅101000)\mathrm{GammaLn}(1.0\cdot10^{1000})Out230 158 509 299 404 568 402⋅10983230\,158\,509\,299\,404\,568\,402\cdot10^{983}

Threads over a list, and the integer points reduce to ln⁡((n−1)!)\ln((n-1)!), matching Wolfram's LogGamma[5] = Log[24]

live ↗
InGammaLn([1,2,3])\mathrm{GammaLn}(\bigl\lbrack1, 2, 3\bigr\rbrack)Out[0,0,ln⁡(2)]\bigl\lbrack0, 0, \ln(2)\bigr\rbrack

Uncertainty propagation through ln⁡Γ\ln\Gamma, with slope ψ(1.2)\psi(1.2)

live ↗
InGammaLn(Around(1.2,0.01))\mathrm{GammaLn}(\mathrm{Around}(1.2, 0.01))OutAround(−0.085 374 090 003 315 83,0.002 890 398 965 921 884)\mathrm{Around}(-0.085\,374\,090\,003\,315\,83, 0.002\,890\,398\,965\,921\,884)

To 30 significant digits, the last one correctly rounded

live ↗
InN(GammaLn(13),30)N(\mathrm{GammaLn}(\frac{1}{3}), 30)Out0.985 420 646 927 767 069 187 174 036 9780.985\,420\,646\,927\,767\,069\,187\,174\,036\,978

GammaLn is the real log-magnitude ln⁡∣Γ(−0.5)∣=ln⁡(2π)\ln|\Gamma(-0.5)| = \ln(2\sqrt\pi), with no imaginary part where Γ<0\Gamma<0

live ↗
InGammaLn(−0.5)\mathrm{GammaLn}(-0.5)Out1.265 512 123 484 645 396 491.265\,512\,123\,484\,645\,396\,49
Applications #

Used to get ln⁡(n!)\ln(n!) for large n without overflowing float64: ln⁡(10!)=GammaLn⁡(11)\ln(10!) = \operatorname{GammaLn}(11)

live ↗
InGammaLn(11)=ln⁡(10!)\mathrm{GammaLn}(11)=\ln(10!)OutTrue\mathrm{True}
Properties #

Defined as ln⁡Γ(z)\ln \Gamma(z), here at z=5z = 5

live ↗
InGammaLn(5)=ln⁡(Γ(5))\mathrm{GammaLn}(5)=\ln(Γ(5))OutTrue\mathrm{True}

GammaLn⁡(1)=ln⁡Γ(1)=ln⁡1=0\operatorname{GammaLn}(1) = \ln \Gamma(1) = \ln 1 = 0

live ↗
InGammaLn(1)=0\mathrm{GammaLn}(1)=0OutTrue\mathrm{True}

Inherits Gamma's recurrence: GammaLn⁡(z+1)=GammaLn⁡(z)+ln⁡z\operatorname{GammaLn}(z+1) = \operatorname{GammaLn}(z) + \ln z

live ↗
InGammaLn(6)=GammaLn(5)+ln⁡(5)\mathrm{GammaLn}(6)=\mathrm{GammaLn}(5)+\ln(5)OutTrue\mathrm{True}

GammaLn⁡(1/2)=12ln⁡π\operatorname{GammaLn}(1/2) = \frac12 \ln \pi, from Γ(1/2)=π\Gamma(1/2) = \sqrt{\pi}

live ↗
InGammaLn(12)=ln⁡(π)2\mathrm{GammaLn}(\frac{1}{2})=\frac{\ln(π)}{2}OutTrue\mathrm{True}

An exact positive integer now reduces too, matching Wolfram's LogGamma[5] = Log[24] (ln⁡24=3ln⁡2+ln⁡3\ln 24 = 3\ln 2 + \ln 3, compute-engine's own factored form for ln⁡\ln of a composite)

live ↗
InGammaLn(5)\mathrm{GammaLn}(5)Out3ln⁡(2)+ln⁡(3)3\ln(2)+\ln(3)

The derivative of ln⁡Γ\ln\Gamma is the digamma function. See Digamma

live ↗
IndGammaLn(x)dx\frac{\mathrm{d}\mathrm{GammaLn}(x)}{\mathrm{d}x}OutDigamma(x)\mathrm{Digamma}(x)
Possible issues #

Off the positive axis GammaLn is the principal ln⁡Γ(z)\ln\Gamma(z): at z=−3/2z = -3/2, where Γ>0\Gamma > 0, that is real. See LogGamma for the continuation

live ↗
InGammaLn(−1.5)\mathrm{GammaLn}(-1.5)Out0.860 047 015 376 481 014 5110.860\,047\,015\,376\,481\,014\,511
Neat examples #

GammaLn⁡(101)\operatorname{GammaLn}(101) is exactly ln⁡(100!)\ln(100!), letting us reason about the size of the 158-digit number 100!100! without computing it

live ↗
InGammaLn(101)=ln⁡(100!)\mathrm{GammaLn}(101)=\ln(100!)OutTrue\mathrm{True}
About
Examples25
Checked againstWolfram Language 20 agree4 differSageMath 20 agree1 differ2 unevaluatedSymPy 19 agree2 differ3 unevaluatedmpmath 17 agree3 unevaluated3 errorJulia 17 agree1 differ3 unevaluated2 errorRust 10 agree3 differ5 error
CrosswalkWikipediaMathWorld ×2WikidataEncyclopedia of MathematicsnLabBritannicaDLMFFungrimFungrim entry ×16Wolfram LanguageSageMathSymPympmathJuliaRust

Implementation

mappedwolframpackages/oracle/src/mappings.ts

The principal logarithm of Gamma, not LogGamma, which is the continuation.

mappedsympypackages/oracle/src/mappings.ts

The principal logarithm of Gamma, not SymPy's loggamma (the continuation, which is LogGamma here). At a negative real where Gamma is negative it adds pi i to the real log-magnitude GammaLn takes.

mappedmpmathpackages/oracle/src/mappings.ts
mappedsagepackages/oracle/src/mappings.ts
mappedjuliapackages/oracle/src/mappings.ts
mappedrustpackages/oracle/src/mappings.ts

See also: Gamma, LogGamma, Digamma