rk85
rk85

Reputation: 57

Incomplete gamma function algorithm

There is a very concise algorithm for computing lower incomplete gamma function:

https://people.sc.fsu.edu/~jburkardt/f_src/asa147/asa147.html

We coded this in C++. There is one thing I don't understand in this algorithm. In one place to compute the following expression:

\frac{\gamma(p,x)}{\Gamma(p)}

it is substituted by:

x^p e^{-x}\sum^\infty_{k=0}\frac{x^k}{\Gamma(k+p+1)},

Obviously this is the same, but why it is done like this? Is computing exp of lgamma more efficient than computing tgamma function (both lgamma and tgamma are available in C++)?

Upvotes: 0

Views: 4398

Answers (2)

Severin Pappadeux
Severin Pappadeux

Reputation: 20080

Does computing exp of lgamma is more efficient than computing tgamma function (both lgamma and tgamma are available in C++)?

computing lgamma is more efficient because it is basically n*log(n) behavior. So typically you have good approximation id you're trying to compute lgamma(x)/x function.

also, keep in mind, that lgamma is often used because it is part of expression which could be computed while tgamma, which is growing as fast as factorial, is not. So it is safe to compute whole expression f(x) as exp(log(f(x))), and if f(x) has product of tgamma, then log(f(x)) will have to sum/substract lgamma.

Good way to avoid overflow, basically

Upvotes: 3

Kaveh Vahedipour
Kaveh Vahedipour

Reputation: 3477

You will find proper implementations of the Gamma for c++ here: http://www.boost.org/doc/libs/1_64_0/libs/math/doc/html/math_toolkit/sf_gamma

Upvotes: 0

Related Questions