Gamma Module

Approximations for the gamma function and related functions. The gamma function (represented by Γ, the capital letter gamma from the Greek alphabet) is one commonly used extension of the factorial function to complex numbers: Γ(x) = (x-1)! The gamma function is defined for all complex numbers except the non-positive integers.

Functions and values

Function or value Description

_gamma z

Full Usage: _gamma z

Parameters:
    z : float - The function input for approximating Γ(z)

Returns: float

Computes an approximation of the real value of the gamma function using the Lanczos Coefficients described in Numerical Recipes (Press et al)

The caller is responsible to handle edge cases such as nan, infinity, and -infinity in the input

z : float

The function input for approximating Γ(z)

Returns: float

_gammaLn z

Full Usage: _gammaLn z

Parameters:
    z : float - The function input for approximating ln(Γ(z))

Returns: float

Computes an approximation of the real value of the log gamma function using the Lanczos Coefficients described in Numerical Recipes (Press et al)

The caller is responsible to handle edge cases such as nan, infinity, and -infinity in the input

z : float

The function input for approximating ln(Γ(z))

Returns: float

digamma x

Full Usage: digamma x

Parameters:
    x : float

Returns: float

Digamma function.

x : float
Returns: float

gamma z

Full Usage: gamma z

Parameters:
    z : float - The function input for approximating Γ(z)

Returns: float

Computes an approximation of the real value of the gamma function using the Lanczos Coefficients described in Numerical Recipes (Press et al)

Edge cases in the input (nan, infinity, and -infinity) are catched and handled. This might be slower than the unchecked version `_gamma` but does not require input sanitation to get expected results for these cases.

z : float

The function input for approximating Γ(z)

Returns: float

gammaLn z

Full Usage: gammaLn z

Parameters:
    z : float - The function input for approximating ln(Γ(z))

Returns: float

Computes an approximation of the real value of the log gamma function using the Lanczos Coefficients described in Numerical Recipes (Press et al)

Edge cases in the input (nan, infinity, and -infinity) are catched and handled. This might be slower than the unchecked version `_gamma` but does not require input sanitation to get expected results for these cases.

z : float

The function input for approximating ln(Γ(z))

Returns: float

lowerIncomplete a x

Full Usage: lowerIncomplete a x

Parameters:
    a : float -
    x : float -

Returns: float

Returns the lower incomplete gamma function
gamma(a,x) = int(exp(-t)t^(a-1),t=0..x) for real a > 0, x > 0.

a : float

x : float

Returns: float

Example

lowerIncompleteRegularized a x

Full Usage: lowerIncompleteRegularized a x

Parameters:
    a : float
    x : float

Returns: float

Returns the incomplete gamma function P(a,X) (regularized gamma)

a : float
x : float
Returns: float

maximum

Full Usage: maximum

Returns: float

Maximum gamma

Returns: float

trigamma x

Full Usage: trigamma x

Parameters:
    x : float

Returns: float

Trigamma function.

This code has been adapted from the FORTRAN77 and subsequent C code by B. E. Schneider and John Burkardt. The code had been made public under the GNU LGPL license.

x : float
Returns: float

upperIncomplete a x

Full Usage: upperIncomplete a x

Parameters:
    a : float -
    x : float -

Returns: float

Returns the upper incomplete gamma function
Gamma(a,x) = int(exp(-t)t^(a-1),t=0..x) for real a > 0, x > 0.

a : float

x : float

Returns: float

Example

upperIncompleteRegularized a x

Full Usage: upperIncompleteRegularized a x

Parameters:
    a : float
    x : float

Returns: float

Returns the incomplete gamma function Q(a,X) = 1 - P(a,X) (regularized gamma)

a : float
x : float
Returns: float