Steven R. Dunbar
Department of Mathematics
203 Avery Hall
University of Nebraska-Lincoln
Lincoln, NE 68588-0130
Voice: 402-472-3731
Fax: 402-472-8466

Topics in
Probability Theory and Stochastic Processes
Steven R. Dunbar


Stirling’s Formula from the Sum of Average Differences


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.




Student: contains scenes of mild algebra or calculus that may require guidance.


Section Starter Question

Section Starter Question

How would you estimate ln k k12k+12 ln tdt graphically? How would you use Taylor Series to estimate the difference? Compare that estimate with the estimates from the Trapezoidal Approximation of ln k k12k+12 ln tdt, using the ideas from Stirling’s Formula from Wallis’ Formula and the Trapezoidal Approximation..


Key Concepts

Key Concepts

  1. Stirling’s Formula as an asymptotic limit follows from estimation of the difference of ln k and the average of ln t on [k 12,k + 12]. Taylor’s Theorem estimates the difference of the mid-value and the average to be O(1k2).




  1. The average of a function f over the interval [a,b] is
    1 b aabf(t) dt.


Mathematical Ideas

Mathematical Ideas

Stirling’s Approximation

Theorem 1 (Stirling’s Approximation). For each n > 0

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

where there exists a real constant A so that |ϵn| < A n .

This is equivalent to n! 2πnn+12en.

Proof. First the proof establishes that there exists a c1 so that log(n!) = c1 + (n + 12) log n n + O(1n).

Expanding the logarithm of n!

log(n!) = k=1n log k = k=1n log k k12k+12 log tdt +k12k+12 log tdt =12n+12 log tdt + k=1n log k k12k+12 log tdt.

Integrating by parts

12n+12 log tdt = t log t t 12n+12 = n + 1 2 log n + 1 2 n + 1 2 1 2 log 1 2 1 2 .

Rewrite the expression log(n + 12) as

log n + 1 2 = log n + log 1 + 1 2n = log n + 1 2n + O 1 n2 .


12n+12 log tdt = n + 1 2 log n + n + 1 2 1 2n n + 1 2 + 1 2 log 1 2 1 2 + O 1 n = c1 + n + 1 2 log n n + O 1 n

where the constant c1 = 1 2 log 1 2 1 2.

Now consider individual terms in the summation:

log k k12k+12 log tdt = log k t log t t k12k+12 = log k k + 1 2 log k + 1 2 + k 1 2 log k 1 2 + 1 = log k 1 2 log k + 1 2 + log k 1 2 + k log k 1 2 log k + 1 2 + 1 = 1 2 log 1 k2 + log k2 1 4 + k log k(1 1 2k) k(1 + 1 2k) + 1 = 1 2 log(1 4k2) k log 1 + 1 2k log 1 1 2k + 1 = O 1 k2 k 1 2k 1 8k2 + O 1 k3 1 2k 1 8k2 + O 1 k3 + 1 = O 1 k2 k 1 k 1 8k2 + 1 8k2 + O 1 k3 + 1 = O 1 k2 .

So there exists a value c2 so that

log k k12k+12 log tdt c2 k2.

Then set

c3 = k=1log k k12k+12 log tdt.

The tail of the infinite sum is

n+1log k k12k+12 log tdt n+1c2 k2 n+1 c2 k(k 1) = c2 n .

The last equation shows that 1n(log k log tdt) = c 3 + O 1 n.

Combining all of these equations gives us

log(n!) = n + 1 2 log n n + c1 + c3 + O 1 n = n + 1 2 log n n + c4 + O 1 n.

Note that this is essentially the same form as the conclusion of Lemma 3 in Stirling’s Formula by Euler MacLaurin Summation.. Exponentiating, we have

n! = (nn+12eneC6 )(1 + ϵn)

using eO 1 n = (1 + ϵn).


Lemma 2 (Wallis’ Formula).

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

Proof. See the proofs in Wallis Formula.. □

As before in the proof of Theorem 5 in Stirling’s Formula by Euler MacLaurin Summation. we can conclude that eC6 = 2π. □


The Euler-Maclaurin Sum Formula proof of Stirling’s Formula starts with log(n!) = j=1n log(j). The classic proof expresses this as 0n1 log(1 + x) dx with an error term with the Euler-Maclaurin summation formula. The Euler-Maclaurin summation formula is an extension of the Trapezoidal Approximation. (Alternatively, the Euler-Maclaurin summation formula is a result of the Fundamental Theorem of Calculus, summation by parts, and integration by parts.) This allows us to write

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


ϵn =nB1(x) x dx

and ϵn 0 as n . Then start from Wallis’ Formula and take logarithms, replacing the logarithms of the factorials with equation (1). This provides an equation for the integral 1B1(x) x dx which is solved for the value log(2π) 1. Then the equation above can be exponentiated to express Stirling’s Formula.

Here the proof also starts with log(n!) = j=1n log(j). Then the proof expresses this as

12n+12 log tdt + k=1n log k k12k+12 log tdt.

Here the error term appears as a sum of terms

log k k12k+12 log tdt

which is the difference of log k and the average of log t on [k 12,k + 12]. Since log t is increasing, it is reasonable to expect the difference should be small. The proof that this difference is O(1k2) is established in this section with a Taylor series expansion. Then

log(n!) = n + 1 2 log n n + C1 + C3 + O 1 n = n + 1 2 log n n + C4 + O 1 n.

Together with Wallis’ Formula, this is now enough to establish Stirling’s Formula.


This section is adapted from: Lesigne, pages 36-39, [1].


Problems to Work

Problems to Work for Understanding



Reading Suggestion:


[1]   Emmanuel Lesigne. Heads or Tails: An Introduction to Limit Theorems in Probability, volume 28 of Student Mathematical Library. American Mathematical Society, 2005.



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,

Email to Steve Dunbar, sdunbar1 at unl dot edu

Last modified: Processed from LATEX source on December 16, 2011