5.2 Sterling approximation

\begin {align} \int _{0}^{\infty }t^{n}e^{-t}dt & =n!\nonumber \\ \int _{0}^{\infty }t^{n}e^{-t}dt & =\int _{0}^{\infty }e^{n\ln t}e^{-t}dt\nonumber \\ & =\int _{0}^{\infty }e^{\left (n\ln \relax (t) -t\right ) }dt\nonumber \\ & =\int _{0}^{\infty }e^{f\relax (t) }dt \tag {1} \end {align}

Where \(f\relax (t) =n\ln \relax (t) -t\). Contribution to integral comes mostly from where \(f\relax (t) \) is maximum. \begin {align*} f^{\prime }\relax (t) & =0\\ \frac {n}{t}-1 & =0\\ t_{\max } & =n \end {align*}

Approximating \(f\relax (t) \) around \(t_{0}\)\[ f\relax (t) =f\left (t_{\max }\right ) +\left (t-t_{\max }\right ) f^{\prime }\left (t_{\max }\right ) +\frac {1}{2}\left (t-t_{\max }\right ) ^{2}f^{\prime \prime }\left (t_{\max }\right ) +\cdots \] But \(f^{\prime }\left (t_{\max }\right ) =0\) and \(f^{\prime \prime }\left ( t\right ) =-\frac {n}{t^{2}}\). Hence the above becomes\[ f\relax (t) =f\left (t_{\max }\right ) -\frac {1}{2}\left (t-t_{\max }\right ) ^{2}\frac {n}{t_{\max }^{2}}+\cdots \] Replacing \(t_{\max }=n\) in the above gives\begin {align} f\relax (t) & =\left (n\ln \relax (n) -n\right ) -\frac {1}{2}\left (t-n\right ) ^{2}\frac {n}{n^{2}}+\cdots \nonumber \\ & =\left (n\ln \relax (n) -n\right ) -\frac {1}{2}\left (t-n\right ) ^{2}\frac {1}{n}+\cdots \tag {2} \end {align}

Substituting (2) into (1) gives\begin {align*} n! & \approx \int _{0}^{\infty }e^{\left (n\ln \relax (n) -n\right ) -\frac {1}{2}\left (t-n\right ) ^{2}\frac {1}{n}}dt\\ & \approx e^{\left (n\ln \relax (n) -n\right ) }\int _{0}^{\infty }e^{-\frac {1}{2}\left (t-n\right ) ^{2}\frac {1}{n}}dt\\ & \approx n^{n}e^{-n}\int _{0}^{\infty }e^{-\frac {1}{2}\left (t-n\right ) ^{2}\frac {1}{n}}dt \end {align*}

Let \(u=\frac {t-n}{\sqrt {2n}}\). When \(t=0,u=-\frac {n}{\sqrt {2n}}\) and when \(t=\infty ,u=\infty \). And \(du=\frac {1}{\sqrt {2n}}dt\). The above now becomes\[ n!\approx n^{n}e^{-n}\int _{-\frac {n}{\sqrt {2n}}}^{\infty }e^{-u^{2}}\sqrt {2n}du \] When \(n\gg 1\), the lower limit of the integral \(\rightarrow -\infty \). Hence \begin {align*} n! & \approx n^{n}e^{-n}\int _{-\infty }^{\infty }e^{-u^{2}}\sqrt {2n}du\\ & \approx \sqrt {2n}n^{n}e^{-n}\sqrt {\pi }\\ & \approx \sqrt {2\pi }n^{n+\frac {1}{2}}e^{-n} \end {align*}