# Ramanujan's approximation to factorial

I saw this approximation for the factorial given by Ramanujan as $$\log(n!) \approx n \log n - n + \frac{\log(n(1+4n(1+2n)))}{6} + \frac{\log(\pi)}{2}$$ in wikipedia, which claims the approximation is superior to Stirling's approximation. I tried to locate the reference but unfortunately I could not.

I would appreciate if someone can throw light on how this asymptotic is obtained and the order of the error.

-
Nobody knows how any of Ramanujan's results were obtained. – Gerry Myerson Jun 1 '12 at 6:20
@Marvis: A good thing would be to email Bruce Berndt. – user9413 Jun 1 '12 at 6:42

## 2 Answers

\eqalign{\log(n!) &\approx \left( \ln \left( n \right) -1 \right) n+\ln \left( \sqrt {2 \pi } \right) +\dfrac{\ln \left( n \right)}{2} +\dfrac{1}{12} n^{-1}-{\dfrac {1}{ 360}}\,{n}^{-3}+O \left( {n}^{-5} \right)\cr n\ln \left( n \right) &-n+\frac{\ln \left( n \left( 1+4\,n \left( 1+2 \,n \right) \right) \right)}{6} +\frac{\ln \left( \pi \right)}{2}\cr &= \left( \ln \left( n \right) -1 \right) n+\ln \left( \sqrt {2 \pi } \right) +\frac{ \ln \left( n \right)}{2} +\frac{1}{12}{n}^{-1}-{ \frac {1}{288}}\,{n}^{-3}+{\frac {1}{768}}\,{n}^{-4}+O \left( {n}^{-5} \right) \cr}

So the error in Ramanujan's approximation is asymptotic to $\left(\dfrac{1}{288} - \dfrac{1}{360}\right) n^{-3} = \dfrac{1}{1440} n^{-3}$.

EDIT: an even better approximation, then, would be

$n\ln \left( n \right) -n+\dfrac{\ln \left(1/30 + n \left( 1+4\,n \left( 1+2 \,n \right) \right) \right)}{6} +\dfrac{\ln \left( \pi \right)}{2}$

where the error is asymptotic to $-\dfrac{11}{11520} n^{-4}$. Thus at $n=10$ we have $\ln 10! \approx 15.1044125730755$, Ramanujan's approximation $\approx 15.1044119983597$ and the improved approximation $\approx 15.1044126589476$.

-
Nice. Thanks! I suspected that by matching the first few coefficients in the error term of Stirling's and rewriting them as log one could get this approximation. I was wondering if there was an inherently new way of coming up with this asymptotic directly instead of comparing with Stirling and then matching coefficients. – user17762 Jun 1 '12 at 17:11
The Ramanujan approximation can equivalently be written as $\dfrac{n!(e/n)^n}{\sqrt{2\pi n}} = \left(1 + \dfrac{1}{2n} + \dfrac{1}{8n^2} + \ldots \right)^{1/6}$, compared to the standard Stirling series $1 + \dfrac{1}{12n} + \dfrac{1}{288n^2} + \ldots$. I don't know what is so special about the exponent $1/6$ in this context. – Robert Israel Jun 1 '12 at 18:41
On the other hand, you could write this as $\left(1 + \dfrac{1}{\sqrt{5}n} + \dfrac{1}{10 n^2} + \ldots\right)^{\sqrt{5}/12}$, which has the advantage that the coefficient of $1/n^3$ is $0$. – Robert Israel Jun 1 '12 at 18:49
Very nice answer and comments. Nevertheless, I would still like to know where exactly it can be found in Bruce Berndt's books on Ramanujan's lost notebook. Does anyone know that? – Manolito Pérez Mar 12 '15 at 11:47

Well, I finally found the formula in

S. Ramanujan, The Lost Notebook and other Unpublished Papers. S. Raghavan and S. S. Rangachari, editors. Narosa, New Delhi, 1987.

page 339.

-