On Ramanujan's approximation, $n!\sim \sqrt{\pi}\big(\frac ne\big)^n\sqrt [6]{(2n)^3+(2n)^2+n+\frac 1{30}}$ Over here I discovered that Ramanujan gave the following factorial approximation, better than Stirling's formula:

$$n!\sim \sqrt{\pi}\left(\frac ne\right)^n\sqrt [6]{(2n)^3+(2n)^2+n+\frac 1{30}}$$

such that the error term decreases rapidly as $n\to \infty$. In other words, $$\lim_{n\to\infty}\cfrac{n!}{\sqrt{\pi}\left(\frac ne\right)^n\sqrt [6]{8n^3+4n^2+n+\frac 1{30}}}=1$$ Just to add, Stirling's formula is: $$n!\sim \sqrt{2\pi n}\left(\frac ne\right)^n$$ so somehow Ramanujan was able to turn $2n$ into $\sqrt [3]{8n^3+4n^2+n+\frac 1{30}}$. Notice that $2n=\sqrt [3]{8n^3}$ so the important expression is $4n^2+n+\frac 1{30}$.
Does anybody know how he got this result? Or is this another one of his mysterious results...
 A: The asymptotic expansion of the factorial may be written
$$
n! \sim \left( {\frac{n}{e}} \right)^n \sqrt {2\pi n} \sum\limits_{k = 0}^\infty  {( - 1)^k \frac{{\gamma _k }}{{n^k }}} ,
$$
where $\gamma_k$ denotes the Stirling coefficients (see, e.g., here). The first three of them are $\gamma_0=1$, $\gamma_1=-\frac{1}{12}$ and $\gamma_2=\frac{1}{288}$. Now, if a function has an asymptotic expansion, then its 6th power also has one and it is the original expansion raised into the power of $6$. Accordingly,
$$
\left( {n!/\left( {\frac{n}{e}} \right)^n \sqrt {2\pi n} } \right)^6 \sim
\left( {\sum\limits_{k = 0}^\infty  {( - 1)^k \frac{{\gamma _k }}{{n^k }}} } \right)^6  \sim 1 + \frac{1}{{2n}} + \frac{1}{{8n^2 }} + \frac{1}{{240n^3 }} - \frac{{11}}{{1920n^4 }} +  \cdots ,
$$
and thus
\begin{align*}
n! & \sim \left( {\frac{n}{e}} \right)^n \sqrt {2\pi n} \sqrt[6]{{1 + \frac{1}{{2n}} + \frac{1}{{8n^2 }} + \frac{1}{{240n^3 }} - \frac{{11}}{{1920n^4 }} +  \cdots }} \\ & = \left( {\frac{n}{e}} \right)^n \sqrt \pi  \sqrt[6]{{8n^3  + 4n^2  + n + \frac{1}{{30}} - \frac{{11}}{{240n}} +  \cdots }}\; .
\end{align*}
Therefore, Ramanujan's approximation is just a manipulation of the standard asymptotic expansion of the factorial. It is of course more accurate than the leading order asymptotics (known as Stirling's formula) since it uses additional terms from the asymptotic expansion. Let me add here that although the standard asymptotic expansion (and Ramanujan's as well) is divergent, for large $n$ the initial terms decrease in magnitude. There is a minimum occuring around $\left\lfloor {2\pi n} \right\rfloor$. Truncating the series at this point yields exponentially accurate approximations (see again the paper above for more details).
