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 by Euler-Maclaurin Summation

_______________________________________________________________________

Note: To read these pages properly, you will need the latest version of the Mozilla Firefox browser, with the STIX fonts installed. In a few sections, you will also need the latest Java plug-in, and JavaScript must be enabled. If you use a browser other than Firefox, you should be able to access the pages and run the applets. However, mathematical expressions will probably not display correctly. Firefox is currently the only browser that supports all of the open standards.

_______________________________________________________________________________________________

Rating

Rating

Mathematicians Only: prolonged scenes of intense rigor.

_______________________________________________________________________________________________

Section Starter Question

Section Starter Question

How would you evaluate or even approximate 2n n for large values of n, say n 100 ?

_______________________________________________________________________________________________

Key Concepts

Key Concepts

  1. Stirling’s Formula, also called Stirling’s Approximation, is the asymptotic relation
    n! 2πnn+12en.

  2. The formula is useful in estimating large factorial values, but its main mathematical value is in limits involving factorials.
  3. A first-order Euler-Maclaurin Summation Formula is
    f(0)+f(1)++f(n) =0nf(t) dt +1 2 f(0) + f(n)+0n(tt12)f(t) dt

__________________________________________________________________________

Vocabulary

Vocabulary

  1. Stirling’s Formula, also called Stirling’s Approximation, is the asymptotic relation
    n! 2πnn+12en.

  2. A first-order Euler-Maclaurin Summation Formula is
    f(0)+f(1)++f(n) =0nf(t) dt +1 2 f(0) + f(n)+0n(tt12)f(t) dt

__________________________________________________________________________

Mathematical Ideas

Mathematical Ideas

Stirling’s Formula

Stirling’s Formula, also called Stirling’s Approximation, is the asymptotic relation

n! 2πnn+12en.

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! 2π n n e n.

An improved inequality version of Stirling’s Formula is

2πnn+12en+1(12n+1) < n! < 2πnn+12en+1(12n). (1)

See Stirling’s Formula..

James Stirling, a Scottish mathematician born in 1692 near Stirling Scotland, received much of his mathematical education in Oxford. He was a friend and correspondent with Nicholaus (I) Bernoulli, Newton, De Moivre, Euler, and Maclaurin. He wrote extensively on methods for accelerating summations of series, and in 1730 published the asymptotic result that bears his name in his book Methodus Differentialis on this subject. See MacTutor History of Mathematics..

According to Diaconis and Freedman, [1], De Moivre proved a version of Stirling’s Formula without the asymptotic constant 2π in 1730 while deriving what we now call the DeMoivre-Laplace Theorem for the normal approximation to the binomial distribution. Stirling also gave a proof of what is now called Stirling’s Formula using Euler-Maclaurin summation and found the constant 2π using Wallis’ Formula. This is the plan for the proof in this section.

An Easy but Crude Discovery Result

See Stirling’s Formula.:

log(n!) = log(1) + log(2) + + log(n) = k=1n log(k) 1n log(x) dx = [x log(x) x]1n = n log(n) n + 1 n log(n) n.

Although this gives the general functional form, it does not automatically give the “asymptotic factor” 2π n. The approximation comes from replacing the sum with an integral, but this can be justified precisely and rigorously with the Euler-Maclaurin sum formula.

An analytic proof using Euler-Maclaurin Summation and Wallis’ Formula

This proof is adapted and expanded from Todd, [2], pages 73-75 with improvements suggested by Jamie Radcliffe and Stephen Hartke.

Lemma 1 (Trapezoidal Approximation). If f is a function such that f(x) is continuous on [r 1,r]

1 2 f(r 1) + f(r) =r1rf(t) dt +r1r(t (r 1) 12)f(t) dt.

Proof. Starting from r1r(t (r 1) 12)f(t) dt, integrate by parts to obtain

r1r t (r 1) 1 2 f(t) dt = 1 2f(r) + 1 2f(r 1) r1rf(t) dt.

Then transpose r1rf(t) dt to the other side. □

Remark. The left side in the lemma is the one-interval Trapezoidal Approximation of the area under f(t) over [r 1,r]. Then the term r1r t (r 1) 1 2 f(t) dt is an expression for the error in approximation.

