# Understand a step in the derivation of the Stirling's approximation

The Stirling's approximation of the factorial function is defined as:

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

This Wikipedia's derivation starts by using the logarithm of $$n!$$

$$\ln n! = \ln 1 + \ln 2 + ... + \ln n$$

And then it says

The right-hand side of this equation minus

$${\displaystyle {\tfrac {1}{2}}(\ln 1+\ln n)={\tfrac {1}{2}}\ln n}$$

is the approximation by the trapezoid rule of the integral

$${\displaystyle \ln n!-{\tfrac {1}{2}}\ln n\approx \int _{1}^{n}\ln x\,{\rm {d}}x=n\ln n-n+1}$$

...

Before proceeding I of course need to understand every step, but I'm not understanding the text that I marked in bold.

What I understand from that statement is that we substract an equation, i.e. $${\displaystyle {\tfrac {1}{2}}(\ln 1+\ln n)={\tfrac {1}{2}}\ln n}$$, from the right hand side of the previous equation, i.e. $$\ln n! = \ln 1 + \ln 2 + ... + \ln n$$, which is $$\ln 1 + \ln 2 + ... + \ln n$$. This does not make sense at all to me.

Could someone explain me what it's meant by that statement?

I must be honest, a great percentage of the times I don't understand something similar to this is because of the way things are explained in English, not because of the formulas. (Please, mathematicians, learn to write well!)

• What exactly is unclear ? The trapezoid-rule states that the integral is approximately $1/2\ln(1)+\ln(2)+\ln(3)+\cdots+\ln(n-1) +1/2\ln(n)$ – Peter Aug 31 '16 at 17:44
• There is nothing to learn on our side. The RHS of an equation is just what is written on the right of the equality sign, so the the RHS of the previous equation minus something has the obvious meaning: what is written in the right part of the previous line, minus something. – Jack D'Aurizio Aug 31 '16 at 17:44
• In our case, something is $\frac{1}{2}\left(\log(1)+\log(n)\right)$, that is $\frac{1}{2}\log n$. – Jack D'Aurizio Aug 31 '16 at 17:46
• No, because you do not subtract $\log(1)+\log(2)+\ldots+\log(n)$ from $\frac{1}{2}\log(n)$, you do the opposite. – Jack D'Aurizio Aug 31 '16 at 17:47
• What else The RHS of the previous equation minus three could mean?! – Jack D'Aurizio Aug 31 '16 at 17:50

The trapezoid with base $[k,k+1]$ has area

$$\frac12\big(\ln k+\ln(k+1)\big)\;;$$

when you sum these over $k=1,\ldots,n-1$, you get

$$\frac12\ln 1+\ln 2+\ln 3+\ldots+\ln(n+1)+\frac12\ln n\;,$$

because every height except the first ($\ln 1$) and the last ($\ln n$) appears twice, once as the righthand height of a trapezoid and then again as the lefthand height of the next trapezoid. This is the same as

$$(\ln 1+\ln 2+\ldots+\ln n)-\left(\frac12\ln 1+\frac12\ln n\right)\;.$$

It doesn’t actually say that you’re subtracting an equation from an equation: it says that you’re subtracting the quantity $\frac12(\ln 1+\ln n)$ from the quantity $\ln 1+\ldots+\ln n$ (which happens to be $\ln n!$), and that this quantity that you’re subtracting can be simplified to $\frac12\ln n$ (since $\ln 1=0$).

• I think there is just a language issue here, not a real mathematical problem. – Jack D'Aurizio Aug 31 '16 at 17:58

$$\log(n!)=\log(1)+\log(2)+\cdots +\log(n)$$
\begin{align} \log(n!)-\frac12 (\log(1)+\log(n))&=\frac12 \log(1)+\log(2)+\cdots +\log(n-1)+\frac12 \log(n)\\\\ &\approx \int_1^n \log(x)\,dx\\\\ &=n\log(n)-n+1 \end{align}
Since the logarithm is concave, the trapezoidal rule approximation provides a lower bound. Therefore, we find from $(1)$ that
$$n!<e\sqrt{n}\left(\frac ne\right)^n$$