![cover image](https://wikiwandv2-19431.kxcdn.com/_next/image?url=https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Mplwp_factorial_gamma_stirling.svg/640px-Mplwp_factorial_gamma_stirling.svg.png&w=640&q=50)
Stirling's approximation
Approximation for factorials / From Wikipedia, the free encyclopedia
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 . It is named after James Stirling, though a related but less precise result was first stated by Abraham de Moivre.[1][2][3]
![Thumb image](http://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Mplwp_factorial_gamma_stirling.svg/320px-Mplwp_factorial_gamma_stirling.svg.png)
One way of stating the approximation involves the logarithm of the factorial:
where the big O notation means that, for all sufficiently large values of
, the difference between
and
will be at most proportional to the logarithm. 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
The error term in either base can be expressed more precisely as
, corresponding to an approximate formula for the factorial itself,
Here the sign
means that the two quantities are asymptotic, that is, that their ratio tends to 1 as
tends to infinity. The following version of the bound holds for all
, rather than only asymptotically: