Trisha Shetty (Editor)

Lanczos approximation

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit

In mathematics, the Lanczos approximation is a method for computing the gamma function numerically, published by Cornelius Lanczos in 1964. It is a practical alternative to the more popular Stirling's approximation for calculating the gamma function with fixed precision.

Contents

Introduction

The Lanczos approximation consists of the formula

Γ ( z + 1 ) = 2 π ( z + g + 1 2 ) z + 1 2 e ( z + g + 1 2 ) A g ( z )

for the gamma function, with

A g ( z ) = 1 2 p 0 ( g ) + p 1 ( g ) z z + 1 + p 2 ( g ) z ( z 1 ) ( z + 1 ) ( z + 2 ) + .

Here g is a constant that may be chosen arbitrarily subject to the restriction that Re(z) > 1/2. The coefficients p, which depend on g, are slightly more difficult to calculate (see below). 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,

Γ ( 1 z ) Γ ( z ) = π sin π z .

The series A is convergent, and may be truncated to obtain an approximation with the desired precision. By choosing an appropriate g (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. If a fixed g is chosen, the coefficients can be calculated in advance and the sum is recast into the following form:

A g ( z ) = c 0 + k = 1 N 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. 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 sin x or ex". The method is also implemented in the GNU Scientific Library.

Coefficients

The coefficients are given by

p k ( g ) = a = 0 k C ( 2 k + 1 , 2 a + 1 ) 2 π ( a 1 2 ) ! ( a + g + 1 2 ) ( a + 1 2 ) e a + g + 1 2

with C(i, j) denoting the (i, j)th element of the Chebyshev polynomial coefficient matrix which can be calculated recursively from the identities

C ( 1 , 1 ) = 1 C ( 2 , 2 ) = 1 C ( i , 1 ) = C ( i 2 , 1 ) i = 3 , 4 , C ( i , j ) = 2 C ( i 1 , j 1 ) i = j = 3 , 4 , C ( i , j ) = 2 C ( i 1 , j 1 ) C ( i 2 , j ) i > j = 2 , 3 ,

Paul Godfrey describes how to obtain the coefficients and also the value of the truncated series A as a matrix product.

Derivation

Lanczos derived the formula from Leonhard Euler's integral

Γ ( z + 1 ) = 0 t z e t d t ,

performing a sequence of basic manipulations to obtain

Γ ( z + 1 ) = ( z + g + 1 ) z + 1 e ( z + g + 1 ) 0 e ( v ( 1 log v ) ) z v g d v ,

and deriving a series for the integral.

Simple implementation

The following implementation in the Python programming language works for complex arguments and typically gives 15 correct decimal places:

References

Lanczos approximation Wikipedia