Thursday, October 18, 2018

Stirlings approximation

The factorial is typically defined by the product of the first $n$ numbers. It can therefore be assumed that the factorial can simply be defined by the product of the first $n$ numbers and that is all there is to it. But actually, to compute the factorials of large numbers it is better to use a different algorithm then that. The best ones tend to use the prime factorization, by noting that the prime factors of $n!$ are all less then $n$ as well as some variant of Legendre's formula which determines the exponents of the prime factors of the factorial. The best algorithm to compute factorials seems to be the prime swing algorithm which reduces it to the swings, with a good big integer library this can be used to compute very large factorials quickly.

Considering that the factorial can be expressed in different ways, it is worth considering how it can be expressed asymptotically. To begin with we know that the factorial function $n!$ grows super-exponentially because $n!$ is multiplied by increasing large numbers as the sequence grows. When one considers super-exponential functions one of the first functions that comes to mind is $n^n$. As it turns out the ratio between $n^n$ and $n!$ grows only exponentially, so it can be reduced. In order to consider the base of this exponential growth rate, we will divided consecutive terms of it. $$\frac{\frac{(n+1)^{(n+1)}}{(n+1)!}}{\frac{n^n}{n!}}$$ We can change $(n+1)!$ to $n!*(n+1)$ and then remove $n!$ from both sides. After that we can remove one from the exponent of $n+1$ by dividing it by $n+1$ to get the reduced formula. $$\frac{(n+1)^n}{n^n}$$ The resulting formula ${(\frac{n+1}{n})}^n$ is precisely the limit definition of $e$ which is what we are familiar with. $${(\frac{n+1}{n})}^n$$ This demonstrates that the ratio between $n^n$ and $n!$ grows exponentially. As both of these two functions have interpretations in combinatorics, with $n^n$ counting the number of functions on a set and $n!$ counting the number of them that are reversible, this counts the ratio of reversibility of them. This ratio grows exponentially at a rate with a base of $e$ as we have shown. This seems to be a fundamental theorem about the nature of reversibility. This gives us a hint as to how we can asymptotically approximate $n!$. Abraham De Moivre demonstrated that $n!$ grows at the rate of $\frac{n^n}{e^n}$ times $\sqrt{n}$ as well as some constant left to be determined later. $$n! \sim c \sqrt{n} \frac{n^n}{e^n}$$ Stirling then proved that the constant is equal to the square root of $2\pi$ which produces Stirlings formula for the factorial. $$n! \sim \sqrt{2\pi n} \frac{n^n}{e^n}$$ This equation given by Stirling is the full asymptotic definition of the factorial function. The appearance of $e$ in the asymptotic definition of factorial also gives some insight into why it is that the reciprocals of the factorials happen to converge to $e$.

No comments:

Post a Comment