LogGamma

Another way to compute the binomial coefficient when using large numbers is to recognize that


{n \choose k} = \frac{n!}{k!\,(n-k)!} = \frac{\Gamma(n+1)}{\Gamma(k+1)\,\Gamma(n-k+1)} = \exp(\ln\Gamma(n+1)-\ln\Gamma(k+1)-\ln\Gamma(n-k+1)),

where ( \ln \Gamma(n) ) denotes the natural logarithm of the gamma function at n. It is a special function that is easily computed and is standard in some programming languages such as using log_gamma in Maxima, LogGamma in Mathematica, gammaln in MATLAB, or lgamma in R. Roundoff error may cause the returned value to not be an integer.

— Wikipedia on Binomial coefficient

2014.07.23 Wednesday ACHK