def incomplete_gamma_lower(a, x, precision=9):
# Numerical approximation of the lower incomplete gamma function to the given precision
# https://en.wikipedia.org/wiki/Incomplete_gamma_function
# http://mathworld.wolfram.com/IncompleteGammaFunction.html
max_diff = 10 ** -precision
def summand(k):
return ((-x) ** k) / factorial(k) / (a + k)
xs = x ** a
sum_ = summand(0)
prev_value = xs * sum_ # for k=0
sum_ += summand(1)
cur_value = xs * sum_ # for k=1
k = 1
while abs(cur_value - prev_value) > max_diff:
k += 1
prev_value = cur_value
sum_ += summand(k)
cur_value = xs * sum_
return cur_value
评论列表
文章目录