An alternative formula for n! using the
gamma function is n! = \int_0^\infty x^n e^{-x}\,{\rm d}x. (as can be seen by repeated integration by parts). Rewriting and changing variables , one obtains n! = \int_0^\infty e^{n\ln x-x}\,{\rm d}x = e^{n \ln n} n \int_0^\infty e^{n(\ln y -y)}\,{\rm d}y. Applying
Laplace's method one has \int_0^\infty e^{n(\ln y -y)}\,{\rm d}y \sim \sqrt{\frac{2\pi}{n}} e^{-n}, which recovers Stirling's formula: n! \sim e^{n \ln n} n \sqrt{\frac{2\pi}{n}} e^{-n} = \sqrt{2\pi n}\left(\frac{n}{e}\right)^n.
Higher orders Further corrections can also be obtained using Laplace's method. Stirling's formula to two orders is n! = \sqrt{2\pi n}\left(\frac{n}{e}\right)^n \left(1 + \frac{1}{12 n}+O\!\left(\frac{1}{n^2}\right) \right). From previous result, we know that \Gamma(x) \sim x^x e^{-x}, so we "peel off" this dominant term, then perform two changes of variables, to obtain:x^{-x}e^x\Gamma(x) = \int_\R e^{x(1+t-e^t)}dtTo verify this: \int_\R e^{x(1+t-e^t)}dt \overset{t \mapsto \ln t}{=} e^x \int_0^\infty t^{x-1} e^{-xt} dt \overset{t \mapsto t/x}{=} x^{-x} e^x \int_0^\infty e^{-t} t^{x-1} dt = x^{-x} e^x \Gamma(x). Now the function t \mapsto 1+t - e^t is unimodal, with maximum value zero. Locally around zero, it looks like -t^2/2, which is why we are able to perform Laplace's method. In order to extend Laplace's method to higher orders, we perform another change of variables by 1+t-e^t = -\tau^2/2. This equation cannot be solved in closed form, but it can be solved by serial expansion, which gives us t = \tau - \tau^2/6 + \tau^3/36 + a_4 \tau^4 + O(\tau^5) . Now plug back to the equation to obtainx^{-x}e^x\Gamma(x) = \int_\R e^{-x\tau^2/2}(1-\tau/3 + \tau^2/12 + 4a_4 \tau^3 + O(\tau^4)) d\tau = \sqrt{2\pi}(x^{-1/2} + x^{-3/2}/12) + O(x^{-5/2})notice how we don't need to actually find a_4, since it is cancelled out by the integral. Higher orders can be achieved by computing more terms in t = \tau + \cdots, which can be obtained programmatically.{{NoteTag|note=For example, a program in Mathematica: series = tau - tau^2/6 + tau^3/36 + tau^4*a + tau^5*b; (*pick the right a,b to make the series equal 0 at higher orders*) Series[tau^2/2 + 1 + t - Exp[t] /. t -> series, {tau, 0, 8}] (*now do the integral*) integral = Integrate[Exp[-x*tau^2/2] * D[series /. a -> 0 /. b -> 0, tau], {tau, -Infinity, Infinity}]; Simplify[integral/Sqrt[2*Pi]*Sqrt[x |name=mathematica-program|content=content|text=text}}
Complex-analytic version A complex-analysis version of this method is to consider \frac{1}{n!} as a
Taylor coefficient of the exponential function e^z = \sum_{n=0}^\infty \frac{z^n}{n!}, computed by
Cauchy's integral formula as \frac{1}{n!} = \frac{1}{2\pi i} \oint\limits_{|z|=r} \frac{e^z}{z^{n+1}} \, \mathrm dz. This line integral can then be approximated using the
saddle-point method with an appropriate choice of contour radius r = r_n. The dominant portion of the integral near the saddle point is then approximated by a real integral and Laplace's method, while the remaining portion of the integral can be bounded above to give an error term.
Using the Central Limit Theorem and the Poisson distribution An alternative version uses the fact that the
Poisson distribution converges to a
normal distribution by the
Central Limit Theorem. Since the Poisson distribution with parameter \mu converges to a normal distribution with mean \mu and variance \mu, their
density functions will be approximately the same: \frac{\exp(-\mu)\mu^x}{x!}\approx \frac{1}{\sqrt{2\pi\mu}}\exp\left(-\frac{1}{2}\left(\frac{x-\mu}{\sqrt{\mu}}\right)^{2}\right) Evaluating this expression at the mean, at which the approximation is particularly accurate, simplifies this expression to: \frac{\exp(-\mu)\mu^\mu}{\mu!}\approx \frac{1}{\sqrt{2\pi\mu}} Taking logs then results in -\mu+\mu\ln\mu-\ln\mu!\approx -\frac{1}{2}\ln (2\pi\mu) which can easily be rearranged to give: \ln\mu!\approx \mu\ln\mu - \mu + \frac{1}{2}\ln (2\pi\mu) Evaluating at \mu=n gives the usual, more precise form of Stirling's approximation. == Speed of convergence and error estimates ==