Remark. The term (t (r 1) 12) appears unmotivated, although it appears naturally in the alternative proof of Lemma 2. On the other hand, integration-by-parts to obtain the Trapezoidal Approximation requires a linear function which is 12 at r and 12 at r 1. Those requirements mean t (r 1) 12 is the natural choice.

Remark. Assume that f(t) is sufficiently differentiable on [r 1,r] so that we can expand f(t) in a Taylor polynomial f(t) = f((r 1) + 12) + (t (r 1) 12)f(c t) where ct is between t and (r 1) + 12. Then

r1r(t (r 1) 12)f(t) dt =r1r(t (r 1) 12)(f(12) + (t (r 1) 12)f(c t)) dt =r1r(t (r 1) 12)2f(c t) dt

Then

r1r(t (r 1) 12)f(t) dt r1r(t (r 1) 12)2 dt max t[r1,r]|f(t)| = 1 12 max t[r1,r]|f(t)|.

This is the standard error estimate for the Trapezoidal Approximation derived in numerical analysis texts. The Trapezoidal Approximation and the error estimate are usually derived by linear interpolation through the endpoints of integration, also known as Lagrange Interpolation, or the Newton-Cotes formula.

Lemma 2. Suppose

  1. f is a function such that f(x) is continuous on [0,n] for some integer n.
  2. Let B1(t) be the periodic extension with period 1 of the function which is t 12 for t [0, 1].

Then

f(0) + f(1) + + f(n) =0nf(t) dt +1 2 f(0) + f(n) +0nB 1(t)f(t) dt

Remark. This is a simple version of the Euler-Maclaurin Summation Formula.

Proof. Using Lemma 1

1 2 f(0) + f(1) =01f(t) dt +01(t 12)f(t) dt.

Then

f(0) + 1 2f(1) =01f(t) dt +1 2f(0) +01(t 12)f(t) dt

and the result follows by inductively applying the result of Lemma 1 on intervals [1, 2], …, [n 1,n] and finally adding 12f(n) to both sides. Note that B1(t) = t (r 1) 12 on [r 1,r]. □

Alternative Direct Proof. Since f(x) is continuous on [0,n]

r1rf(t) dt = f(r) f(r 1),r = 1, 2,,n.

If we multiply this by r and sum we get

r=1nr1rrf(t) dt = r=1nr(f(r) f(r 1)) = r=1n(rf(r) (r 1)f(r 1)) r=1nf(r 1) = n f(n) 0 f(0) (f(0) + f(1) + + f(n 1)) = (f(0) + f(1) + + f(n)) + (n + 1)f(n)

Note that we can write r = t + 1 in the integral, so that after rearranging we have

f(0) + f(1) + + f(n) = (n + 1)f(n) 0n(t + 1)f(t) dt (2)

Next, by integration by parts we have

0ntf(t) dt = n f(n) 0nf(t) dt. (3)

Then solving for nf(n) in (2) and substituting it into (3), obtain

f(0) + f(1) + + f(n) =0nf(t) dt +f(n) 0n(t + t + 1)f(t) dt.

Take the last term and rearrange it as

0n(t + t + 1)f(t) dt =0n(t t 12 12)f(t) dt

and finally use the Fundamental Theorem of Calculus on the last term. Thus

f(0)+f(1)++f(n) =0nf(t) dt +(f(n)+f(0))2+0n(tt12)f(t) dt.

or equivalently using the definition of B1(t)

f(0) + f(1) + + f(n) =0nf(t) dt +1 2 f(0) + f(n) +0nB 1(t)f(t) dt

Lemma 3.

log(n!) = (n + 1 2) log(n) n + 1 +1B1(x) x dxϵn

where

ϵn =nB1(x) x dx

and ϵn 0 as n .

Proof. Using Lemma 2 with f(x) = log(1 + x) on [0,n 1]

log(1)+log(2)++log(n) =0n1 log(1+x) dx +1 2(log(1)+log(n))+0n1B1(x) 1 + x dx.

After rearranging and the change of variables y = 1 + x on the last integral this becomes

log(n!) = n log(n) n + 1 + 1 2 log(n) +1nB1(x) x dx.

Looking back at the definition B1(x) = x x 12, we can regard 1nB1(x) x dx as the sum of the first 2(n 1) terms of an alternating series with terms of decreasing magnitude. Hence 1B1(x) x dx converges. Then we can write

