TITLE: Intuitive reason for an approximation to $x!$
QUESTION [7 upvotes]: I was working today on approximating $x!$ using the integral of $\ln x$, and using computer software to calculate limits, I found that $\dfrac{(12x)(\sqrt{2\pi x})(x^x)}{(12x-1)e^x}$ gives a very close approximation of $x!$. Multiplying the figure by $\dfrac{288x^2}{288x^2+1}$ seems to render the approximation even closer, and there are obviously further terms one could add as well. What I'm curious about is the role of the $\sqrt{2\pi x}$ term; I knew there would be a (hopefully asymptotic) error term in the product, but $\sqrt{2\pi}$ had never crossed my mind as a possibility. Is there an intuitive reason that this term appears here?

REPLY [5 votes]: Considering the ratio
$$R=\frac{12x\,\sqrt{2\pi x}\,x^x}{(12x-1)\,e^x\, x!}$$ and using series for large values of $x$, we have$$R=1+\frac{1}{288 x^\color{red}{2}}+\frac{77}{25920 x^3}++O\left(\frac{1}{x^4}\right)$$ while
$$\frac{288x^2}{288x^2+1}=1-\frac{1}{288 x^2}+\frac{1}{82944 x^4}+O\left(\frac{1}{x^6}\right)$$
As you observed
$$ \frac{288 x^2}{288 x^2+1}\,R=1+\frac{77}{25920 x^\color{red}{3}}+O\left(\frac{1}{x^4}\right)$$ is much better.
Trying to improve it, I considered
$$\frac {a_0+a_1x+a_2x^2} {b_0+b_1x+b_2x^2}\,R$$ which was expanded for large values of $x$.
This leads to
$$\frac{129600 x^2-110880 x+94189}{129600 x^2-110880 x+94639}\,R=1+\frac{4000387}{2939328000 x^\color{red}{5}}+O\left(\frac{1}{x^6}\right)$$
It is amazing to see how a "minor" change can improve. Notice that
$$\frac{129600 x^2-110880 x+94189}{129600 x^2-110880 x+94639}-\frac{288x^2}{288x^2+1}=-\frac{77}{25920 x^3}+O\left(\frac{1}{x^4}\right)$$