Module gamma

Module gamma 

Source
Expand description

The upper incomplete gamma function Gamma(n, z) of integer and half-integer degree.

upper_gamma takes whichever of the continued fraction, power series, Kummer sum and degree recurrence (DLMF 8) keeps relative accuracy at the argument. ScaledGammaLadder steps through the scaled values Gamma(d, a) / a^d at descending degrees, which the Kambe series sums.

Upstream: incgamma of treams/special/_integrals.pyx, which runs the degree recurrence only. The choice of method and the scaled ladder are treams-rs extensions.

Structsยง

ScaledGammaLadder ๐Ÿ”’
Scaled incomplete gamma functions R(d) = Gamma(d, a) / a^d of one argument at descending degrees d = n, n-1, ...: downward by R(d) = (a R(d+1) - e^-a) / d, which is stable once |d| >= |a|, and above that upward from one upper_gamma evaluation up to LADDER_RUN degrees lower. At a = 0 every value is the limit -1/d. reflected selects the branch -sqrt(a) for half-integer degrees.

Constantsยง

GAMMA_SERIES_RADIUS ๐Ÿ”’
Largest |z| at which gamma_series is used. It needs about 2|z| terms of size up to e^|z|; with the power z^n split in two factors every intermediate stays representable for |n| <= MAX_DEGREE.
LADDER_RUN ๐Ÿ”’
Degrees per upward run of ScaledGammaLadder. Short runs keep the seed far below |a| in degree magnitude, where the continued fraction converges quickly, and avoid evaluating degrees that a short series never reaches.
RECURRENCE_GROWTH ๐Ÿ”’
Largest growth of the relative rounding error accepted from one method without trying another (one digit).
SERIES_PARABOLA ๐Ÿ”’
Bound on |z| + Re z of the parabola around the negative real axis inside which the power series terms share a phase: their cancellation stays below e.

Functionsยง

continued_fraction ๐Ÿ”’
The continued fraction h of DLMF 8.9.2, Gamma(n, z) = z^n e^-z h on the principal branch, with whether it converged.
downward_unstable ๐Ÿ”’
Whether the rounding error of the downward recurrence from base to n grows beyond RECURRENCE_GROWTH: the step to degree d amplifies it by max(1, |z|/|d|).
exp1 ๐Ÿ”’
The exponential integral E1(z) = Gamma(0, z), the start of the integer-degree recurrence. The power series cancels by about e^(|z| + Re z), while the continued fraction converges slowly next to the negative real axis; beyond |z| = 40 the fraction converges there too.
gamma_derivative ๐Ÿ”’
The argument derivative dGamma(n, z)/dz = -z^(n-1) e^-z, with its limits -1 (n = 1) and 0 (n > 1) at z = 0.
gamma_fraction ๐Ÿ”’
Gamma(n, z) from DLMF 8.9.2 by modified Lentz iteration, which keeps relative accuracy for negative degree and large |z| away from the negative real axis, and whether it converged.
gamma_kummer ๐Ÿ”’
The Kummer sum of DLMF 8.7.1 with 8.2.7, Gamma(a, z) = Gamma(a) - z^a e^-z sum_k z^k / (a (a+1) ... (a+k)), whose terms fall at any phase of z for 0 < |z| < a, with the magnitude of the terms as the absolute error bound in units of epsilon.
gamma_recurrence ๐Ÿ”’
The degree recurrence DLMF 8.8.2 from E1 (integer degree) or sqrt(pi) erfc(sqrt z) (half-integer degree), with powers of z updated by one multiplication per step (integer degrees stay real on the real axis), and a first-order bound on the absolute error in units of epsilon from the start value and each endpoint term. modulus is |z|.
gamma_series ๐Ÿ”’
The power series of DLMF 8.7.3, Gamma(a,z) = Gamma(a) - z^a sum_k (-z)^k / (k! (a+k)), whose terms share a phase near the negative real axis; for a = -m, DLMF 8.4.15 replaces the Gamma(a) pole pair by (-1)^m (psi(m+1) - ln z) / m!. The principal logarithm and the signed zero of Im z select the side of the cut; the magnitude of the terms bounds the error.
half_power ๐Ÿ”’
z^degree on the principal branch for an integer or half-integer degree. Integer degrees stay exactly real on the real axis, unlike exp(degree ln z).
inverse ๐Ÿ”’
1/z without squaring |z|: num_complexโ€™s inv() divides by |z|^2, which loses precision below |z| = 1e-154 and underflows to NaN results below 1e-162.
normal ๐Ÿ”’
Whether 1e-290 <= |x| < 1e290, from the larger component of a finite x unless |x| lies near either end (|x| is at most sqrt 2 times that component).
upper_gamma ๐Ÿ”’
The upper incomplete gamma function Gamma(n, z) of integer or half-integer n.