# Approximation for $n!$ using $\sqrt{2 \pi n}$

For Stirling's Approximation , I am using to seeing this written in the following notation:

$$\ln(n!) = n(\ln(n)) - n$$

But recently, I saw this version (e.g. https://www.youtube.com/watch?v=HV0Tqcg9MtU, @ 5:50) :

$$n! \approx \sqrt{2 \pi n} \left( \frac{n}{e} \right)^n$$

I am trying to understand where this version of Stirling's Formula comes from.

I tried to play around with some algebra manipulations:

$$\ln(n!) \approx n \ln(n) - n$$ $$e^{\ln(n!)} \approx e^{n \ln(n) - n}$$ $$e^{\ln(x)} = x$$: $$n! \approx e^{n \ln(n) - n}$$ $$n! \approx \left(e^{\ln(n)}\right)^n e^{-n}$$ $$n! \approx n^n e^{-n}$$

This looks almost correct, but it is missing the $$\sqrt{2 \pi n}$$ term.

I am not sure how to justify adding the $$\sqrt{2 \pi n}$$ term.

• If you write the first formula more precisely, you'll get $+O(\ln n)$ term on the right-hand side (see en.wikipedia.org/wiki/Stirling%27s_approximation). $\sqrt{2 \pi n}$ is $e^{O(\ln n)}$. Commented Jul 2 at 4:40
• If you just calculate some values ($n = 5$ should already be enough) you'll find that the second one is more accurate than the first. The second one is the precise multiplicative asymptotic in the sense that the limit as the LHS is divided by the RHS is $1$. Commented Jul 2 at 4:57
• en.wikipedia.org/wiki/Stirling%27s_approximation This article should gives some ideas of how and where it comes from. Commented Jul 2 at 7:28
• $\ln(n!) = n(\ln(n)) - n$ is incorrect. This is not an equality. The error term is missing: $\ln(n!) = n(\ln(n)) - n+\mathcal{O}(\ln (n))$.
– Gary
Commented Jul 2 at 7:28

The derivation should be doable at the start of university, when guided. It's probably doable without guidance if one is familiar with Laplace's method for approximating integrals.

Here is a more detailed version of deriving the approximation using Laplace's method: see wikipedia here

1. First, you need to prove the relationship between $$n!$$ and the gamma function. Prove that the gamme function is indeed such that $$\Gamma(\alpha+1)=\alpha \Gamma(\alpha)$$, ie, it extends the recursive property of factorial numbers to the positive reals.

2. Second, find the maximum of the integrand of the Gamma function $$\Gamma(\alpha)$$.

3. Compute the second derivative of the log of the integrand. Prove that it is strictly negative. This shows that the integrand is log-concave. NB: log-concavity is sufficient for Laplace's approximation to be asymptotically correct, but it is not necessary.

4. Compute the integral of the exponential of the Taylor expansion to second order of the log integrand. This is the Laplace approximation of the integral. Check that it is identical to the Stirling formula.

5. Find some proof to establish that the Gamma function and its Laplace approximation converge to one-another. Depending on your level, there are multiple ways to do so. Please note, this step typically leads to ugly partial integrals. That's expected.

Best of luck and bon courage.

$$n! = \Gamma(n+1) = \int_0^\infty x^ne^{-x} dx$$ $$\int_0^\infty x^ne^{-x} dx$$ Let $$x = nz$$ $$n\int_0^\infty (nz)^n e^{-nz} dz$$ $$n^{n+1}\int_0^\infty z^ne^{-nz} dz$$ $$n^{n+1}\int_0^\infty e^{n\ln(z)}e^{-nz} dz$$ $$n^{n+1}\int_0^\infty e^{n(\ln(z)-z)} dz$$ Using taylor series we can approximate $$\ln(z)-z \approx -1 - \frac{1}{2}(z-1)^2$$

$$n^{n+1}\int_0^\infty e^{n(\ln(z)-z)} dz \approx n^{n+1}\int_0^\infty e^{n(-1 - \frac{1}{2}(z-1)^2)} dz$$ $$n^{n+1}\int_0^\infty e^{-n} e^{- \frac{n}{2}(z-1)^2}dz$$ $$n^{n+1}e^{-n}\int_0^\infty e^{- \frac{n}{2}(z-1)^2}dz$$

This integral is similar to the Gaussian integral $$\int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2}$$

$$n^{n+1}e^{-n} \sqrt{\frac{2\pi}{n}}$$ $$n^ne^{-n} \sqrt{{2\pi n}}$$ $$n! \approx \left( {\frac{n}{e}} \right) ^n \sqrt{{2\pi n}}$$