Lanczos approximation

Last updated

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

for the gamma function, with

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

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, thanks to partial fraction decomposition, the sum is recast into the following form:

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, Boost, CPython and musl.

Coefficients

The coefficients are given by

where represents the (n, m)th element of the matrix of coefficients for the Chebyshev polynomials, which can be calculated recursively from these identities:

Godfrey (2001) describes how to obtain the coefficients and also the value of the truncated series A as a matrix product. [2]

Derivation

Lanczos derived the formula from Leonhard Euler's integral

performing a sequence of basic manipulations to obtain

and deriving a series for the integral.

Simple implementation

The following implementation in the Python programming language works for complex arguments and typically gives 13 correct decimal places. 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.

fromcmathimportsin,sqrt,pi,exp"""The coefficients used in the code are for when g = 7 and n = 9Here are some other samplesg = 5n = 5p = [    1.0000018972739440364,    76.180082222642137322,    -86.505092037054859197,    24.012898581922685900,    -1.2296028490285820771]g = 5n = 7p = [    1.0000000001900148240,    76.180091729471463483,    -86.505320329416767652,    24.014098240830910490,    -1.2317395724501553875,    0.0012086509738661785061,    -5.3952393849531283785e-6]g = 8n = 12p = [    0.9999999999999999298,    1975.3739023578852322,    -4397.3823927922428918,    3462.6328459862717019,    -1156.9851431631167820,    154.53815050252775060,    -6.2536716123689161798,    0.034642762454736807441,    -7.4776171974442977377e-7,    6.3041253821852264261e-8,    -2.7405717035683877489e-8,    4.0486948817567609101e-9]"""g=7n=9p=[0.99999999999980993,676.5203681218851,-1259.1392167224028,771.32342877765313,-176.61502916214059,12.507343278686905,-0.13857109526572012,9.9843695780195716e-6,1.5056327351493116e-7]EPSILON=1e-07defdrop_imag(z):ifabs(z.imag)<=EPSILON:z=z.realreturnzdefgamma(z):z=complex(z)ifz.real<0.5:y=pi/(sin(pi*z)*gamma(1-z))# Reflection formulaelse:z-=1x=p[0]foriinrange(1,len(p)):x+=p[i]/(z+i)t=z+g+0.5y=sqrt(2*pi)*t**(z+0.5)*exp(-t)*xreturndrop_imag(y)"""The above use of the reflection (thus the if-else structure) is necessary, even though it may look strange, as it allows to extend the approximation to values of z where Re(z) < 0.5, where the Lanczos method is not valid."""print(gamma(1))print(gamma(5))print(gamma(0.5))

See also

Related Research Articles

<span class="mw-page-title-main">Gamma function</span> Extension of the factorial function

In mathematics, the gamma function is one commonly used extension of the factorial function to complex numbers. The gamma function is defined for all complex numbers except the non-positive integers. For every positive integer n,

<span class="mw-page-title-main">Stirling's approximation</span> Approximation for factorials

In mathematics, Stirling's approximation is an asymptotic approximation for factorials. It is a good approximation, leading to accurate results even for small values of . It is named after James Stirling, though a related but less precise result was first stated by Abraham de Moivre.

<span class="mw-page-title-main">Error function</span> Sigmoid shape special function

In mathematics, the error function, often denoted by erf, is a function defined as:

<span class="mw-page-title-main">Fabry–Pérot interferometer</span> Optical device with parallel mirrors

In optics, a Fabry–Pérot interferometer (FPI) or etalon is an optical cavity made from two parallel reflecting surfaces. Optical waves can pass through the optical cavity only when they are in resonance with it. It is named after Charles Fabry and Alfred Perot, who developed the instrument in 1899. Etalon is from the French étalon, meaning "measuring gauge" or "standard".

<span class="mw-page-title-main">Spherical harmonics</span> Special mathematical functions defined on the surface of a sphere

In mathematics and physical science, spherical harmonics are special functions defined on the surface of a sphere. They are often employed in solving partial differential equations in many scientific fields. The table of spherical harmonics contains a list of common spherical harmonics.

<span class="mw-page-title-main">Beta function</span> Mathematical function

