Stirling's Approximation
Statement
Stirling's approximation: As ,
More precisely, the ratio as .
The approximation is already tight for moderate and gives the correct exponential order and polynomial correction for quantities like the central binomial coefficient .
Visualization
Numerical comparison: exact vs Stirling approximation and their ratio.
| (approx) | ratio | ||
|---|---|---|---|
| 1 | 1 | 0.9221 | 1.0847 |
| 5 | 120 | 118.02 | 1.0168 |
| 10 | 3628800 | 3598695.6 | 1.0083 |
| 20 | 1.0042 |
The ratio decreases monotonically toward 1. Robbins (1955) showed:
Error magnitude. The multiplicative error is , so for the relative error is about .
Log version (useful for information theory and combinatorics):
This is the starting point for entropy estimates and the analysis of random permutations.
Proof Sketch
- Wallis' product. Show as (Wallis 1655).
- Define Stirling sequence. Let ; show it is log-convex and decreasing.
- Identify the limit. The limit satisfies via Wallis, giving .
- Reconstruct. .
The Mathlib proof in Mathlib.Analysis.SpecialFunctions.Stirling follows exactly this route: Stirling.tendsto_stirlingSeq_sqrt_pi proves , and Stirling.factorial_isEquivalent_stirling packages the asymptotic equivalence.
Connections
Stirling's approximation is the analytic foundation for estimates on Catalan NumbersCatalan NumbersThe ubiquitous sequence counting balanced parentheses, binary trees, and Dyck pathsRead more → () and Bell NumbersBell NumbersThe total number of partitions of a set of n elementsRead more →. It connects to the Wallis product and Taylor's TheoremTaylor's TheoremApproximate smooth functions by polynomials with explicit error boundsRead more → (the Stirling series is an asymptotic expansion). The log version is the combinatorial backbone of the Inclusion-Exclusion PrincipleInclusion-Exclusion PrincipleThe size of a union is the alternating sum of intersection sizesRead more → applied to derangements.
Lean4 Proof
import Mathlib.Analysis.SpecialFunctions.Stirling
/-- Stirling's formula: n! is asymptotically equivalent to sqrt(2*pi*n)*(n/e)^n.
Mathlib's `Stirling.factorial_isEquivalent_stirling` states this. -/
theorem stirling_formula_alias :
(fun n ↦ (n ! : ℝ)) ~[Filter.atTop]
fun n ↦ Real.sqrt (2 * n * Real.pi) * (n / Real.exp 1) ^ n :=
Stirling.factorial_isEquivalent_stirling
/-- Numeric sanity check: 10! = 3628800. -/
theorem factorial_10 : Nat.factorial 10 = 3628800 := by decide