structural:scholar_edition, structural:reformatting, linguistic:paraphrasing, quality:correction
Higher orders

In fact, further corrections can also be obtained using Laplace's method. From previous result, we know that Γ (x) ∼ x x e − x {\displaystyle \Gamma (x)\sim x^{x}e^{-x}}, so we "peel off" this dominant term, then perform two changes of variables, to obtain: x − x e x Γ (x) = ∫ R e x (1 + t − e t) d t {\displaystyle x^{-x}e^{x}\Gamma (x)=\int _{\mathbb {R} }e^{x(1+t-e^{t})}dt} To verify this: ∫ R e x (1 + t − e t) d t = t ↦ ln t e x ∫ 0 ∞ t x − 1 e − x t d t = t ↦ t / x x − x e x ∫ 0 ∞ e − t t x − 1 d t = x − x e x Γ (x) {\displaystyle \int _{\mathbb {R} }e^{x(1+t-e^{t})}dt{\overset {t\mapsto \ln t}{=}}e^{x}\int _{0}^{\infty }t^{x-1}e^{-xt}dt{\overset {t\mapsto t/x}{=}}x^{-x}e^{x}\int _{0}^{\infty }e^{-t}t^{x-1}dt=x^{-x}e^{x}\Gamma (x)}.

Now the function t ↦ 1 + t − e t {\displaystyle t\mapsto 1+t-e^{t}} is unimodal, with maximum value zero. Locally around zero, it looks like − t 2 / 2 {\displaystyle -t^{2}/2}, which is why we are able to perform Laplace's method. In order to extend Laplace's method to higher orders, we perform another change of variables by 1 + t − e t = − τ 2 / 2 {\displaystyle 1+t-e^{t}=-\tau ^{2}/2}. This equation cannot be solved in closed form, but it can be solved by serial expansion, which gives us t = τ − τ 2 / 6 + τ 3 / 36 + a 4 τ 4 + O (τ 5) {\displaystyle t=\tau -\tau ^{2}/6+\tau ^{3}/36+a_{4}\tau ^{4}+O(\tau ^{5})}. Now plug back to the equation to obtain x − x e x Γ (x) = ∫ R e − x τ 2 / 2 (1 − τ / 3 + τ 2 / 12 + 4 a 4 τ 3 + O (τ 4)) d τ = 2 π (x − 1 / 2 + x − 3 / 2 / 12) + O (x − 5 / 2) {\displaystyle x^{-x}e^{x}\Gamma (x)=\int _{\mathbb {R} }e^{-x\tau ^{2}/2}(1-\tau /3+\tau ^{2}/12+4a_{4}\tau ^{3}+O(\tau ^{4}))d\tau ={\sqrt {2\pi }}(x^{-1/2}+x^{-3/2}/12)+O(x^{-5/2})} notice how we don't need to actually find a 4 {\displaystyle a_{4}}, since it is cancelled out by the integral. Higher orders can be achieved by computing more terms in t = τ + ⋯ {\displaystyle t=\tau +\cdots }, which can be obtained programmatically.

Thus we get Stirling's formula to two orders: n ! = 2 π n (n e) n (1 + 1 12 n + O (1 n 2)). {\displaystyle n!={\sqrt {2\pi n}}\left({\frac {n}{e}}\right)^{n}\left(1+{\frac {1}{12n}}+O\left({\frac {1}{n^{2}}}\right)\right).}