GammaLn
The natural logarithm of , avoiding the overflow of computing Gamma directly for large z.
Gamma functionMathWorldLogGammaFunctionGammaFunctionWikidataQ190573Encyclopedia of MathematicsGamma-functionnLabGamma functionBritannicascience/gamma-functionDLMF5.2.E1FungrimLogGammaFungrim entryWolfram LanguageLogGamma!GammaLn(z), useful where itself would overflow.log(gamma(z))!SymPylog(gamma(z))mpmathlog(gamma(z))Juliaenumeratio_ball(z -> log(gamma(z)), z)Rustln_gamma(z)Typed signatures
| Type | Package | Applies |
|---|---|---|
(complex | infinity) -> number | analyticreplaces compute-engine | always |
(complex | infinity) -> number | compute-engine | always |
Details
- Defined via Gamma: for , where 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: .
- , from .
- Diverges to 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 it is , so with no imaginary part, though . LogGamma is the principal continuation, analytic off : (Wolfram's
LogGamma[-0.5]and mpmath'sloggamma(-0.5), both ; the principal logarithm of the negative real itself would be , so it is a third value). Use GammaLn for the magnitude of a real gamma ratio, LogGamma where continuity in matters. - For complex it is with a PRINCIPAL logarithm, which is not Wolfram's : the two differ by multiples of off the positive axis.
Plot
Examples
6 more kept as data, checked against the oraclesBasic #
Scope #
At a pole of Gamma, compute-engine gives the real log-magnitude's divergence, PositiveInfinity, rather than treating GammaLn as complex-analytic
live ↗Complex arguments; here the principal and Wolfram's agree, as the imaginary part stays inside
live ↗Threads over a list, and the integer points reduce to , matching Wolfram's LogGamma[5] = Log[24]
live ↗Properties #
An exact positive integer now reduces too, matching Wolfram's LogGamma[5] = Log[24] (, compute-engine's own factored form for of a composite)
live ↗Possible issues #
Neat examples #
is exactly , letting us reason about the size of the 158-digit number without computing it
live ↗About
| Examples | 25 |
|---|---|
| Checked against | Wolfram 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 |
| Crosswalk | WikipediaMathWorld ×2WikidataEncyclopedia of MathematicsnLabBritannicaDLMFFungrimFungrim entry ×16Wolfram LanguageSageMathSymPympmathJuliaRust |
Implementation
wolframpackages/oracle/src/mappings.tsThe principal logarithm of Gamma, not LogGamma, which is the continuation.
sympypackages/oracle/src/mappings.tsThe 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.
mpmathpackages/oracle/src/mappings.tssagepackages/oracle/src/mappings.tsjuliapackages/oracle/src/mappings.tsrustpackages/oracle/src/mappings.ts