In mathematics, Stirling's approximation is an asymptotic approximation for factorials. It is a good approximation, leading to accurate results even for small values of . It is named after James Stirling, though a related but less precise result was first stated by Abraham de Moivre.
Article
In mathematics, Stirling's approximation (or Stirling's formula) is an asymptotic approximation for factorials. It is a good approximation, leading to accurate results even for small values of
n
{\displaystyle n}
. It is named after James Stirling, though a related but less precise result was first stated by Abraham de Moivre.
One way of stating the approximation involves the logarithm of the factorial:
ln
n
!
=
n
ln
n
−
n
+
O
(
ln
n
)
,
{\displaystyle \ln n!=n\ln n-n+O(\ln n),}
where the big O notation means that, for all sufficiently large values of
n
{\displaystyle n}
, the difference between
ln
n
!
{\displaystyle \ln n!}
and
n
ln
n
−
n
{\displaystyle n\ln n-n}
will be at most proportional to the logarithm of
n
{\displaystyle n}
. In computer science applications such as the worst-case lower bound for comparison sorting, it is convenient to instead use the binary logarithm, giving the equivalent form
De Moivre gave an approximate rational-number expression for the natural logarithm of the constant. Stirling's contribution in 1730 consisted of showing that the constant is precisely
Using the Central Limit Theorem and the Poisson distribution
An alternative version uses the fact that the Poisson distribution converges to a normal distribution by the Central Limit Theorem.
Since the Poisson distribution with parameter
μ
{\displaystyle \mu }
converges to a normal distribution with mean
μ
{\displaystyle \mu }
and variance
μ
{\displaystyle \mu }
, their density functions will be approximately the same:
exp
(
−
μ
)
μ
x
x
!
≈
1
2
π
μ
exp
(
Speed of convergence and error estimates
Stirling's formula is in fact the first approximation to the following series (now called the Stirling series):
n
!
∼
2
π
n
(
n
e
)
n
(
1
+
1
12
n
+
1
288
n
2
−
139
51840
n
3
−
571
2488320
n
4
+
163879
Stirling's formula for the gamma function
For all positive integers,
n
!
=
Γ
(
n
+
1
)
,
{\displaystyle n!=\Gamma (n+1),}
where Γ denotes the gamma function.
However, the gamma function, unlike the factorial, is more broadly defined for all complex numbers other than non-positive integers; nevertheless, Stirling's formula may still be applied. If Re(z) > 0, then
ln
Γ
(
z
)
=
z
ln
z
−
z
+
1
2
ln
A convergent version of Stirling's formula
Thomas Bayes showed, in a letter to John Canton published by the Royal Society in 1763, that Stirling's formula did not give a convergent series. Obtaining a convergent version of Stirling's formula entails evaluating Binet's formula:
For discrete cases, rather than the asymptotic formula described above, a more accurate equation, and much easier to prove result has been derived by T. S. Nanjundiah:
is unimodal, with maximum value zero. Locally around zero, it looks like
−
t
2
2
{\textstyle -{\frac {t^{2}}{2}}}
, which is why we are able to perform Laplace's method. In order to extend Laplace's method to higher orders, we perform another change of variables by
1
+
t
−
e
t
=
−
τ
2
2
{\textstyle 1+t-e^{t}=-{\frac {\tau ^{2}}{2}}}
. This equation cannot be solved in closed form, but it can be solved by serial expansion, which gives us
This line integral can then be approximated using the saddle-point method with an appropriate choice of contour radius
r
=
r
n
{\displaystyle r=r_{n}}
. The dominant portion of the integral near the saddle point is then approximated by a real integral and Laplace's method, while the remaining portion of the integral can be bounded above to give an error term.
An explicit formula for the coefficients in this series was given by G. Nemes. Further terms are listed in the On-Line Encyclopedia of Integer Sequences as A001163 and A001164. The first graph in this section shows the relative error vs.
n
{\displaystyle n}
, for 1 through all 5 terms listed above. The coefficients have the following asymptotic formula:
which shows that it grows superexponentially, and that by the ratio test the radius of convergence is zero.
However, the representation obtained directly from the Euler–Maclaurin approximation, in which the correction term itself is the argument of the exponential function, converges much faster (needs half the number of correction terms for the same accuracy):
As n → ∞, the error in the truncated series is asymptotically equal to the first omitted term. This is an example of an asymptotic expansion. It is not a convergent series; for any particular value of
n
{\displaystyle n}
there are only so many terms of the series that improve accuracy, after which accuracy worsens. This is shown in the next graph, which shows the relative error versus the number of terms in the series, for larger numbers of terms. More precisely, let St (n) be the Stirling series to
is the nth Bernoulli number (note that the limit of the sum as
N
→
∞
{\displaystyle N\to \infty }
is not convergent, so this formula is just an asymptotic expansion). The formula is valid for
z
{\displaystyle z}
large enough in absolute value, when |arg(z)| < π − ε, where ε is positive, with an error term of O(z−2N+ 1). The corresponding approximation may now be written:
where the expansion is identical to that of Stirling's series above for
n
!
{\displaystyle n!}
, except that
n
{\displaystyle n}
is replaced with z − 1.
A further application of this asymptotic expansion is for complex argument z with constant Re(z). See for example the Stirling formula applied in Im(z) = t of the Riemann–Siegel theta function on the straight line 1/4 + it.
can be obtained by rearranging Stirling's extended formula and observing a coincidence between the resultant power series and the Taylor series expansion of the hyperbolic sine function. This approximation is good to more than 8 decimal digits for z with a real part greater than 8. Robert H. Windschitl suggested it in 2002 for computing the gamma function with fair accuracy on calculators with limited program or register memory.
Gergő Nemes proposed in 2007 an approximation which gives the same number of exact digits as the Windschitl approximation but is much simpler: