Stirling’s Formula and Stirling’s Approximation

A physics student proves Stirling's formula using the Gamma function, with the complete original learning note and separate editorial clarifications.

Original Korean learning note

Translation of the complete original learning note. The original reasoning and claims are retained; bounded editorial clarifications follow separately.

Thermal and Statistical Mechanics

English transcription of the original calligraphic title, “Thermal/Statistical”. Archived original title image.

Finally! After entering the physics department, I have reached the second semester of my third year and am taking Thermal and Statistical Mechanics!

Statistical mechanics—a field I have wanted to study just as much as quantum mechanics!!!

For some reason, I really want to do well at it….

I even considered a double major in statistics. Maybe it is because of my vague feeling that statistics could be a powerful tool for explaining nature and society….

Anyway, let me once again work hard at writing up what I have learned.

First, the aim of this textbook really is to teach “statistical mechanics.”

Then what about thermodynamics??? What is going on????

By learning to apply certain tools of statistical mechanics to thermodynamics,

we naturally get a feel for statistical mechanics,

and only then does the book properly teach us what statistical mechanics is.

So apparently this semester will be only thermodynamics.

Let us learn it well here, and move into statistical mechanics next semester!!!

Well…. Through Chapter 3 it is mostly “the basics,” so I will treat that much as….

just a chance to straighten out terminology and concepts. From around Chapter 4, I will study things in my own way and write up thermodynamics.

Through Chapter 3, it is basically an introduction to the mathematics and… very basic things???

(If you have studied quantum mechanics, I think quantum mechanics already gives you the background you need in probability and statistics.)

So I am going to prove Stirling’s formula, which we will use a lot from now on!!!!!

To talk about Stirling’s formula, we first need to discuss the Gamma function, so I will refer a little to a mathematical physics textbook.

Integrating $\int_0^\infty e^{-\alpha x}\,dx$,

$$ =\left[-\frac1\alpha e^{-\alpha x}\right]_0^\infty=\frac1\alpha $$$$ \int_0^\infty e^{-\alpha x}\,dx=\frac1\alpha $$ $$ \int_0^\infty e^{-\alpha x}\,dx=\frac1\alpha $$

Differentiate both sides with respect to $\alpha$:

$$ \begin{aligned} \frac d{d\alpha}\int_0^\infty e^{-\alpha x}\,dx&=\frac d{d\alpha}\left(\frac1\alpha\right)\\ \int_0^\infty(-xe^{-\alpha x})\,dx&=-\frac1{\alpha^2}\\ \int_0^\infty xe^{-\alpha x}\,dx&=\frac1{\alpha^2} \end{aligned} $$

Apply $\frac d{d\alpha}$ again:

$$ \begin{aligned} \int_0^\infty(-x^2e^{-\alpha x})\,dx&=-\frac2{\alpha^3}\\ \int_0^\infty x^2e^{-\alpha x}\,dx&=\frac2{\alpha^3} \end{aligned} $$

Once more, apply $\frac d{d\alpha}$:

$$ \int_0^\infty x^3e^{-\alpha x}\,dx=\frac{3!}{\alpha^4} $$

Keep going:

$$ \vdots\\ \int_0^\infty x^ne^{-\alpha x}\,dx=\frac{n!}{\alpha^{n+1}} $$

Substitute 1 for $\alpha$:

$$ \int_0^\infty x^ne^{-x}\,dx=n! $$

Oh!!! We can express the factorial—the thing I only used in high-school probability and statistics—as an integral like this!?!?!

$$ n!=\int_0^\infty x^ne^{-x}\,dx\qquad(n=1,2,3,\ldots) $$

But the Gamma function we are curious about,

$$ \Gamma(n) $$

is precisely the right-hand side of the expression above.

$$ \Gamma(n+1)=\int_0^\infty x^ne^{-x}\,dx $$

In other words, $n!$ is useful only when $n$ is a positive integer,

and when $n$ is zero, rational, or negative, we have to use the Gamma function on the right!!!!!!!

As a side note, the definition $0!=1$ that we learned in high school…… can easily be proved with the Gamma function!

(To a physics student, it is really… amazing. Hahaha.)

Then let us first define the Gamma function!!!

$$ \begin{aligned} \Gamma(n+1)&=\int_0^\infty x^ne^{-x}\,dx=n!\\ \Gamma(n)&=\int_0^\infty x^{n-1}e^{-x}\,dx=(n-1)! \end{aligned} $$

Multiply both sides of the second equation by $n$.

$$ n\Gamma(n)=n(n-1)!=n! $$$$ n\Gamma(n)=n! $$

Something like that…? As an aside, I tried out a technique for expressing things with the Gamma function. When solving problems, moving between the two sides and rewriting them using this relation can make a problem easier.

Now, in the case we were curious about—when it is “not a natural number”—

we follow the definition of the Gamma function

and substitute the value to calculate it.

$n$ $-\frac32$ $-\frac12$ $\frac12$ $1$ $\frac32$ $2$ $\frac52$ $3$ $4$
$\Gamma(n)$ $\frac43\sqrt\pi$ $-2\sqrt\pi$ $\sqrt\pi$ $1$ $\frac12\sqrt\pi$ $1$ $\frac34\sqrt\pi$ $2$ $6$

That is how the calculation comes out.

The calculation requires the technique of Gaussian integration!!!!

It is not difficult!! Let us move on to Stirling’s formula!!!!

In thermal and statistical mechanics,

$$ {}_n C_r $$

we will apparently deal frequently with numbers like this.

Ah, and in thermal and statistical mechanics, $n$ is an unbelievably large number….

$$ {}_n C_r=\frac{{}_n P_r}{r!}=\frac{n!}{r!(n-r)!} $$

Even if we just think of one mole, that means roughly six thousand “hae” particles [$6\times10^{23}$]. If $n$ in a combination is six thousand hae,

hahahahahahahahahahahaha—six thousand hae factorial! I do not think there is enough paper on Earth to write all those digits??????

In high-school mathematics, we learned something for handling unbelievably large numbers a little more easily.

That something is $\log$.

When it comes to using this logarithm,

people doing chemistry usually use the common logarithm with base 10,

whereas people doing physics tend to use $\ln$, the natural logarithm with base $e$ (exponential)!

We are going to take $\ln$ of the combination.

Stirling’s formula is a logarithmic expression for a large number such as $n!$!!!!!

Let me first throw the formula out there:

$$ \ln n!\cong n\ln n-n+\frac12\ln 2\pi n $$

Or

$$ n!\cong n^ne^{-n}\sqrt{2\pi n} $$

There, there, there, there—this is Stirling’s formula.

This is why I introduced the Gamma function earlier: to show it.

Let us check the Stirling formula above!!!!!!!!!

$$ \Gamma(n+1)=\int_0^\infty x^ne^{-x}\,dx=n! $$

Here, let me express $x^ne^{-x}$ a little differently.

$$ \begin{aligned} x^n&=e^{\ln x^n}\\ x^ne^{-x}&=e^{\ln x^n-x} \end{aligned} $$

Therefore,

$$ n!=\int_0^\infty e^{\ln x^n-x}\,dx $$ $$ n!=\int_0^\infty e^{\ln x^n-x}\,dx $$

To evaluate the integral on the right, I will substitute a variable that makes it manageable.

$$ x=n+y\sqrt n\quad\Longrightarrow\quad dx=\sqrt n\,dy $$

And the integration limits are

$$ \begin{cases}x=0\ \longrightarrow\ y=-\sqrt n\\ \text{infinity is, well—}\end{cases} $$$$ n!=\int_0^\infty e^{\ln x^n-x}\,dx=\int_{-\sqrt n}^\infty e^{n\ln(n+y\sqrt n)-(n+y\sqrt n)}\sqrt n\,dy $$

Now let us work on the exponent in the exponential.

$$ \ln(n+y\sqrt n)=\ln\left[n\left(1+\frac y{\sqrt n}\right)\right]=\ln n+{\color{red}\ln\left(1+\frac y{\sqrt n}\right)} $$

If $n$ is enormously large, a Taylor expansion of the red expression should fit very well.

$$ \ln\left(1+\frac y{\sqrt n}\right)=\frac y{\sqrt n}-\frac{y^2}{2n}+\frac{y^3}{3n\sqrt n}-\cdots $$

Throw the rest away and keep only terms through second order.

$$ n!=\int_{-\sqrt n}^\infty e^{n\ln(n+y\sqrt n)-(n+y\sqrt n)}\sqrt n\,dy $$$$ =\int_{-\sqrt n}^\infty e^{n\left[\ln n+\ln\left(1+\frac y{\sqrt n}\right)\right]-(n+y\sqrt n)}\sqrt n\,dy= $$

From this line on, it is an “approximation”!!! I will substitute the expression approximated by the Taylor expansion!

$$ \cong\int_{-\sqrt n}^\infty e^{n\left[\ln n+\frac y{\sqrt n}-\frac{y^2}{2n}\right]-(n+y\sqrt n)}\sqrt n\,dy $$$$ \cong\int_{-\sqrt n}^\infty e^{n\ln n+y\sqrt n-\frac{y^2}2-(n+y\sqrt n)}\sqrt n\,dy $$

Hororororo~~~! There are terms banging their heads together and dying! There are!!!!

$$ \cong\int_{-\sqrt n}^\infty e^{n\ln n-\frac{y^2}2-n}\sqrt n\,dy $$$$ \cong\int_{-\sqrt n}^\infty e^{n\ln n-n}e^{-\frac{y^2}2}\sqrt n\,dy $$

Anything that is not a variable goes outside!

$$ \begin{aligned} &\cong\sqrt n\,e^{-n}e^{n\ln n}\int_{-\sqrt n}^\infty e^{-\frac{y^2}2}\,dy\\ &\cong\sqrt n\,e^{-n}e^{\ln n^n}\int_{-\sqrt n}^\infty e^{-\frac{y^2}2}\,dy\\ &\cong\sqrt n\,n^ne^{-n}\int_{-\sqrt n}^\infty e^{-\frac{y^2}2}\,dy \end{aligned} $$ $$ n!\cong\sqrt n\,n^ne^{-n}{\color{red}\int_{-\sqrt n}^\infty e^{-\frac{y^2}2}\,dy} $$

