Approximations
Complex values of the gamma function can be computed numerically with arbitrary precision using Stirling's approximation or the Lanczos approximation.
The gamma function can be computed to fixed precision for Re(z) ∈ by applying integration by parts to Euler's integral. For any positive number x the gamma function can be written
When Re(z) ∈ and x ≥ 1, the absolute value of the last integral is smaller than (x + 1) e−x. By choosing x large enough, this last expression can be made smaller than 2−N for any desired value N. Thus, the gamma function can be evaluated to N bits of precision with the above series.
The only fast algorithm for calculation of the Euler gamma function for any algebraic argument (including rational) was constructed by E.A. Karatsuba, see for details "Fast Algorithms and the FEE Method".
For arguments that are integer multiples of 1/24 the gamma function can also be evaluated quickly using arithmetic-geometric mean iterations (see particular values of the gamma function).
Because the Gamma and factorial functions grow so rapidly for moderately large arguments, many computing environments include a function that returns the natural logarithm of the gamma function (often given the name lngamma in programming environments or gammaln in spreadsheets); this grows much more slowly, and for combinatorial calculations allows adding and subtracting logs instead of multiplying and dividing very large values. The digamma function, which is the derivative of this function, is also commonly seen. In the context of technical and physical applications, e.g. with wave propagation, the functional equation
is often used since it allows one to determine function values in one strip of width 1 in z from the neighbouring strip. In particular, starting with a good approximation for a z with large real part one may go step by step down to the desired z. Following an indication of Carl Friedrich Gauss, Rocktaeschel (1922) proposed for lngamma an approximation for large Re(z):
This can be used to accurately approximate for z with a smaller Re(z) via (P.E.Böhmer, 1939)
A more accurate approximation can be obtained by using more terms from the asymptotic expansions of and, which are based on Stirling's approximation.
An asymptotic approximation (which has no convergence area for z!) of the gamma function is
and in its "natural" presentation
where the coefficients of the terms with k > 1 of in the last expansion are simply .
Read more about this topic: Gamma Function