Proof of Stirling's Formula using Trapezoid rule and Wallis Product

I need a proof of stirling's formula which uses the riemann's sum and trapezoid approximation to come up with $ \frac {n!}{(n/e)^n \sqrt n}$ $ \rightarrow C$ where $C$ is derived from Wallis product. I tried searching the internet but was not able to come up with anything.


Solution 1:

First note that we can write

$$\begin{align} \log(n!)&=\sum_{k=1}^n \log(k)\\\\ &=n\log(n)+\sum_{k=1}^n\log(k/n)\\\\ &=n\left(\log(n)+\frac1n\sum_{k=1}^n\log(k/n)\right) \\\\ &=n\left(\log(n)+\int_0^1 \log(x)\,dx\right)-n\left(\int_0^1 \log(x)\,dx-\frac1n \sum_{k=1}^n \log(k/n)\right)\\\\ &=\log\left(\left(\frac ne\right)^n\right)-n\left(\int_0^1 \log(x)\,dx-\frac1n \sum_{k=1}^n \log(k/n)\right)\tag 1 \end{align}$$

Next, we write the integral on the right-hand side of $(1)$ as

$$\begin{align} \int_{0}^1 \log(x)\,dx&=\int_0^{1/n}\log(x)\,dx+\sum_{k=1}^{n-1}\int_{k/n}^{(k+1)/n} \log(x)\,dx \\\\ &=-\frac1n\left(\log(n)+1\right)+\sum_{k=1}^{n-1}\int_{k/n}^{(k+1)/n} \log(x)\,dx \tag2 \end{align}$$

Applying the Trapezoidal Rule to the integral in $(2)$ reveals

$$\int_{k/n}^{(k+1)/n} \log(x)\,dx =\frac1{2n} \left(\log\left(\frac{k+1}{n}\right)+\log\left(\frac{k}{n}\right)\right)+\frac{1}{12n^3}\frac{1}{\xi^2} \tag3$$

where $k/n<\xi<(k+1)/n$.

Inserting $(3)$ into $(2)$ yields

$$\int_0^1 \log(x)\,dx =-\frac1{2n}\log(n)+\frac1n\sum_{k=1}^n\log(k/n)+O\left(\frac{1}{n}\right)\tag 4$$

Substituting $(4)$ into $(1)$ we find that

$$\log(n!)=\log\left(\left(\frac ne\right)^n\right)+\frac12\log(n)+O\left(1\right)$$

whereupon rearranging terms gives

$$\log\left(\frac{n!}{\sqrt{n}\left(\frac{n}{e}\right)^n}\right)=O\left(1\right) \tag 5$$

Finally, exponentiation of $(5)$ yields

$$\begin{align} \frac{n!}{\sqrt{n}\left(\frac{n}{e}\right)^n}&=e^{O\left(1\right)}\\\\ &=O(1) \end{align}$$

whereupon taking the limit gives

$$\lim_{n\to \infty}\frac{n!}{\sqrt{n}\left(\frac{n}{e}\right)^n}=C$$

for some constant $C$.

Solution 2:

I wrote the following derivation for this answer, but it seems relevant to this question. In $(1)$, we write an integral over a unit interval as the value at the middle of the interval plus an error term. This is a Riemann sum with error term.


First $$ \begin{align} \int_{k-1/2}^{k+1/2}\log(x)\,\mathrm{d}x &=\int_k^{k+1/2}\log(x)\,\mathrm{d}x+\int_{k-1/2}^k\log(x)\,\mathrm{d}x\\ &=\int_0^{1/2}\log(k+t)\,\mathrm{d}x+\int_0^{1/2}\log(k-t)\,\mathrm{d}t\\ &=\int_0^{1/2}\log\left(k^2-t^2\right)\,\mathrm{d}t\\ &=\log(k)+\int_0^{1/2}\log\left(1-\frac{t^2}{k^2}\right)\,\mathrm{d}t\tag{1} \end{align} $$ Euler's Product Formula for $\sin(\pi t)$ easily leads to $$ \sum_{k=1}^\infty\log\left(1-\frac{t^2}{k^2}\right)=\log\left(\frac{\sin(\pi t)}{\pi t}\right)\tag{2} $$ Using symmetry and a double angle formula, we get $$ \begin{align} \int_0^{1/2}\log(\sin(\pi t))\,\mathrm{d}t &=\frac12\int_0^1\log(\sin(\pi t))\,\mathrm{d}t\\ &=\int_0^{1/2}\log(\sin(2\pi t))\,\mathrm{d}t\\ &=\frac12\log(2)+\int_0^{1/2}\log(\sin(\pi t))\,\mathrm{d}t+\int_0^{1/2}\log(\cos(\pi t))\,\mathrm{d}t\\ &=\frac12\log(2)+2\int_0^{1/2}\log(\sin(\pi t))\,\mathrm{d}t\\[3pt] &=-\frac12\log(2)\tag{3} \end{align} $$ Using $(1)$, $(2)$, $(3)$, and $\log\left(n+\tfrac12\right)=\log(n)+\frac1{2n}+O\!\left(\frac1{n^2}\right)$, we get $$ \begin{align} \log(n!) &=\sum_{k=1}^n\log(k)\\ &=\int_{1/2}^{n+1/2}\log(x)\,\mathrm{d}x-\sum_{k=1}^n\int_0^{1/2}\log\left(1-\frac{t^2}{k^2}\right)\,\mathrm{d}t\\ &=\int_{1/2}^{n+1/2}\log(x)\,\mathrm{d}x-\int_0^{1/2}\log\left(\frac{\sin(\pi t)}{\pi t}\right)\,\mathrm{d}t+\sum_{k=n+1}^\infty \int_0^{1/2}\log\left(1-\frac{t^2}{k^2}\right)\,\mathrm{d}t\\ &=\int_0^{n+1/2}\log(x)\,\mathrm{d}x+\tfrac12\log(\pi)-\int_0^{1/2}\log(\sin(\pi t))\,\mathrm{d}t+\sum_{k=n+1}^\infty O\!\left(\frac1{k^2}\right)\\[6pt] &=\left(n+\tfrac12\right)\log\left(n+\tfrac12\right)-\left(n+\tfrac12\right)+\tfrac12\log(\pi)+\tfrac12\log(2)+O\!\left(\tfrac1n\right)\\[12pt] &=\left(n+\tfrac12\right)\log(n)-n+\tfrac12\log(2\pi)+O\!\left(\tfrac1n\right)\\[12pt] &=n\log(n)-n+\tfrac12\log(2\pi n)+O\!\left(\tfrac1n\right)\tag{4} \end{align} $$ Equation $(4)$ is equivalent to $$ \bbox[5px,border:2px solid #C0A000]{n!=\sqrt{2\pi n}\,\frac{n^n}{e^n}\left(1+O\!\left(\frac1n\right)\right)}\tag{5} $$


A Useful Representation

We can collect terms from the derivation of equation $(4)$ to get $$ \begin{align} \log(n!) &=\int_0^{n+1/2}\log(x)\,\mathrm{d}x+\tfrac12\log(2\pi)+\sum_{k=n+1}^\infty \int_0^{1/2}\log\left(1-\frac{t^2}{k^2}\right)\,\mathrm{d}t\\ &=\int_0^{n+1/2}\log(x)\,\mathrm{d}x+\tfrac12\log(2\pi)+\sum_{k=1}^\infty \int_0^{1/2}\log\left(1-\frac{t^2}{(n+k)^2}\right)\,\mathrm{d}t\tag{6} \end{align} $$ which is analytic in $n$ and, as shown in this answer, convex on the positive reals.