We have got this far.

Now we need to tidy up the red part.

$$ n!\cong\sqrt n\,n^ne^{-n}\left[\int_{-\infty}^\infty e^{-\frac{y^2}2}\,dy-\int_{-\infty}^{-\sqrt n}e^{-\frac{y^2}2}\,dy\right] $$

You were not surprised, were you?! Hahahahaha.

$$ n!\cong\sqrt n\,n^ne^{-n}\left[\int_{-\infty}^\infty e^{-\frac{y^2}2}\,dy-{\color{blue}\int_{-\infty}^{-\sqrt n}e^{-\frac{y^2}2}\,dy}\right] $$

We can see that the blue term tends to zero as $n$ gets larger and larger. We said $n$ was unbelievably large when using the Taylor expansion too, so let us throw away the blue part altogether.

$$ n!\cong\sqrt n\,n^ne^{-n}\int_{-\infty}^\infty {\color{red}e^{-\frac{y^2}2}}\,dy $$

This is an even function, so

$$ n!\cong\sqrt n\,n^ne^{-n}\,2\int_0^\infty e^{-\frac{y^2}2}\,dy $$

Integration by substitution

$$ \begin{aligned} t&=\frac{y^2}2,\quad y=\sqrt{2t}\\ dt&=y\,dy\\ dy&=\frac1{\sqrt{2t}}\,dt \end{aligned} $$$$ \begin{aligned} n!&\cong\sqrt n\,n^ne^{-n}\,2\int_0^\infty e^{-t}\frac1{\sqrt{2t}}\,dt \cong\sqrt n\,n^ne^{-n}\frac2{\sqrt2}\int_0^\infty e^{-t}t^{-\frac12}\,dt\\ &\cong\sqrt n\,n^ne^{-n}\frac2{\sqrt2}\Gamma\left(\frac12\right) \cong\sqrt n\,n^ne^{-n}\sqrt{2\pi} \end{aligned} $$$$ \begin{aligned} \therefore\quad n!&\cong\sqrt n\,n^ne^{-n}\sqrt{2\pi}\\ &\cong n^ne^{-n}\sqrt{2\pi n} \end{aligned} $$

Taking the logarithm of both sides gives

$$ \ln n!\cong n\ln n-n+\frac12\ln 2\pi n $$

If $n$ is very large, in $n!\cong n^ne^{-n}{\color{red}\sqrt{2\pi n}}$, we can throw away the red part too.

Therefore,

$$ n!\cong n^ne^{-n} $$

Taking the logarithm of both sides gives

$$ \ln n!\cong n\ln n-n $$

Ah, finally, it is done. T_T T_T

Editorial clarifications separate from the original note

  1. The first integral and differentiation argument assume real $\alpha>0$ (more generally $\Re\alpha>0$), with nonnegative integer $n$. Differentiation under the integral needs the corresponding convergence justification.
  2. The Euler integral $\Gamma(z)=\int_0^\infty x^{z-1}e^{-x}\,dx$ defines the Gamma function directly for $\Re z>0$. Values such as $\Gamma(-1/2)$ and $\Gamma(-3/2)$ in the table use analytic continuation through the recurrence $\Gamma(z+1)=z\Gamma(z)$, rather than direct substitution into a convergent Euler integral. Gamma has poles at $0,-1,-2,\ldots$. Thus the original general statement about zero, rational, or negative arguments needs these qualifications; $0!=1$ is already a valid factorial value, and $\Gamma(1)=1$ agrees with it. The source’s brief identification of the right-hand integral with $\Gamma(n)$ is off by one: that integral is $\Gamma(n+1)$, as the next displayed equation correctly states.
  3. In this note, $\ln n!$ means $\ln(n!)$, and $\ln 2\pi n$ means $\ln(2\pi n)$. The original notation and approximation glyph $\cong$ are preserved above. The approximation concerns large positive $n$; the substitution $x=n+y\sqrt n$ uses $n>0$.
  4. The Taylor series for $\ln(1+y/\sqrt n)$ converges for $|y|<\sqrt n$. Its truncation is not a uniform justification over the entire integration range. A complete asymptotic argument controls the region near the maximum and the tails separately. The Gaussian tail removed later does tend to zero as $n\to\infty$.
  5. Stirling’s leading multiplicative asymptotic is $n!\sim\sqrt{2\pi n}(n/e)^n$. Removing $\sqrt{2\pi n}$ from this formula does not give a multiplicative asymptotic equivalent: the ratio to $(n/e)^n$ grows like $\sqrt{2\pi n}$. It is valid to omit the smaller term at leading logarithmic order: $\ln(n!)=n\ln n-n+\tfrac12\ln(2\pi n)+O(1/n)$, and $\ln(n!)\sim n\ln n-n$ as $n\to\infty$.

These bounded clarifications are new editorial material, not translated source prose.

Comments

Discussion happens via GitHub Discussions. You'll need a GitHub account to comment.