Stirling's approximation

In CoCalc you can calculate the binomial coefficient like this (right). Most calculators have a hard time dealing with such large numbers.

In Mathematica ${25 \choose 50} \equiv $ Binomial[50,25] =126 410 606 437 752.

As you can imagine, if we had a solid with just 1 mole $\approx 6\times 10^{23}$ of particles, the factorials get waaaaay huge. So it's more manageable to work with the logarithm of the number.

James Stirling--a contemporary of Isaac Newton--came up with an approximation for $\ln(n!)$, and since $${N \choose N_1}=\frac{N!}{N_1!(N-N_1)!}$$ we can use his result to approximate the log of the binomial coefficient.

Stirling's approximation for $\ln(n!)$

A graph of the natural log function:

This *looks* like the kind of construction used to construct approximations to integrals. Here the integral that we're approximating with rectangles would appear to be...: $$\begin{align}\int_1^n \ln(n) dn &\approx \ln(1)+\ln(2)+\ln(3)+....\ln(n) \\
& = \ln(1*2*3*....n) = \ln(n!).\end{align}$$

This approximation looks not too good for small values of $n$, but ought to be better and better for large $n$.

But, we can look up the integral and solve it exactly: $$ \int_1^n \ln(n') dn' = \left[n'\ln(n') -n' \right]_1^n =n\ln(n)-n -0+1.$$

Putting this together with the approximation to the integral, for large $n$ (we can ignore the added 1) we get Stirling's approximation:

$$\ln(n!) \approx n\ln(n) - n.$$

How good is Stirling's approximation?

Let's plot $\ln n!$ vs Stirling's approximation, $n\ln n -n$.

Unfortunately CoCalc's list_plot function starts to choke around 250!. So you can use Wolfram Alpha instead.

  1. Using WolframAlpha.com, plot the two functions $\ln(n!)$ and Sterling's approximation, $n\ln n -n$ on the same graph, at first with $1\leq n \leq 15$.

    Here's an example of how you can plot two functions on the same graph. Re-use and modify!

    Now, try out different value of $n_\text{max}$ for the plotting domain of $n$ values, that is, $1\leq n \leq n_\text{max}$. At about what value of $n_\text{max}$ can you no longer visually distinguish much difference between $\ln n!$ from Stirling's approximation? (past the URL of your WolframAlpha graph into your response)

  2. Using WolframAlpha or CoCalc, calculate exactly: $$ \ln{500 \choose 250} $$ that is, the natural log of binomial(500,250).

    Then express the log of the binomial (see equation 1) in terms of the logarithms of a several factorials, and calculate the same thing using Sterling's approximation for the logarithms of the factorials.

binomial(500,250)=$\frac{500!}{(250!)((500-250)!)} =\frac{500!}{(250!)^2}$. So, ln(binomial(...))= $$\ln(500!)-2\ln(250!)\approx 500\ln 500 -500-2*(250\ln 250-250)=346.57$$