// HACKER NEWS — CYBERSECURITY
How Big Are Factorials?
The other day, I found myself wondering how big 52! (52 factorial) is,
and that led me to ponder how these could be estimated without a
calculator or a computer.
It turns out there’s some fairly interesting math behind being able to
estimate the size (number of digits) of a factorial reasonably
accurately. This post will start by stating how to do the estimate, and
if you’re curious you can read on for the math background.
As an example, let’s use my original question, by estimating this for
52!
Well, 52 divided by e is... 20-ish? And \log_{10}(20) is
about 1.3 [1]; therefore our estimate comes out to:
The real answer is 68, so this is very close! In estimates like this -
when you’re dealing with enormous numbers - being off by a couple of
digits usually isn't a big deal.
This integral does not have an analytic expression in the general case,
but it does have a very useful property that we can take advantage of.
Let’s see what \Gamma(n+1) is:
But notice that the last integral is just \Gamma(n); therefore,
we’ve shown that:
Let’s also calculate \Gamma(1) - it’s a special case that has an
analytical solution:
In other words - the Gamma function is an interpolation of the factorial
over all positive reals. Here’s a plot of the Gamma function over a
small range; note that the y axis is log-scale because of the function’s
fast growth:
You may have encountered Stirling’s approximation before: