

def gamma_below(a, x):
    'Normalized lower incomplete gamma integral.\n\n    ``(1/\\Gamma(a)) \\int_0^x e^{-t} t^{a - 1} dt``\n\n    gamma_below is the complement of gamma_above:\n\n    ``gamma_below(a, x) = 1 - gamma_above(a, x)``\n\n    As x grows, gamma_below(a, x) converges to 1.\n\n    For x <= max(1, a), this is computed by the power series[1]:\n\n         x^a e^-x   /           x^2            x^3                   ----------- | 1 + x + ------- + -------------- + ... |\n        a \\Gamma(a) \\         (a + 1)   (a + 1)(a + 2)       /\n\n    For x > max(1, a), this is computed by ``1 - gamma_above(a, x)``.\n\n\n    [1] NIST Digital Library of Mathematical Functions, Release 1.0.9\n    of 2014-08-29, Eq. 8.7.1 <http://dlmf.nist.gov/8.7.E1>.\n\n    In the NIST DLMF notation, ``gamma_below(a, x)`` is ``P(a, x)``,\n    related to ``\\gamma^*`` by ``\\gamma^*(a, x) = x^{-a} P(a, x)``.\n\n    To derive the power series, multiply (8.7.1) by ``x^a``, expand\n    ``\\Gamma(a + k + 1)`` into ``\\Gamma(a) a(a + 1)...(a + k)``, and\n    factor ``a \\Gamma(a)`` out of the sum.\n    '
    assert (0.0 < a)
    assert (0.0 <= x)
    if (x == 0.0):
        return 0.0
    if (x > max(1.0, a)):
        return (1.0 - gamma_above(a, x))
    w = (((a * math.log(x)) - x) - math.lgamma(a))
    if (w < (- MAXLOG)):
        return 0.0
    m = ieee_exp(w)

    def seq():
        k = 0
        t = 1.0
        while True:
            (yield t)
            k += 1
            t *= (x / (a + k))
    return ((m / x) * abs_summation(seq()))

dataset/ETHPy150Open probcomp/bayeslite/src/math_util.py gamma_below/VarMisuse@166/725 `a`->`x`