11

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...

Mr Pie
  • 9,459
  • Ramanujan was a master of algebraic manipulation. You can compare this with the formula derived via Euler Maclaurin summation. – Paramanand Singh Apr 17 '20 at 03:43
  • 1
    In particular compare $\dfrac{\sqrt[6]{(2n)^3+(2n)^2+n+1/30}}{\sqrt{2n}}$ with $\exp(J(n)) $ where $J(n) $ is given in this answer. – Paramanand Singh Apr 17 '20 at 03:52
  • A better fraction would be $\frac 1{31}$ instead of $\frac 1{30}$. This fraction gives the greatest accuracy when $n=0$, given an integral denominator. – Mr Pie May 06 '20 at 01:39

2 Answers2

9

Edited after @Gary's comment.

This is question I could have been asking for years. I wonder if the basis of this magnificent approximation has been published anywhere.

What I have seen (the problem is that I do not remember where) are approximations built as $$n!\sim \sqrt{\pi}\left(\frac ne\right)^n\sqrt [2k]{P_k(n)}$$ where remains the mystery of the $\sqrt [2k]{.}$. The first case I saw is Gosper approximation.

The coefficients of the polynomials were obtained taking the logarithms of both sides and identified with the Stirling series. So, what was obtained are $$P_1(n)=2n+\frac 13$$ $$P_2(n)=4n^2 + \frac{{4}}{3}n + \frac{2}{9}$$ $$\color{red}{P_3(n)=8 n^3+4 n^2+n+\frac{1}{30}}$$ and for sure, with the tools we have today, we could continue for ever $$P_4(n)=16 n^4+\frac{32 }{3}n^3+\frac{32 }{9}n^2+\frac{176 }{405}n-\frac{128}{1215}$$ $$P_5(n)=32 n^5+\frac{80 }{3}n^4+\frac{100 }{9}n^3+\frac{178}{81}n^2-\frac{95}{972}n+\frac{2143}{40824}$$ $$P_6(n)=64 n^6+64 n^5+32 n^4+\frac{128 }{15}n^3+\frac{8 }{15}n^2+\frac{8 }{105}n+\frac{596}{1575}$$

for more and more accuracy.

For example, for $n=5$, the magic formula given by the great Ramanujan gives $120.000147066$ while the last given here leads to $120.000000406$.

Edit

Staying with the power $\frac 16$ from Ramanujan, we could extend it as $$P_3(n)=8 n^3+4 n^2+n+\frac{1}{30}\left(1+\sum_{i=1}^\infty \frac {a_i}{n^i}\right)$$ and the sequence of the first $a_i$'s is $$\left\{-\frac{11}{8},\frac{79}{112},\frac{3539}{6720},-\frac{9511}{13440},-\frac{30 153}{71680},\frac{233934691}{212889600},\frac{3595113569}{5960908800},\cdots\right\}$$

  • 1
    well explained and excellent answer – MAS Apr 17 '20 at 06:11
  • Perhaps we can include a function $f(n)$ within some $P_n$ so that $f$ is increasing in order to make up for $P_m$ given $m>n$. Lol, idk. It's a thought to entertain, but perhaps a bit too vague to actually apply. – Mr Pie Apr 17 '20 at 06:13
  • 1
    +1 and perhaps Ramanujan also observed the same thing you wrote in last paragraph and therefore chose $k=3$ for his formula. – Paramanand Singh Apr 17 '20 at 06:59
  • @ParamanandSingh very often his formulae are derived from general identities. See this question for example. However, he would list out only the most elegant special cases. If I recall correctly, he once wrote "if $a^3+b^3=c^3$, then $(a+b-c)^3=3(a+b)(c-a)(c-b)$" (not sure if the second equation is correct, just recalling from memory). From this, we can assume he didn't hear of Fermat's Last Theorem. And yet he entirely mastered diophantine power equations. – Mr Pie Apr 17 '20 at 07:28
  • 1
    @MrPie: His real strength was almost extraordinary powers of algebraic manipulation and he was always sure that he did not need anything more than that. Unfortunately that attitude is now lost in the modern focus on abstractions. – Paramanand Singh Apr 17 '20 at 08:20
  • @ParamanandSingh well, perhaps for the majority, but I certainly haven't lost it. I am definitely not as confident as he was in tackling big problems and asserting the answers, but I like to find my own formulae reminiscent of his works. Man... if only he got to live a proper length of life. Imagine what would transpire. – Mr Pie Apr 17 '20 at 08:23
  • Congratulations! $\color{green}{\checkmark}$ – Mr Pie Apr 22 '20 at 08:05
  • @ClaudeLeibovici I think it should be $P_1 (n) = 2n + \frac{1}{3}$, $P_2 (n) = 4n^2 + \frac{{4n}}{3} + \frac{2}{9}$. I did not check the higher ones. – Gary Mar 22 '24 at 01:21
  • 1
    @Gary. Thanks for pointing. Only these one were wrong; all other have been triple checked. – Claude Leibovici Mar 22 '24 at 11:22
4

The asymptotic expansion of the factorial can be expressed as:

$$ n! \sim \left( \frac{n}{\mathrm{e}} \right)^n \sqrt{2\pi n} \sum_{k=0}^\infty (-1)^k \frac{\gamma_k}{n^k}, $$

where $\gamma_k$ represents the Stirling coefficients (refer to here for more information). The first three coefficients are $\gamma_0=1$, $\gamma_1=-\frac{1}{12}$, and $\gamma_2=\frac{1}{288}$. Now, if a function possesses an asymptotic expansion, then its sixth power also has one, given by raising the original expansion to the power of $6$. Hence,

$$ \left( \frac{n!}{\left( \frac{n}{\mathrm{e}} \right)^n \sqrt{2\pi n}} \right)^6 \sim \left( \sum_{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} + \ldots, $$

which implies

\begin{align*} n! & \sim \left( \frac{n}{\mathrm{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} + \ldots} \\ & = \left( \frac{n}{\mathrm{e}} \right)^n \sqrt{\pi} \sqrt[6]{8n^3 + 4n^2 + n + \frac{1}{30} - \frac{11}{240n} + \ldots}\;. \end{align*}

Hence, Ramanujan's approximation is essentially a manipulation of the standard asymptotic expansion of the factorial. It is notably more accurate than the leading-order asymptotics (known as Stirling's formula) as it incorporates additional terms from the asymptotic expansion. It is worth mentioning that although the standard asymptotic expansion (and Ramanujan's as well) is divergent, for large values of $n$, the initial terms decrease in magnitude. A minimum occurs around $\left\lfloor {2\pi n} \right\rfloor$. Truncating the series at this point results in exponentially accurate approximations (for more details, refer again to the aforementioned paper).

Gary
  • 31,845