# Lanczos approximation

Lanczos approximation

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.

Introduction

The Lanczos approximation consists of the formula

:$Gamma\left(z+1\right) = sqrt\left\{2pi\right\} \left\{left\left( z + g + frac\left\{1\right\}\left\{2\right\} ight\right)\right\}^\left\{z + frac\left\{1\right\}\left\{2\right\} \right\} e^\left\{-left\left(z+g+frac\left\{1\right\}\left\{2\right\} ight\right)\right\} A_g\left(z\right)$

for the Gamma function, with

:$A_g\left(z\right) = frac\left\{1\right\}\left\{2\right\}p_0\left(g\right) + p_1\left(g\right) frac\left\{z\right\}\left\{z+1\right\} + p_2\left(g\right) frac\left\{z\left(z-1\right)\right\}\left\{\left(z+1\right)\left(z+2\right)\right\} + cdots.$

Here "g" is a constant that may be chosen arbitrarily subject to the restriction that Re("z"+"g"+1/2) > 0. 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,

:$Gamma\left(1-z\right) ; Gamma\left(z\right) = \left\{pi over sin pi z\right\}.$

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\left(z\right) = c_0 + sum_\left\{k=1\right\}^\left\{N\right\} frac\left\{c_k\right\}\left\{z+k\right\}$

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 "e""x"". The method is also implemented in the GNU Scientific Library.

Coefficients

The coefficients are given by:

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

:

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:$Gamma\left(z+1\right) = int_0^infty t^\left\{z\right\},e^\left\{-t\right\},dt,$

performing a sequence of basic manipulations to obtain

:$Gamma\left(z+1\right) = \left(z+g+1\right)^\left\{z+1\right\} e^\left\{-\left(z+g+1\right)\right\} int_0^e \left[v\left(1-log v\right)\right] ^\left\{z-frac\left\{1\right\}\left\{2 v^g,dv,$

and deriving a series for the integral.

imple implementation

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

from cmath import *

# Coefficients used by the GNU Scientific Libraryg = 7p = [0.99999999999980993, 676.5203681218851, -1259.1392167224028, 771.32342877765313, -176.61502916214059, 12.507343278686905, -0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7]

def gamma(z): z = complex(z) # Reflection formula if z.real < 0.5: return pi / (sin(pi*z)*gamma(1-z)) else: z -= 1 x = p  for i in range(1, g+2): x += p [i] /(z+i) t = z + g + 0.5 return sqrt(2*pi) * t**(z+0.5) * exp(-t) * x

References

* Godfrey, Paul (2001). [http://home.att.net/~numericana/answer/info/godfrey.htm Lanczos Implementation of the Gamma Function]
* cite journal
last = Lanczos
first = Cornelius
title = A Precision Approximation of the Gamma Function
journal = [http://www.siam.org/journals/sinum.php SIAM Journal on Numerical Analysis series B]
volume = 1
pages = pp.86–96
date = 1964
publisher = Society for Industrial and Applied Mathematics
id = ISSN: 0887459X

* Press, William et al. [http://www.library.cornell.edu/nr/cbookcpdf.html "Numerical Recipes in C"] . (Second edition, Cambridge University Press 1992). ISBN 0-521-43108-5
* Pugh, Glendon (2004). [http://web.mala.bc.ca/pughg/phdThesis/phdThesis.pdf An analysis of the Lanczos Gamma approximation]
* Toth, Viktor (2005). [http://www.rskey.org/lanczos.htm Programmable Calculators: The Lanczos Approximation]
*

Wikimedia Foundation. 2010.

### Look at other dictionaries:

• Cornelius Lanczos — Lanczos redirects here. For resampling method, see Lanczos resampling. Cornelius Lanczos Born February 2, 1893(1893 02 02) Székesfehérvár Died …   Wikipedia

• Lanczos — Cornelius Lanczos ([ˈlaːntsoʃ]; auch Kornél Löwy, Kornél Lánczos), (* 2. Februar 1893 in Székesfehérvár, Österreich Ungarn; † 25. Juni 1974 in Budapest) war ein ungarischer Mathematiker und Physiker. Inhaltsverzeichnis 1 Leben 2 Werk …   Deutsch Wikipedia

• Approximation sigma — En mathématiques, l’approximation sigma, imaginée par Cornelius Lanczos, est une méthode de fenêtrage qui permet d ajuster une série de Fourier pour éliminer le phénomène de Gibbs qui pourrait survenir aux discontinuités. Principe Une… …   Wikipédia en Français

• Spouge's approximation — In mathematics, Spouge s approximation is a formula for the gamma function due to John L. Spouge. The formula is a modification of Stirling s approximation, and has the form:Gamma(z+1) = (z+a)^{z+1/2} e^{ (z+a)} left [ c 0 + sum {k=1}^{a 1}… …   Wikipedia

• Stirling's approximation — In mathematics, Stirling s approximation (or Stirling s formula) is an approximation for large factorials. It is named in honour of James Stirling.The formula is written as:n! approx sqrt{2pi n}, left(frac{n}{e} ight)^{n}.Roughly, this means that …   Wikipedia

• Cornelius Lanczos — ((hu) Lánczos Kornél) (né Kornél Löwy le 2 février 1893 à Székesfehérvár – 25 juin 1974 à Budapest) était un mathématicien et physicien hongrois. Sommaire 1 Biographie 2 Annexes …   Wikipédia en Français

• Cornelius Lanczos — ([ˈlaːntsoʃ]; auch Kornél Löwy, Kornél Lánczos; * 2. Februar 1893 in Székesfehérvár, Österreich Ungarn; † 25. Juni 1974 in Budapest) war ein ungarischer Mathematiker und Physiker. Inhaltsverzeichnis 1 Leben 2 Werk …   Deutsch Wikipedia

• Sigma approximation — In mathematics, σ approximation adjusts a Fourier summation to eliminate the Gibbs phenomenon which would otherwise occur at discontinuities. A σ approximated summation for a series of period T can be written as follows::s( heta) = frac{1}{2} a 0 …   Wikipedia

• List of numerical analysis topics — This is a list of numerical analysis topics, by Wikipedia page. Contents 1 General 2 Error 3 Elementary and special functions 4 Numerical linear algebra …   Wikipedia

• Gamma function — For the gamma function of ordinals, see Veblen function. The gamma function along part of the real axis In mathematics, the gamma function (represented by the capital Greek letter Γ) is an extension of the factorial function, with its… …   Wikipedia