# Prove Stirling's formula given that for $I_n = \int_0^{\pi/2} \sin^n\theta \, d\theta$ we have $I_{2n+1}/I_{2n} \rightarrow 1$

For $$I_n = \int_0^{\pi/2} \sin^n\theta \, d\theta$$ it is possible to show (using integration by parts and $$\sin^2\theta = 1-\cos^2\theta$$) that: $$nI_n = (n-1)I_{n-2}$$

We can then repeatedly apply this relation to $$\frac{I_{2n+1}}{I_{2n}}$$ to show: $$\frac{I_{2n+1}}{I_{2n}} = \frac{2^{4n+1}(n!)^4}{\pi (2n)!(2n+1)!}$$

This ratio converges to $$1$$ since $$I_{2n+2}/I_{2n} \rightarrow 1$$ (easy to show with the above recursive relation) which is always larger than $$I_{2n+1}/I_{2n}$$. Since $$I_{2n}/I_{2n} = 1$$, we can sandwich the desired ratio.

I also know that (from Show that $n!e^n/n^{n+1/2} \leq e^{1/(4n)}C$) that: $$r_n = n!e^n/n^{n+1/2} \leq e^{1/(4n)}C$$ for all $$n$$ and for $$C = \lim_{n\rightarrow \infty} n!e^n/n^{n+1/2}$$. Now I want to show Stirling's formula:

$$n! \sim \sqrt{2\pi}n^{n+1/2}/e^n$$

What I've tried

Using the upper bound on $$r_n$$ it is clear that all that remains is to show that $$C = \sqrt{2\pi}$$. I have seen trick on related problems involving expressing the integral $$I_n$$ in terms of the beta function, but I think another trick is needed as well (perhaps one involving introducing a term $$e^{i\theta}$$ but I am struggling to get anything more specific than that.

Note that you know a little bit more from the linked question - that $$n!/(n^{n+1/2} e^{-n})$$ decreases to $$C$$.

Using this and the upper bound you have, note that $$\frac{I_{2n+1}}{I_{2n}} \le \frac{2^{4n + 1} C^4 n^{4n + 2} e^{-4n} e^{1/n}}{\pi \cdot C(2n)^{2n+1/2}e^{-2n} \cdot C(2n+1)^{2n + 3/2} e^{-2n - 1}} \\ = \frac{C^2}{2\pi} \frac{e^{1+1/n}}{(1 + 1/2n)^{2n + 3/2}} =: a_n$$

Since $$I_{2n+1}/I_{2n} \to 1,$$ we can conclude that $$\liminf a_n \ge 1$$. But $$\liminf a_n = \frac{C^2}{2\pi}$$, thus telling us that $$C \ge \sqrt{2\pi}$$.

Similarly, we can develop the lower bound $$\frac{I_{2n+1}}{I_{2n}} \ge \frac{C^2}{2\pi} \frac{e}{e^{1/8n + 1/8n + 4} (1+1/2n)^{2n + 3/2}} =: b_n,$$

and argue that $$\frac{C^2}{2\pi} = \limsup b_n \le 1,$$ ergo $$C \le \sqrt{2\pi}$$.

Thus we have shown that $$\sqrt{2\pi} \le C \le \sqrt{2\pi},$$ which of course implies that $$C = \sqrt{2\pi}$$.

I believe this is exactly what you are looking for: https://en.wikipedia.org/wiki/Wallis%27_integrals#Deducing_Stirling's_formula.