====== Stirling's formula ====== \[ \begin{align} n!&=\int_0^\infty x^n e^{-x} dx\\ &= \int_0^\infty e^{n\ln x -x} dx\\ \end{align} \] \[ f(x)=n\ln x - x \] \[ \begin{align} f'(x)&=\frac{n}{x}- 1\\ f''(x)&=-\frac{n}{x^2}\\ \end{align} \] \[ \begin{align} f(x)&=f(n)+f'(n)(x-n)+\frac{1}{2}f''(n)(x-n)^2+\cdots\\ f(n)&=n\ln n - n\\ f'(n)&=\frac{n}{n}- 1=0\\ f''(n)&=-\frac{n}{n^2}=-\frac{1}{n}\\ \end{align} \] \[ f(x)=n\ln n - n-\frac{1}{2n}(x-n)^2+\cdots\\ \] \[ \begin{align} \int_0^\infty e^{n\ln x -x} dx&=\int_0^\infty e^{n\ln n - n-\frac{1}{2n}(x-n)^2+\cdots} dx\\ &=e^{n\ln n - n}\int_0^\infty e^{-\frac{1}{2n}(x-n)^2+\cdots} dx \end{align} \]