## Friday, April 13, 2012

### Stirling’s Formula!

Factorials are used in many branches of mathematics and physics, and particularly in statistical mechanics. One often needs the natural logarithm of a factorial, ln(n!). In Chapter 3 of the 4th edition of Intermediate Physics for Medicine and Biology, Russ Hobbie and I use Stirling’s approximation to compute ln(n!). We analyze this approximation in Appendix I.
There is a very useful approximation to the factorial, called Stirling’s approximation:
ln(n!) = n ln nn .
To derive it, write ln(n!) as
ln(n!) = ln 1 + ln 2 + … + ln n = ∑ ln m
The sum is the same as the total area of the rectangles in Fig. I.1, where the height of each rectangle is ln m and the width of the base is one. The area of all the rectangles is approximately the area under the smooth curve, which is a plot of ln m. The area is approximately
1nln m dm = [m ln mm]1n = n ln nn + 1.
This completes the proof.
David Mermin—one of my favorite writers among physicists—has much more to say about Stirling’s approximation in his American Journal of Physics article “Stirling’s Formula!” (leave it to Mermin to work an exclamation point into his title). He writes Stirling’s approximation as n! = √(2 π n) (n/e)n. Taking the natural logarithm of both sides gives ln(n!) = ln(2 π n)/2 + n ln nn . For large n, the first term is small, and the result is the same as Russ and I present. I wonder what affect the first term has on the approximation? For small n, it makes a big difference! In Table I.1 of our textbook, we compute the accuracy of n ln nn for n = 5. In that case, n! = 120, so ln(n!) = ln(120) = 4.7875 and 5 ln 5 – 5 = 3.047, giving a 36% error. But ln(10 π)/2 + 5 ln 5 – 5 = 4.7708, implying an error of 0.35 %, so Mermin’s formula is much better than ours. (I shouldn’t call it Mermin’s formula; I believe Stirling himself derived n! = √(2 π n) (n/e)n.)

Mermin doesn’t stop there. He analyzes the approximation in more detail, and eventually derives an exact formula for n! that looks like Stirling’s approximation given above, except multiplied by an infinite product. In the process, he looks at the approximation for the base of the natural logarithms, e, presented in Chapter 2 of Intermediate Physics for Medicine and Biology, e = (1 + 1/N)N, and shows that a “spectacularly better” approximation for e is (1 + 1/N)N+1/2. He then goes on to derive an improved approximation for n!, which is his expression for Stirling’s formula times e(1/12n). Perhaps getting carried away, he then derives even better approximations.

All of this matters little in applications to statistical mechanics, where n is on the order of Avogadro’s number, in which case the first term in Stirling’s formula is utterly negligible. Nevertheless, I urge you to read Mermin’s paper, if only to enjoy the elegance of his writing. To learn more about Mermin’s views on writing physics, see his essay “Writing Physics.”