Steven R. Dunbar
Department of Mathematics
203 Avery Hall
University of Nebraska-Lincoln
Lincoln, NE 68588-0130
http://www.math.unl.edu
Voice: 402-472-3731
Fax: 402-472-8466
Topics in
Probability Theory and Stochastic Processes
Steven R. Dunbar
Stirling’s Formula Derived from the Gamma Function
Rating
Mathematicians Only: prolonged scenes of intense rigor.
1
Section Starter Question
Do you know of a function defined for, say the positive real numbers, which
has the value n! for positive integers n?
Key Concepts
1. Stirling’s Formula, also called Stirling’s Approximation, is the asymptotic relation
√
n! ∼ 2πnn+1/2 e−n .
2. The formula is useful in estimating large factorial values, but its main
mathematical value is in limits involving factorials.
3. The Gamma function is generally defined as
Z ∞
Γ(z) =
xz−1 e−x dx .
0
For an integer n, Γ(n) = (n − 1)! .
Vocabulary
1. Stirling’s Formula, also called Stirling’s Approximation, is the asymptotic relation
√
n! ∼ 2πnn+1/2 e−n .
2
2. The Gamma function is generally defined as
Z ∞
Γ(z) =
xz−1 e−x dx .
0
For an integer n, Γ(n) = (n − 1)! .
Mathematical Ideas
Stirling’s Formula, also called Stirling’s Approximation, is the asymptotic
relation
√
n! ∼ 2πnn+1/2 e−n .
The formula is useful in estimating large factorial values, but its main mathematical value is in limits involving factorials. Another attractive form of
Stirling’s Formula is:
n n
√
.
n! ∼ 2πn
e
An improved inequality version of Stirling’s Formula is
√
√
2πnn+1/2 e−n+1/(12n+1) < n! < 2πnn+1/2 e−n+1/(12n) .
(1)
See Stirling’s Formula in MathWorld.com.
First we formally define the Gamma function and its most important
property. Then we give a heuristic argument for Stirling’s formula for the
Gamma function using asymptotics of integrals, based on some notes by P.
Garrett, [1]. Here we rigorously derive Stirling’s Formula using the Gamma
function and estimates of the logarithm function, based on the short note by
R. Michel, [2].
3
Definition of the Gamma Function
Lemma 1 (Gamma Function).
∞
Z
xn e−x dx .
n! =
0
Proof. The proof is by induction. Start with n = 0,
Z ∞
Z ∞
0 −x
x e dx =
e−x dx = 1 = 0! .
0
0
Then in general, integrating by parts
Z ∞
Z
n −x
x e dx = n
0
∞
xn−1 e−x dx .
0
Inductively,
∞
Z
xn e−x dx .
n! =
0
Remark. The Gamma function is generally defined as
Z ∞
xz−1 e−x dx .
Γ(z) =
0
Then the same integration by parts shows Γ(z) = (z − 1)Γ(z − 1) . For an
integer n, Γ(n) = (n − 1)! .
Heuristic Derivation of Stirling’s Formula from Asymptotics of Integrals
Observe that
Z
Γ(z + 1) =
∞
z −x
xe
Z
dx =
0
∞
e−x+z log x dx .
0
Note that −x + z log x has a unique critical point at x = z. The critical
point is a maximum since the second derivative has value −1/z < 0 there.
The idea is to replace −x + z log x by its second degree Taylor polynomial
4
based at z, then evaluate the resulting integral. Note that the second degree
Taylor polynomial is the quadratic polynomial best approximating a function.
The idea is that most of the contribution to the integral comes from the
maximum, and because of the negative exponential, contribution away from
the maximum is slight.
So expand −x+z log x in a second-degree Taylor polynomial at the critical
point z:
1
(x − z)2 .
−x + z log x ≈ −z + z log z −
2!z
Thus we can approximate the Gamma function with
Z ∞
Γ(z + 1) = zΓ(z) =
e−x+z log x dx
(2)
0
Z ∞
1
2
e−z+z log z− 2!z (x−z) dx
≈
0
Z ∞
2
−z z
=e z
e−(x−z) /2z dx
Z0 ∞
2
≈ e−z z z
e−(x−z) /2z dx .
−∞
Note that last evaluation of the integral is over the whole real line. By
Lemma 4 of DeMoivre-Laplace Central Limit Theorem
Z 0
1
2
e−(x−z) /2z dx ≤ e−z/4 .
2z
−∞
This is very small for large z, so heuristically the asymptotics of the integral
over the whole line is of the same order as the integral over [0, ∞).
To simplify the integral, replace x by zu. Notice that a factor of z cancels
from both sides
Z ∞
2
−z z
e−z(u−1) /2 du .
Γ(z) = e z
−∞
√
Make another change of variables x = z(u − 1) so that
√ Z ∞
√
Z ∞
−x2
1
2π
−z z
−z(u−1)2 /2
−z z
−z
z
e z
e
du = e z √
e 2 dx = e z √ .
z −∞
z
−∞
The last equality is derived in Evaluation of the Gaussian Density Integral.
5
Simplifying,
Γ(s) ≈
√
2πe−z z z−1/2 .
As an alternative, one can apply Laplace’s method (for asymptotics of
integrals) to the integral in (2) and derive the same conclusion somewhat
more rigorously.
Rigorous Derivation of Stirling’s Formula
Lemma 2.
n! = n
n
√
Z
−n
∞
ne
gn (y) dy
−∞
where
n
√
y
gn (y) = 1 + √
e−y n 1(−√n,∞) (y) .
n
Proof. In √
Lemma 1 make√the substitution x =
x
y = √n − n) with dx = n dy to give
Z
∞
n −x
x e
0
√
ny + n (or equivalently
∞
√
√
√
n −(y n+n)
n
+
n)
e
n dy
(y
√
− n
Z
√
√ −n ∞
√
n
= n ne
(y/ n + 1)n e−(y n) dy
√
− n
Z ∞
√
= nn ne−n
gn (y) dy .
Z
dx =
−∞
Remark. This means that what remains is to show the integral
√
approaches the asymptotic constant 2π .
Lemma 3. For |x| < 1,
3
log(1 + x) − x + 1 x2 ≤ 1 |x| .
2 3 1 − |x|
6
R∞
−∞
gn (y) dy
2
Figure 1: A graph of the functions in Lemma 3 with | log(1 + x) − x + x2 | in
|x|3
in blue.
red and 31 · 1−|x|
Remark. Note further that
|x|3
≤ |x|2
1 − |x|
(3)
for |x| ≤ 1/2. This will be used later to simplify the expression on the right
side of the inequality in Lemma 3.
Proof. Expanding log(1 + x) in a Taylor series and applying the triangle
inequality
∞
X
1
|x|3
2
log(1 + x) − x + x ≤
.
2 k
k=3
Grossly overestimating each term by using the least denominator and summing as a geometric series
∞
X
|x|3
k=3
k
≤
7
1 |x|3
.
3 1 − |x|
Lemma 4.
|ea − eb | ≤ eb · |a − b| · e|a−b| .
Proof.
|ea − eb | = eb |ea−b − 1|
P∞ xk−1
P∞ xk−1
P∞ xk
P
xk
Notice that ex − 1 = ∞
k=1 k! = x
k=1 k! ≤ x
k=1 (k−1)! = x
k=0 k! =
x
x
x
xe . Alternatively let f (x) = e − 1 and g(x) = xe . Then f (0) = 0 = g(0),
and f 0 (x) = ex ≤ ex + xex = g 0 (x) for x > 0 . Likewise f 0 (x) = ex ≥
ex + xex = g 0 (x) for x < 0 . Therefore ex − 1 = f (x) ≤ g(x) = xex for all x .
Then
eb |ea−b − 1| ≤ eb · |a − b| · e|a−b| .
Lemma 5. For |y| ≤
√
n
2
|gn (y) − e−y
2 /2
|y|3
2
| ≤ √ e−y /6 .
n
√
Proof. For |y| ≤
|gn (y) − e
−y 2 /2
n
2
n
√
y
2 /2 −y
n
−y
e
1(−√n,∞) (y) − e
| = 1 + √
n
““
”n ” √
log 1+ √y
2
−y n
n
= e
1(−√n,∞) (y) − e−y /2 .
√
Using |y| ≤
n
2
““
log 1+ √y ”n ”−y√n
−y 2 /2 n
= e
−e
.
Using Lemma 4
≤e
−y 2 /2
˛ ““
n ˛˛log 1+ √y ”n ”−y√n+y2 /2˛˛˛
√
y
2
n
· log
1+ √
− y n + y /2 · e
,
n
then with rules of logarithms
˛ ““
˛
””
˛
˛
y2 ˛
2
n˛˛log 1+ √yn − √yn + 2n
y
y
y
˛
−y 2 /2
,
=e
· n · log 1 + √
− √ + ·e
n
n 2n
8
and using Lemma 3
≤ e−y
2 /2
3 /n3/2
1 |y|3 /n3/2 n· 13 · |y|
√
√ e 1−|y|/ n .
3 1 − |y|/ n
·n·
Making a coarse estimate on the fraction
3 3/2
1 |y| /n √
1
|y|3 /n3/2
√
√ en· 3 1−|y|/ n
·
3 1 − ( n/2)/ n
3 /n3/2
2 |y|3 n· 13 |y|
2
√
1−|y|/ n .
= e−y /2 ·
e
3 n1/2
≤ e−y
2 /2
·n·
Use the remark after Lemma 3
= e−y
2 /2
·
2 |y|3 1 |y|2
e3
3 n1/2
Combine the exponents and coarsely over-estimate the fraction
|y|3
2
≤ √ e−y /6 .
n
Lemma 6.
lim gn (y) = e−y
2 /2
n→∞
where the limit is uniform on compact subsets of R .
√
n
2
Proof. For |y| ≤
use Lemma5
|gn (y) − e−y
2 /2
|y|3
2
| ≤ √ e−y /6 .
n
2
Note that |y|3 e−y /6 has a maximum value of 27e−3/2 .
Let K be a compact subset of R with M be a bound
|x| <
√ so that K ⊂ {x :√
M } . Let > 0 be given. Let n be so large that M < n/2 and 27e−3/2 / n <
√
3
2
2
√ e−y /6 ≤ 27e−3/2 / n < .
. Then for all y ∈ K, |gn (y) − e−y /2 | ≤ |y|
n
9
Figure 2: A graph of the functions in Lemma 7 with log(1 + x) in red and
x − (5/6)(x2 )/(2 + x) in blue.
Lemma 7. For x > −1
log(1 + x) ≤ x −
5 x2
.
62+x
2
2
x
x −x+4
Proof. Consider f (x) = x − 56 2+x
− log(1 + x), with f 0 (x) = x · 6(1+x)(2+x)
2 .
0
The only critical point on the domain x > −1 is x = 0, and f (x) < 0 for
−1 < x < 0, f 0 (x) > 0 for x > 0 . Then f (x) has a global minimum value of
x2
0 at x = 0 . Hence log(x) ≤ x − 56 2+x
.
Remark. Unfortunately, although the proof is straightforward the origin of
the rational function on the right is unmotivated.
Lemma 8.
0 ≤ gn (y) ≤ e−|y|/6 ,
10
|y| >
1√
n
2
√
Proof. For y > − n,
√
y
log(gn (y)) = n log(1 + √ ) − y n
n
2
5
y
√
≤−
6 2 + y/ n
√
√
√
using Lemma
7. For |y| > 12 n and on the domain y > − n, 1 < 2+y/ n ≤
√
2 + |y|/ n, so
5|y|
5|y|
√ ≥
√ .
2 + y/ n
2 + |y|/ n
√
√
√
Now since |y| > 12 n, it is true that 4|y| > 2 n, so 5|y| > 2 n + |y| or
√
5|y|
√ >
n . Finally multiplying through by −|y|/6,
2+|y|/ n
√
y2
y2
−|y|
−5
−5
−|y| n
√ ≤
√ <
<
.
6 2 + y/ n
6 2 + |y|/ n
6
6
Theorem 9 (Stirling’s Formula).
√
n! ∼ 2πnn+1/2 e−n .
Proof. By Lemma 2
n! = n
n
√
−n
Z
∞
ne
gn (y) dy
−∞
where
n
√
y
gn (y) = 1 + √
e−y n 1(−√n,∞) (y) .
n
From Lemma 6
lim gn (y) = e−y
2 /2
n→∞
uniformly on compact sets and gn (y) is integrable by Lemma 8. Hence by
the Lebesgue Convergence Theorem
Z ∞
Z ∞
2
lim
gn (y) dy =
e−y /2 dy
n→∞
−∞
−∞
√
and since −∞ e
dy = 2π it follows that
R∞
gn (y) dy
n!
= lim −∞ √
= 1.
lim √
√
n→∞
2πnn ne−n n→∞
2π
R∞
−y 2 /2
11
Figure 3: A graph of the functions in Lemma 10 with 1 +
1
x4
+ 12 log(1 + x) in red and 120
in blue.
x
1
12
·
x2
1+x
−
Asymptotic Expansions
Lemma 10. For x > 0
x2
1
·
−
0<1+
12 1 + x
1 1
+
x 2
log(1 + x) ≤
x4
.
120
Remark. Unfortunately, although the proof is straightforward the origin of
the function on the left is unmotivated.
3
x
Proof. Let f (x) = 2x + 16 1+x
− (x + 2) log(1 + x) for x > −1 so f 0 (x) =
x3
1
x2
x+2
0
− 61 (1+x)
2 − 2 2(1+x) − log(1 + x) − x+1 + 2 . Then f (0) = 0, and f (0) = 0 .
3
x
00
Further f 00 (x) = 31 · (1+x)
3 and f (x) > 0 for x > 0 . Therefore, f (x) > 0 for
x > 0 and dividing through by 2x yields the left inequality.
5
For the right side, consider h(x) = x60 − f (x) . Again h(0) = h0 (0) = 0 .
3
x3
Further h00 (x) = x3 − 13 · (1+x)
3 > 0 for x > −1 . The right side inequality
follows immediately.
12
Lemma 11. For x > 0,
1
1
ex ≤ 1 + x + x2 + x3 ex .
2
6
Proof. For x > 0, expanding ex in a Taylor series
∞
1 2 X xk
e =1+x+ x +
2
k!
k=3
x
∞
1
1 X xk−3
= 1 + x + x2 + x3
2
6 k=3 k!/6
∞
1 2 1 3X
xk
=1+x+ x + x
2
6 k=0 (k + 3)!/6
∞
1 2 1 3 X xk
≤1+x+ x + x
2
6 k=0 k!
since (k + 3)!/6 ≥ k! .
Lemma 12.
1
1 e1/24
≤
3
6 12
9440
1/24
Remark. Numerically 16 e123 ≈ 0.0001005542925 and
so the difference is about 5 × 10−6 .
1
9440
≈ 0.0001059322034,
Proof. I don’t have a rigorous proof based on, say, elementary comparisons
in the rational number system. In fact, it is not clear how the denominator
9440 arises. However, as will be seen in the proof of Theorem 13 what is
1/24
really needed is that 61 e123 is a finite constant. Finding a rational number
with unit numerator and 4-digit denominator to bound the constant is simply
a convenience.
Theorem 13. For n ≥ 2,
n!
1 1
1
√
2πnn+1/2 e−n − 1 − 12n ≤ 288n2 + 9940n3 .
13
n!
an
n+1 n+1/2 −1
an
Proof. Let an = √2πnn+1/2
.
Then
=
e
and
log
=
an+1
n
an+1
e−n
(n+1/2) log(1+1/n)−1 . Using the left inequality in Lemma 10 with x = 1/n
1
an
≤
.
log
an+1
12n(n + 1)
Then
n+r−1
n+r−1
X
an
1 X
1
1 1
1
ak
log
=
≤
=
−
.
log
an+r
ak+1
12 k=n k(k + 1)
12 n n + r
k=n
Now let r → ∞, noting that limr→∞ an+r = 1, so log(an ) ≤
e1/(12n) . Now use Lemma 11 and Lemma 12 to yield
1
12n
and an ≤
1
1 1
1 1
+
+
e1/(12n)
2
12n 2 (12n)
6 (12n)3
1 1
1 1
1
+
+
e1/(12·2)
≤1+
2
12n 2 (12n)
6 (12n)3
1
1 1
1
≤1+
+
+
.
2
12n 2 (12n)
9440n3
an ≤ 1 +
Then
√
n!
−1−
1
1 1
1
≤
+
.
2
12n
2 (12n)
9440n3
2πnn+1/2 e−n
Likewise, using the right inequality in Lemma 10 with x = 1/n
an
1
1 1
≥
−
.
log
an+1
12(n(n + 1)) 120 n4
Then
log
an
an+r
=
n+r−1
X
k=n
log
ak
ak+1
≥
n+r−1
n+r−1
1 X
1
1 X 1
−
12 k=n k(k + 1) 120 k=n k 4
n+r−1
1 1
1
1 X 1
=
−
−
.
12 n n + r
120 k=n k 4
Again let r → ∞, noting that limr→∞ an+r = 1 to obtain
∞
∞
X
1
1 X 1
1
1 1
1
1
1 1
1
log(an ) ≥
−
=
−
−
≥
−
−
4
4
4
4
12n 120 k=n k
12n 120 n k=n+1 k
12n 120 n 360n3
14
R∞ 1
P
1
because ∞
k=n+1 k4 ≤ n x4 dx using right-box Riemann sums with width
1.
1
1 1
1
rn
Let rn = 12n
− 120
− 360n
. By a well-known estimate
3 . Hence an ≥ e
n4
rn
e ≥ 1 + rn . Therefore,
an ≥ 1 +
1
1 1
1
−
−
4
12n 120 n
360n3
Equivalently,
n!
1
1
1 1
√
≥−
−1−
−
.
3
n+1/2
−n
12n
360n
120 n4
2πn
e
Since
1 1
1 1
1
1
+
≤
+
360n3 120 n4
2 (12n)2 9440n3
the two inequalities can be summarized as
√
n!
2πnn+1/2 e−n
−1−
1 1
1
1
≤
+
.
2
12n
2 (12n)
9440n3
Remark. The proof actually shows the slightly stronger bounds
−
1
1 1
n!
1 1
1
1
−
≤√
≤
+
.
−1−
3
4
2
n+1/2
−n
360n
120 n
12n
2 (12n)
9440n3
2πn
e
Remark. Using similar reasoning, from the well-known estimate ern ≥ 1 +
rn + 12 rn2 , one can derive the estimate
n!
1
1
√
≤ 1 + 1
−
1
−
−
2πnn+1/2 e−n
2
12n 288n 360n3 108n4
valid for n ≥ 3 .
Remark. Note that for n = 1,
√
since
√e
2π
n!
2πnn+1/2 e−n
≈ 1.0844 and
13
12
e
13
1
=√ ≥
=1+
12
12
2π
≈ 1.08334 . Similarly for n = 2
n!
e2
25
1
√
=√
≥
=1+
24
12 · 2
2πnn+1/2 e−n
2π 23/2
15
2
since √2πe 23/2 ≈ 1.042207 and
n≥3
√
n!
2πnn+1/2 e−n
−1−
25
24
≈ 1.041664 . From the remark above, for
1
1
1
1
≥
−
−
> 0.
2
3
12n
288n
360n
108n4
Then for all n ≥ 1,
n!
√
≥1+
1
12n
2πnn+1/2 e−n
which is a better bound than e1/(2n+1) quoted in equation (1). In order to
2x
see this bound, consider f (x) = log(1 + x) − 2+x
, defined for x > −1. Then
1
x2
0
0
)>
f (x) = (1+x)(2+x)2 and f (0) = 0, f (x) > 0 for x > 0. Then log(1 + 12n
2
1
1
1/(12n+1)
> 12n+1 . Hence 1 + 12n > e
.
24n+1
Alternate Derivation of Stirling’s Asymptotic Formula
Note that xt e−x has its maximum value at x = t. That is, most of the value
of the Gamma Function comes from values of x near t. Therefore use a
partition of the Gamma Function with t > 0, f (x) = xt e−x for x > 0, and
A = {x : |x − t| ≥ t/2}. Then
Z ∞
xt e−x dx
Γ(t + 1) =
0
Z 3t/2
Z ∞
=
f (x) dx +
1A (x)f (x) dx
t/2
0
where 1A (·) is the indicator function (or characteristic function) of A. For
x ∈ A, 1 ≤ 4(x − t)2 /t2 , so we have 1A (x) ≤ 4(x − t)2 /t2 . Then
Z 3t/2
Z
1
1
4(x − t)2 t −x
t −x
x e dx ≤
x e dx
1 −
Γ(t + 1) {x:|x−t|≥t/2}
Γ(t + 1) t/2
t2
Z ∞
4
≤
(x − t)2 xt e−x dx
Γ(t + 1)t2 0
Expanding (x − t)2 and using Γ(z + 1) = zΓ(z) from the remark following
Lemma1 yields
Z ∞
(x − t)2 xt e−x dx = (t + 2)(t + 1)Γ(t + 1) − 2t(t + 1)Γ(t + 1) + t2 Γ(t + 1).
0
16
Then simplifying the right side
Z 3t/2
1
2+t
xt e−x dx ≤ 4 2
1 −
Γ(t + 1) t/2
t
√
t + t and setting gt (y) = (1 +
Making
the
change
of
variables
x
=
y
√
√ t −y√t
for y > − t just as in the proof of Lemma2, we get
y/ t) e
√
Z √t/2
tt t
lim
gt (y) dy = 1.
t→∞ Γ(t + 1)et −√t/2
(4)
Now using |x| ≤ 1/2 and Lemma3
3
1
2
log(1 + x) − x + x ≤ 1 |x| ≤ 2 |x|3 .
2 3 1 − |x|
3
Then using Lemma5
|y|3
2
2
gt (y) − e−y /2 ≤ √ e−y /6
t
√
for |y| ≤ t/2. Then
Z √
Z ∞
Z √t/2
Z
t/2
1
2
2
−y /2
3 −y 2 /6
e
dy ≤ √
|y| e
dy +
e−y /2 dy
√ gt (y) dy −
√
√
− t/2
t − t/2
−∞
|y|> t/2
√ −t/24
Z
−t/24
36e
−3 te
36
2
− √
=
+√ +
e−y /2 dy
√
2
t
t
|y|> t/2
Therefore,
√
Z
lim
t→∞
t/2
√
− t/2
Z
∞
gt (y) dy =
e−y
2 /2
dy =
−∞
Combining this with the limit in equation 4, we have
Γ(t + 1)et
lim √
= 1.
t→∞
2πtt+1/2
17
√
2π .
Sources
The main part of this section is adapted from the short note by R. Michel,
[2]. The alternate derivation is adapted from the even shorter note by R.
Michel, [3].
Problems to Work for Understanding
1. Show that
R∞
e−y
−∞
2 /2
dy =
√
2π .
Reading Suggestion:
References
[1] Paul Garrett. Asymptotics of integrals. Online, accessed November 2012,
July 2011.
[2] Reinhard Michel. On Stirling’s formula. American Mathematical Monthly,
109(4):388–390, April 2002.
[3] Reinhard Michel. The (n + 1)th proof of Stirling’s Formula. American
Mathematical Monthly, 115(9):844–845, November 2008.
18
Outside Readings and Links:
1.
2.
3.
4.
I check all the information on each page for correctness and typographical
errors. Nevertheless, some errors may occur and I would be grateful if you would
alert me to such errors. I make every reasonable effort to present current and
accurate information for public use, however I do not guarantee the accuracy or
timeliness of information on this website. Your use of the information from this
website is strictly voluntary and at your risk.
I have checked the links to external sites for usefulness. Links to external
websites are provided as a convenience. I do not endorse, control, monitor, or
guarantee the information contained in any external website. I don’t guarantee
that the links are active at all times. Use the links here with the same caution as
you would all information on the Internet. This website reflects the thoughts, interests and opinions of its author. They do not explicitly represent official positions
or policies of my employer.
Information on this website is subject to change without notice.
Steve Dunbar’s Home Page, http://www.math.unl.edu/~sdunbar1
Email to Steve Dunbar, sdunbar1 at unl dot edu
Last modified: Processed from LATEX source on November 26, 2012
19
© Copyright 2026 Paperzz