Estimating the Gamma function to high precision efficiently?

3.6k Views Asked by At

I know there are several approximations of the Gamma function that provide decent approximations of this function.

I was wondering, how can I efficiently estimate specific values of the Gamma function, like $\Gamma (\frac{1}{3})$ or $\Gamma (\frac{1}{4})$, to a high degree of accuracy (unlike Stirling's approximation and other low-accuracy methods)?

4

There are 4 best solutions below

5
On BEST ANSWER

Gourdon and Sebah pages on "Numbers, constants and computation" are usually interesting for this kind of record (start by clicking on 'constants' at the left).

They reference Shigeru Kondo and Steve Pagliarulo for having computed 10^10 digits of $\Gamma\left(\frac 14\right)$ and $\Gamma\left(\frac 13\right)$ in 2010 and 2009 (see here). Many methods for high precision are clearly exposed in the other pages of the first link (FFT, binary splitting and this kind of things should be simply explained at least in the .ps or .pdf files).

This paper of Alexander Yee concerning high precision evaluation of $\pi$ contains too references to Kondo & Pagliarulo's record (he has a page of records too but without $\Gamma$ I fear).

In the special case $\Gamma\left(\frac k{24}\right)$ a quadratic algorithm is proposed in Weisstein's Gamma Function page (see around (99)).
This method is the famous AGM method and you may find too in page 6 of Sebah and Gourdon's postscript paper on Gamma (or here) that : $$\displaystyle \Gamma\left(\frac 14\right)^2=\frac{(2\pi)^{3/2}}{AGM(\sqrt{2},1)}$$

You may find in the excellent book of the Borweins "Pi and the AGM" following derivation using the complete elliptic integral of the first kind $\rm{K}$ : page25

Hoping it helped anyway,

0
On

I'm not sure what sort of approximation you need.

Have you looked at the Lanczos approximation? It provides the technique used in the classic book Numerical Recipes. It can be used to calculate reasonable approximations for $\Gamma$ (8 decimal places or so) even on devices with constrained resources, like the 12C financial calculator from HP.

3
On

(This is an addendum of sorts to Raymond's answer, and an expansion of my comment there.)

For certain small rational arguments, Borwein and Zucker show that the gamma function can be evaluated using the complete elliptic integral of the first kind $K(m)$ (where $m$ is the parameter), evaluated at so-called "singular values". Since the complete elliptic integral of the first kind can be evaluated using the quadratically convergent arithmetic-geometric mean,

$$K(m)=\frac{\pi}{2\mathrm{AGM}(1,\sqrt{1-m})}$$

we also have a fast way to evaluate the gamma function for those particular rational arguments.

Letting the singular values be denoted by $k_r=\lambda^\ast(r)$ (where $\lambda^\ast(r)$ is the elliptic lambda function), e.g.

$$\begin{align*} k_1&=\frac{1}{\sqrt{2}}\\ k_2&=\sqrt{2}-1\\ k_3&=\frac{\sqrt{3}-1}{2\sqrt{2}}\\ k_4&=3-2\sqrt{2}\\ k_5&=\sqrt{\frac{1}{2}-\sqrt{\sqrt{5}-2}}\\ k_6&=\left(2-\sqrt{3}\right)\left(\sqrt{3}-\sqrt{2}\right) \end{align*}$$

we have for instance the evaluations

$$\begin{align*} \Gamma\left(\frac13\right)&=\frac{2^{7/9}\pi^{1/3}}{3^{1/12}}(K(k_3^2))^{1/3}\\ \Gamma\left(\frac14\right)&=2\pi^{1/4}\sqrt{K(k_1^2)}\\ \Gamma\left(\frac16\right)&=\frac{\sqrt{3}}{\sqrt[3]{2}\sqrt{\pi}}\left(\Gamma\left(\frac13\right)\right)^2\\ \Gamma\left(\frac18\right)\Gamma\left(\frac38\right)&=\sqrt{\sqrt{2}-1}\sqrt{\pi}2^{13/4}K(k_2^2)\\ \frac{\Gamma\left(\frac18\right)}{\Gamma\left(\frac38\right)}&=\frac{2\sqrt{\sqrt{2}+1}}{\sqrt[4]{\pi}}\sqrt{K(k_1^2)} \end{align*}$$

See the Borwein/Zucker paper for more details.


With regards to the Lanczos approximation mentioned by Rory in his answer, Paul Godfrey presents a short note on how to derive the approximation that is somewhat more straightforward than the original derivation by Lanczos.

For other methods, see this paper by Schmelzer and Trefethen, and this webpage by Peter Luschny.

0
On

I made a graph on Desmos and a c++ implementation about this earlier today if anybody else wants to take a look at it. It uses the Lanczos Approximation. Here’s the graph and here’s the C++ implementation which works with complex numbers too