Lanczos approximation
In mathematics, the Lanczos approximation is a method for computing the gamma function numerically, published by Cornelius Lanczos in 1964.[src] It is a practical alternative to the more popular Stirling's approximation for calculating the gamma function with fixed precision.[src]
In mathematics, the Lanczos approximation is a method for computing the gamma function numerically, published by Cornelius Lanczos in 1964.[src] It is a practical alternative to the more popular Stirling's approximation for calculating the gamma function with fixed precision.[src] ==Introduction== The Lanczos approximation consists of the formula \Gamma(z+1) = \sqrt{2\pi} {\left( z + g + \tfrac12 \right)}^{z + \frac12 } e^{-\left(z+g+\frac12\right)} A_g(z) for the gamma function, with A_g(z) = \tfrac12p_0(g) + p_1(g) \frac{z}{z+1} + p_2(g) \frac{z(z-1)}{(z+1)(z+2)} + \cdots.[src] Here is a real constant that may be chosen arbitrarily subject to the restriction that .[src] The coefficients , which depend on , are slightly more difficult to calculate (see below).[src] Although the formula as stated here is only valid for arguments in the right complex half-plane, it can be extended to the entire complex plane by the reflection formula, \Gamma(1-z) \; \Gamma(z) = \frac{\pi }{ \sin \pi z}.[src] The series is convergent, and may be truncated to obtain an approximation with the desired precision.[src] By choosing an appropriate (typically a small integer), only some 5–10 terms of the series are needed to compute the gamma function with typical single or double floating-point precision.[src] If a fixed is chosen, the coefficients can be calculated in advance and, thanks to partial fraction decomposition, the sum is recast into the following form: A_g(z) = c_0 + \sum_{k=1}^{N} \frac{c_k}{z+k} Thus computing the gamma function becomes a matter of evaluating only a small number of elementary functions and multiplying by stored constants.[src] The Lanczos approximation was popularized by Numerical Recipes, according to which computing the gamma function becomes "not much more difficult than other built-in functions that we take for granted, such as or ." The method is also implemented in the GNU Scientific Library, Boost, CPython and musl.[src] ==Coefficients== The coefficients are given by p_k(g) = \frac{\sqrt{2}}{\pi} \sum_{l=0}^k C_{2k+1,\,2l+1} \left(l - \tfrac{1}{2} \right)![src] {\left(l + g + \tfrac{1}{2} \right)}^{-\left(l+\frac12\right)} e^{l + g + \frac12 } where represents the th element of the matrix of coefficients for the Chebyshev polynomials, which can be calculated recursively from these identities: \begin{align} C_{1,\,1} &= 1 \\[5px] C_{2,\,2} &= 1 \\[5px] C_{n+1,\,1} &= -\,C_{n-1,\,1} & \text{ for } n &= 2, 3, 4\, \dots \\[5px] C_{n+1,\,n+1} &= 2\,C_{n,\,n} & \text{ for } n &= 2, 3, 4\, \dots \\[5px] C_{n+1,\,m+1} &= 2\,C_{n,\,m} - C_{n-1,\,m+1} & \text{ for } n & > m = 1, 2, 3\, \dots \end{align} Godfrey (2001) describes how to obtain the coefficients and also the value of the truncated series as a matrix product with good precision in floating-point.[src] ==Derivation== Lanczos derived the formula from Leonhard Euler's integral \Gamma(z+1) = \int_0^\infty t^{z}\,e^{-t}\,dt, performing a sequence of basic manipulations to obtain \Gamma(z+1) = \left(z+g+1\right)^{z+1} e^{-(z+g+1)} \int_0^e \bigl(v(1-\log v)\bigr)^{z} v^g\,dv, and deriving a series for the integral.[src] ==Simple implementation== The following implementation in the Python programming language works for complex arguments and typically gives 13 correct decimal places.[src] Note that omitting the smallest coefficients (in pursuit of speed, for example) gives totally inaccurate results; the coefficients must be recomputed from scratch for an expansion with fewer terms.[src] from cmath import sin, sqrt, pi, exp Constant g and Coefficients p_k(g) G = 7 P = [ 0.99999999999980993, 676.5203681218851, -1259.1392167224028, 771.32342877765313, -176.61502916214059, 12.507343278686905, -0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7 ] EPSILON = 1e-07 def drop_imag(z: complex) -> float | complex: """Turn (a+bj) into a when |b| float | complex: z = complex(z) if z.real ==See also== Stirling's approximation Spouge's approximation ==References==[src]
18 sentences · 18 cited inline · 0 references stored
References
No reference rows published for this article.
Cite this article
MLA
"Lanczos approximation." encyclopegia.org, 2026, https://encyclopegia.org/wiki/lanczos-approximation. Accessed 26 November 2026.
Chicago
"Lanczos approximation." encyclopegia.org. Accessed November 26, 2026. https://encyclopegia.org/wiki/lanczos-approximation.
APA
encyclopegia.org. (2026). Lanczos approximation. Retrieved November 26, 2026, from https://encyclopegia.org/wiki/lanczos-approximation
Accessed November 26, 2026 · CC BY-SA 4.0 · citation page · JSON
Claims
| Predicate | Value | Source |
|---|---|---|
| publication date | 1964 | Wikipedia |