

def gamma_above(a, x):
    'Normalized upper incomplete gamma integral.\n\n    ``(1/\\Gamma(a)) \\int_x^\\infty e^{-t} t^{a - 1} dt``\n\n    gamma_above is the complement of gamma_below:\n\n    ``gamma_above(a, x) = 1 - gamma_below(a, x)``\n\n    As x goes to zero, gamma_above(a, x) converges to 1.\n\n    For x > max(1, a), this is computed by the continued fraction[1]:\n\n                   1\n        -----------------------\n                  1 - s\n        x + -------------------\n                       1\n            1 + ---------------\n                       2 - s\n                x + -----------\n                           2\n                    1 + -------\n                        x + ...\n\n    which is then multiplied by ``x^a e^{-x} / \\Gamma(a)``.\n\n    For x <= max(1, a), this is computed by ``1 - gamma_below(a, x)``.\n\n    [1] Abramowitz & Stegun, p. 263, 6.5.31\n    '
    assert (0.0 < a)
    assert (0.0 <= x)
    if (x <= max(1.0, a)):
        return (1.0 - gamma_below(a, x))
    w = (((x * math.log(x)) - x) - math.lgamma(a))
    if (w < (- MAXLOG)):
        return 0.0
    m = ieee_exp(w)

    def contfrac():
        (yield (1, x))
        i = 0
        while True:
            if ((i % 2) == 0):
                (yield ((((i // 2) + 1) - a), 1))
            else:
                (yield (((i + 1) // 2), x))
            i += 1
    return (m * limit(convergents(contfrac())))

dataset/ETHPy150Open probcomp/bayeslite/src/math_util.py gamma_above/VarMisuse@60/431 `a`->`x`