Since the dawn of time, humanity has been fascinated by the factorial function. This function is defined for all natural numbers, and the factorial of the natural number $n$ is denoted by $n!$. The number $n!$ is best defined as the number of permutations of $n$ objects. The number of permutations of no objects is exactly one so $0! = 1$. Otherwise we have

$$n! = 1\times 2 \times \cdots \times n$$ whenever $n > 0$. Actually, this formula also makes sense for $n=0$ if we are considering the formula to degenerate to the empty product.

Here is an example: $10! = 3628800$. For large numbers, computing the factorial can take some time so many mathematicians over the ages have come up with approximations to the factorial.

## Stirling’s formula

Stirling derived the approxmation

$$n! \approx n^ne^{-n}\sqrt{2\pi n}.$$ Let’s test it out. Stirling approximates $10!$ as 3598695.6187410504 which is about 30104 less than the real value.

## Burnside’s formula

Burnside derived the approximation

$$n! \approx \sqrt{2\pi}\left( \frac{n+1/2}{e}\right)^{n + 1/2}.$$ Let’s see if it’s better than Stirling’s formula. Burnside’s formula approximates $10!$ as 3643220.9817212913, which is only about 14421 greater than the true number. A little better!

## Bauer’s formula

Bauer derived the approxmation

$$n! \approx n^ne^{-n}\sqrt{2\pi(n+1/6)}.$$ It is a formula that is very much in the spirit of Stirling’s formula but slightly corrected. Can it do better than Burnside’s formula or Stirling’s original formula? Testing it out on $10!$, it gives 3628560.824755708. Incredible! It’s only about 239 less than the true valie.

## Ramanujan’s formula

The great Srinivas Ramanujan, whose deftness at manipulating infinite sums and numbers remains unparalleled to this day, came up with the formula

$$n!\approx \sqrt{\pi}n^ne^{-n}\left(8n^3 + 4n^2 + n + 1/30 \right)^{1/6}.$$ Can Ramanujan decimate the other formulas? Again, we test it out on $10!$ to obtain 3628800.311612623…shocking! The integer part of this number is exactly $10!$. Should we try it on another one? The factorial of 18 is

whereas Ramanujan’s formula gives

which is only 54964675.0 greater than the real value (less than $9\times 10^{-9}$ of the real value).

## Comparing

To further compare these I used the above formulas as approximations to $\log(n!)$ to make the computations easier and computed the absolute value of the difference between $\log(n!)$ and the log of each of the formulas above. I plotted the cumulative error up to $n=1000$. Here are the first three:

There is not much point in even putting the even better Ramanujan formula on the plot because it would also be flat so here is a separate plot with Bauer against Ramanujan: