Skip to content

jcboyd/study-no-1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lanczos

The Lanczos approximation, named after Cornelius Lanczos (1893-1974), is a reformulation of the gamma function,

gamma

The gamma function is a vitally important function in many areas of mathematics, such as geometry, calculus, and particularly statistics, where it underpins various density functions such as the chi-squared and Student's t-distribution. The gamma function interpolates the factorial function with,

factorial

which may be seen by integrating by parts. It is the only log-convex function that achieves this. The unfortunate offset is due to Legendre. The gamma function further extends the factorial function to the real and complex domains.

Apart from a few well-defined identities, the gamma function is difficult to evaluate, in contrast with, for example, the error function (erf), which can easily be approximated by a Maclaurin series. Classical approaches to approximating the gamma function utilised Stirling's approximation (see https://github.com/jcboyd/lastchancestats for a derivation). The Lanzcos approximation reformulates the gamma function to include an infinite series,

lanczos

The infinite series expansion is,

series

where g is a freely-chosen positive real. The p coefficients themselves have a complicated formulation, involving the coefficients of Chebyshev polynomials and gamma function identities. To save computation time, the series is reformulated using partial fractions decomposition, producing a new set of coefficients that can be combined in a simplified way. For a well-chosen constant g and a small number of terms in the series, the Lanczos approximation is accurate to within floating-point precision. Consequently, it is scarcely more expensive than computing, say, trigonometric functions, or the exponential function.

The reflection formula is a useful identity due to Euler, that relates the gamma function for positive and negative reals,

reflection

An implementation of the gamma function therefore need only account for complex numbers with positive real part then ''reflect'' any negatives.

This module gives an implementation in C of the gamma function as well as a set of functions used to compute the coefficients. An interface file for SWIG (https://github.com/swig/swig) and setup file is provided for use in Python.

About

An implementation of the Lanczos approximation in C with Python wrapper

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published