In mathematics, the beta function, also called the Euler integral of the first kind, is a special function that is closely related to the gamma function and to binomial coefficients. It is defined by the integral

<span class="mw-page-title-main">Airy function</span> Special function in the physical sciences

In the physical sciences, the Airy function (or Airy function of the first kind) Ai(x) is a special function named after the British astronomer George Biddell Airy (1801–1892). The function Ai(x) and the related function Bi(x), are linearly independent solutions to the differential equation

<span class="mw-page-title-main">Digamma function</span> Mathematical function

In mathematics, the digamma function is defined as the logarithmic derivative of the gamma function:

<span class="mw-page-title-main">Particle in a spherically symmetric potential</span> Quantum mechanical model

In quantum mechanics, a spherically symmetric potential is a system of which the potential only depends on the radial distance from the spherical center and a location in space. A particle in a spherically symmetric potential will behave accordingly to said potential and can therefore be used as an approximation, for example, of the electron in a hydrogen atom or of the formation of chemical bonds.

<span class="mw-page-title-main">Voigt profile</span> Probability distribution

The Voigt profile is a probability distribution given by a convolution of a Cauchy-Lorentz distribution and a Gaussian distribution. It is often used in analyzing data from spectroscopy or diffraction.

<span class="mw-page-title-main">Stieltjes constants</span>

In mathematics, the Stieltjes constants are the numbers that occur in the Laurent series expansion of the Riemann zeta function:

<span class="mw-page-title-main">Reciprocal gamma function</span> Mathematical function

In mathematics, the reciprocal gamma function is the function

In q-analog theory, the -gamma function, or basic gamma function, is a generalization of the ordinary gamma function closely related to the double gamma function. It was introduced by Jackson (1905). It is given by

In mathematics, Spouge's approximation is a formula for computing an approximation of the gamma function. It was named after John L. Spouge, who defined the formula in a 1994 paper. The formula is a modification of Stirling's approximation, and has the form

The Wigner D-matrix is a unitary matrix in an irreducible representation of the groups SU(2) and SO(3). It was introduced in 1927 by Eugene Wigner, and plays a fundamental role in the quantum mechanical theory of angular momentum. The complex conjugate of the D-matrix is an eigenfunction of the Hamiltonian of spherical and symmetric rigid rotors. The letter D stands for Darstellung, which means "representation" in German.

In mathematics, the Schur orthogonality relations, which were proven by Issai Schur through Schur's lemma, express a central fact about representations of finite groups. They admit a generalization to the case of compact groups in general, and in particular compact Lie groups, such as the rotation group SO(3).

In mathematics, Maass forms or Maass wave forms are studied in the theory of automorphic forms. Maass forms are complex-valued smooth functions of the upper half plane, which transform in a similar way under the operation of a discrete subgroup of as modular forms. They are eigenforms of the hyperbolic Laplace operator defined on and satisfy certain growth conditions at the cusps of a fundamental domain of . In contrast to modular forms, Maass forms need not be holomorphic. They were studied first by Hans Maass in 1949.

Gregory coefficientsGn, also known as reciprocal logarithmic numbers, Bernoulli numbers of the second kind, or Cauchy numbers of the first kind, are the rational numbers that occur in the Maclaurin series expansion of the reciprocal logarithm

In representation theory of mathematics, the Waldspurger formula relates the special values of two L-functions of two related admissible irreducible representations. Let k be the base field, f be an automorphic form over k, π be the representation associated via the Jacquet–Langlands correspondence with f. Goro Shimura (1976) proved this formula, when and f is a cusp form; Günter Harder made the same discovery at the same time in an unpublished paper. Marie-France Vignéras (1980) proved this formula, when and f is a newform. Jean-Loup Waldspurger, for whom the formula is named, reproved and generalized the result of Vignéras in 1985 via a totally different method which was widely used thereafter by mathematicians to prove similar formulas.

References

  1. Pugh, Glendon (2004). An analysis of the Lanczos Gamma approximation (PDF) (Ph.D.).
  2. Godfrey, Paul (2001). "Lanczos implementation of the gamma function". Numericana.