log(n!) = n log(n) n + 1 + 1 2 log(n) +1B1(x) x dxϵn

where

ϵn =nB1(x) x dx

and ϵn 0 as n . □

Lemma 4 (Wallis’ Formula).

lim n 24n (n!)4 ((2n)!)2(2n + 1) = π 2

Proof. See the proofs in Wallis Formula.. □

Theorem 5 (Stirling’s Formula).

log(n!) = n + 1 2 log(n) n + log(2π) nB1(x) x dx

or equivalently

n! n e n2π n

as n .

Proof. For convenience, let

J =1B1(x) x dx.

Start with Wallis’ Formula and take logarithms, also use Lemma 3 on the factorials:

4n log(2) + 4 n + 1 2 log(n) 4n + 4 + 4J 4ϵn 2 2n + 1 2 log(2n) 2n + 1 + J ϵ2n log(2n + 1) log π 2 (4)

Expand, gather and cancel like terms and obtain

log(n) + 2 + 2J 4ϵn log(2) 2ϵ2n log(2n + 1) log π 2

Note that log(2n + 1) log(n) = log(2 + 1n) log(2) as n so

2 + 2J = log 2π

and rearranging J = log(2π) 1.

Therefore, from Lemma 3 we can write

log(n!) = n + 1 2 log(n) n + log(2π) nB1(x) x dx

which after exponentiation can be written in the more familiar form:

n! 2π n n e n.

Corollary 1 (Error Estimate on Stirling’s Formula).

0 < log(n!) n + 1 2 log(n) n + log(2π) < 1 12 1 n 12

or equivalently

2πnn+12en < n! < 2πnn+12en+1(12(n12)).

Remark. This estimate is not as strong as

2πnn+12en+1(12n+1) < n! < 2πnn+12en+1(12n).

quoted above in equation (1).

Proof. The proof makes the estimate on

ϵn =nB1(x) x dx.

Start with

ϵn = r=n(ϵ r ϵr+1)

and then estimate

ϵr ϵr+1 =rr+12B1(x) x dx +r+12r+1B1(x) x dx = 120B1(r + 12 y) r + 12 y dy +012B1(r + 12 + z) r + 12 + z dz =012B1(12 y) r + 12 y + B1(12 + y) r + 12 + y dy =012 y r + 12 y + y r + 12 + ydy = 2012 y2 (r + 12)2 y2 dy

Therefore

ϵn = r=n012 2y2 (r + 12)2 y2 dy < r=nr20122y2 dy = 1 12 r=nr2

Now

r2 < r2 1 4 1 = r 1 2 1 r + 1 2 1

so

0 < ϵn < 1 12 r=nr 1 2 1 r 1 2 1 < 1 12 n 1 2 1

Sources

Problems to Work

Problems to Work for Understanding

  1. Make a table of values of n!, 2πnn+12en, 2πnn+12en+1(12n+1) and 2πnn+12en+1(12n) for n from 1 to 15. Compute the relative error between n! and 2πnn+12en for each value of n. Likewise compute the relative error between n! and 2πnn+12en+1(12n) for each value of n.
  2. Using a computer algebra system compute 100! and the Stirling’s Formula approximation. Calculate the absolute error and the relative error between the two values.
  3. Show that
    r=1nr(f(r) f(r 1)) = (f(0) + f(1) + + f(n)) + (n + 1)f(n)

    by using “summation by parts”.

  4. Establish and prove the Trapezoidal Approximation and its error for approximating abf(t) dt given the function values at a = x0,x1,x2,,xn = b where xi xi 1 = h = (b a)n uniformly for all i.
  5. Show that
    24n (n!)4 ((2n)!)2(2n + 1) = 2 2 4 4 6 6(2n) (2n) 1 3 3 5 5(2n 1) (2 + 1).

__________________________________________________________________________

Books

Reading Suggestion:

References

[1]   P. Diaconis and D. Freedman. An elmentary proof of Stirling’s formula. American Mathematical Monthly, 93:123–126, 1986.

[2]   John Todd. Introduction to the Constructive Theory of Functions. Academic Press, 1963.

__________________________________________________________________________

Links

Outside Readings and Links:

__________________________________________________________________________

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 October 10, 2011