The Stirling Formula
The Stirling formula is an essential tool for simplifying calculations with factorials of large numbers, offering a quick and practical approximation.
This result is especially useful in areas such as thermodynamics, probability, and asymptotic analysis, where working with extremely large numbers is common. Understanding its derivation not only facilitates its application but also allows appreciation of its relevance in efficient calculation and solving complex problems.
Learning Objectives:
At the end of this class, the student will be able to:
- Understand the derivation of Stirling’s formula from the definition of the factorial using the Gamma function.
- Apply Stirling’s formula to approximate factorials of very large numbers.
- Calculate logarithmic approximations of factorials using basic logarithmic and exponential tools.
TABLE OF CONTENTS:
Derivation of Stirling’s Formula
Logarithmic Approximation of Factorials
Example: Approximation of the Factorial of a Very Large Number
Derivation of Stirling’s Formula
The derivation of Stirling’s formula begins with the definition of the factorial using the Gamma function, which is:
n! =\Gamma(n+1) = \displaystyle \int_0^\infty t^n e^{-t} \, dt
Using this expression, we perform a variable change: t = nx. This implies that x \in [0, \infty[ and dt = n dx. With this change, the integral transforms as follows:
n! = \Gamma(n+1) = \displaystyle \int_0^\infty (nx)^n e^{-nx} n \, dx = n^{n+1} \int_0^\infty x^n e^{-nx} dx
Next, we perform a second variable change: x = 1 + \dfrac{s}{\sqrt{n}}. This implies:
\begin{array}{rl} & s = (x-1)\sqrt{n}, \quad s \in [-\sqrt{n}, \infty[ \\ \\ & dx = \dfrac{ds}{\sqrt{n}} \end{array}
With this variable change, the integral takes the following form:
\begin{array}{rl} n! = \Gamma(n+1) &= \displaystyle n^{n+1} \int_{-\sqrt{n}}^\infty \left( 1 + \dfrac{s}{\sqrt{n}} \right)^n e^{-n\left(1+\dfrac{s}{\sqrt{n}}\right)} \dfrac{ds}{\sqrt{n}} \\ \\ &= \displaystyle \dfrac{n^{n+1}}{\sqrt{n}} \int_{-\sqrt{n}}^\infty e^{n\ln\left( 1 + \dfrac{s}{\sqrt{n}} \right)} e^{-n - s\sqrt{n}} ds \\ \\ &= \displaystyle n^n e^{-n} \sqrt{n} \int_{-\sqrt{n}}^\infty e^{n\ln\left(1+\dfrac{s}{\sqrt{n}}\right) - s\sqrt{n}} ds \end{array}
Now we use the Taylor series expansion for the natural logarithm:
\ln(1+x) = \displaystyle\sum_{k=1}^{\infty} \dfrac{(-1)^{k+1}x^k}{k}
Applying this expansion to \ln\left(1+\dfrac{s}{\sqrt{n}}\right), we expand the exponential expression as follows:
\begin{array}{rl} n\ln\left(1+\dfrac{s}{\sqrt{n}}\right) - s\sqrt{n} & = \displaystyle n \left[\sum_{k=1}^{\infty} \dfrac{(-1)^{k+1}\left(\dfrac{s}{\sqrt{n}} \right)^k}{k} \right] - s\sqrt{n} \\ \\ & = n \left[ \dfrac{s}{\sqrt{n}} - \dfrac{s^2}{2n} + \dfrac{s^3}{3n\sqrt{n}} - \dfrac{s^4}{4n^2} + \dfrac{s^5}{5n^2\sqrt{n}} \cdots \right] - s\sqrt{n} \\ \\ & = s\sqrt{n} - \dfrac{s^2}{2} + \dfrac{s^3}{3\sqrt{n}} - \dfrac{s^4}{4n} + \dfrac{s^5}{5n\sqrt{n}} \cdots - s\sqrt{n} \\ \\ & = - \dfrac{s^2}{2} + \dfrac{s^3}{3\sqrt{n}} - \dfrac{s^4}{4n} + \dfrac{s^5}{5n\sqrt{n}} \cdots \\ \\ & = - \dfrac{s^2}{2} + \displaystyle \sum_{k=3}^\infty \dfrac{(-1)^{k+1}s^k}{k\sqrt{n^{k-2}}} \end{array}
Thus, we can write the full expression as:
n! = \Gamma(n+1) = \displaystyle n^n e^{-n} \sqrt{n} \int_{-\sqrt{n}}^\infty e^{- \dfrac{s^2}{2} + \displaystyle \sum_{k=3}^\infty \dfrac{(-1)^{k+1}s^k}{k\sqrt{n^{k-2}}}} ds
This result is fundamental for calculating factorials of very large numbers. As n grows, the terms in the summation inside the exponential tend to zero, leaving only the dominant term. This simplifies the integral, which can be solved as a Gaussian integral:
n! = \Gamma(n+1) \approx \displaystyle n^n e^{-n} \sqrt{n} \int_{-\infty}^\infty e^{- \frac{s^2}{2}} ds = n^n e^{-n} \sqrt{n} \sqrt{2\pi}
This result is known as Stirling’s formula for the factorial of large numbers:
\boxed{n! \approx \sqrt{2\pi n}\left(\dfrac{n}{e}\right)^{n}}
Logarithmic Approximation of Factorials
A direct result of Stirling’s formula is the logarithmic approximation of the factorial. Taking the natural logarithm of Stirling’s formula, we obtain:
\begin{array}{rcl} \ln(n!) \approx \ln\left( \sqrt{2n\pi}\left(\dfrac{n}{e}\right)^{n} \right) &=& \dfrac{1}{2}\ln(2n\pi) + n\ln\left(\dfrac{n}{e}\right) \\ \\ &=& \dfrac{1}{2}\ln(2n\pi) + n\ln(n) - n \\ \\ &\approx & n\ln(n) - n \end{array}
In the last step, an additional approximation is made by neglecting the term \dfrac{1}{2}\ln(2n\pi). This term becomes insignificant compared to n\ln(n) - n for large values of n.
The validity of this approximation is justified by calculating the relative error between the two expressions:
\begin{array}{rcl} \text{Initial Approximation} & = & \dfrac{1}{2}\ln(2n\pi) + n\ln(n) - n \\ \\ \text{Final Approximation} & = & n\ln(n) - n \\ \\ \text{Relative Error} &=& \dfrac{\text{Final Approximation} - \text{Initial Approximation}}{\text{Initial Approximation}} \\ \\ &=& \dfrac{-\dfrac{1}{2}\ln(2n\pi)}{\dfrac{1}{2}\ln(2n\pi) + n\ln(n) - n} \end{array}
Now consider the limit as n \to \infty:
\begin{array}{rl} \displaystyle \lim_{n\to\infty} \text{Relative Error} & = \displaystyle \lim_{n\to\infty} \dfrac{-\dfrac{1}{2}\ln(2n\pi)}{\dfrac{1}{2}\ln(2n\pi) + n\ln(n) - n} \\ \\ & = \displaystyle \lim_{n\to\infty} \dfrac{-\dfrac{1}{2n}}{\dfrac{1}{2n} + \ln(n) + 1 - 1} = 0 \end{array}
Thus, since the error tends to zero for large values of n, we can confidently use the following logarithmic approximation:
\boxed{\ln(n!) \approx n\ln(n) - n}
Example: Approximation of the Factorial of a Very Large Number
Calculating the factorial of extremely large numbers, such as 10,000!, is practically impossible with conventional tools due to the size of the result. However, using the logarithmic approximation of the factorial derived from Stirling’s formula, we can make it manageable even with basic calculators.
The logarithmic formula of the factorial states:
\ln(10,000!) \approx 10,000 \ln(10,000) - 10,000
To convert from natural logarithms (\ln) to base-10 logarithms (\log), we use the relationship:
\ln(10,000!) = \dfrac{\log(10,000!)}{\log(e)}
This implies that:
\log(10,000!) \approx \log(e) \cdot (10,000 \ln(10,000) - 10,000)
Thus:
10,000! \approx 10^{\log(e) \cdot (10,000 \ln(10,000) - 10,000)} \approx 10^{35,657.06}
Here, we observe that the exponent becomes manageable for most calculators. Thus, while we may not be able to visualize the number due to its immense size, we know that it contains approximately 35,657 digits. This approach turns an otherwise unattainable calculation into something feasible.
