To learn more about EpiX Analytics' work, please visit our modeling applications, white papers, and training schedule.

Page tree


n! is very laborious to calculate for high values of n because it requires doing (n-1) individual multiplications. The following equation [by a Scots mathematician James Stirling (1692-1770)], known as the Stirling formula, can be used instead to get a very close approximation:


\Big(\frac{n}{e}\Big)^{n} \sqrt{2 \pi m}\Big(\frac{n}{12n+1}\Big)<n!< \Big(\frac{n}{e}\Big)^{n} \sqrt{2 \pi m}


An n gets larger the two limits rapidly approach each other, and a commonly quoted simplification of Stirling's formula is thus:


n!\sim\sqrt{2 \pi n}\Big(\frac{n}{e}\Big)^{n}


The equation is sometimes useful for ratios of factorials, as is often needed in probability calculations. However, in general we find using a gamma function easier and more accurate:


\Gamma (n+1)=n!


So Excel's GAMMALN(x+1) = Log(x!), and calculating x!/y! is:




The ratio of the factorials is done in logs which means you can handle much higher numbers. For example, using FACT(1002)/FACT(999) to calculate 1002! / 999! will generate an error as Excel tries to calculate both large factorials. However, EXP(GAMMALN(1003)- GAMMALN(1000)) gives the value 1003001999.99923 which compares well against the true answer of 1000*1001*1002 = 1003002000.


  • No labels