Most of us might be familiar with factorials, such as \( 5! \), which equals \(5 \cdot 4 \cdot 3 \cdot 2 \cdot 1 = 120 \). Here's the main definition of a factorial, given some integer \(n \):
\[ n! = n \times (n-1) \times (n-2) \times \cdots \times 2 \times 1 \]
One question you might be asking is WHAT ABOUT NON-INTEGERS?!?!?! Good question! It turns out that the above definition is actually a generalization of a MUCH scarier definition for the factorial:
\[ z! = \int_{0}^{\infty} x^ze^{-x}\,dx\ \]
What's crazy is that the above formula works for ALL non-negative real numbers \( z \). Now, the question of how the this formula was even formed is NOT the focus today. Rather. the focus will be about solving equations like these:
\[ x! = 100 \]
There isn't realllllly a good way to solve an equation like this. I mean, I guess you'll need to take the INVERSE factorial on both sides or something?? What does the inverse factorial even mean???
Good news, as it turns out that's what we're gonna be doing today! HOWEVERRRR, first we need to use Stirling's Approximation:
\[ x! \approx \left(\frac{x}{e}\right)^x\sqrt{2\pi x} \]
This will basically give us a tangible equation we can work with that's close enough to the factorial value! If we replace the left hand side with \( y \):
\[ y \approx \left(\frac{x}{e}\right)^x\sqrt{2\pi x} \]
What we can then do is manipulate this equation such that we only have \( x \) on one side, and some expression in terms of \( y \) on the other!
However, in order to make our lives easier, we actually want to use the following version of Stirling's Approximation instead (and we'll be seeing why this version will be more useful very soon):
\[ y \approx \left(\frac{x+\frac{1}{2}}{e}\right)^{x+\frac{1}{2}}\sqrt{2\pi} \]
Feel free to verify for yourself that this approximation is good anough for the factorial (you can use graphing, Wolfram Alpha, etc.). REGARDLESS, now we can get on to solving this equation in terms of \( x \), giving us a closed form equation to compute very close values to equations like \( x! = 100 \). Firstly, let's divide both sides by \( \sqrt{2\pi} \):
\[ \frac{y}{\sqrt{2\pi}} \approx \left(\frac{x+\frac{1}{2}}{e}\right)^{x+\frac{1}{2}} \]
Now let's get rid of the annoying variable in the exponent by then taking the natural logarithm on both sides:
\[ \ln\left(\frac{y}{\sqrt{2\pi}}\right) \approx \left(x+\frac{1}{2}\right)\ln\left(\frac{x+\frac{1}{2}}{e}\right) \]
So that's all well and good, but now what??? We have fractions, logarithms, square roots... how the heck do we isolate \( x \)???
The answer lies in the magical Lambert W Function, an absolute game-changer! Watching the linked video will be necessary for continuing on with the algebra!
Simply put, the Lambert W function, \( W(x) \), has the following property
\[ W(ae^a) = a \]
A closed form equation for this function doesn't really exist to my knowledge, but by just using the property above we can do some real damage!
Specifically, first divide both sides by \( e \). This yields
\[ \frac{1}{e}\ln\left(\frac{y}{\sqrt{2\pi}}\right) \approx \frac{x+\frac{1}{2}}{e}\ln\left(\frac{x+\frac{1}{2}}{e}\right) \]
While doing this may seem completely unnecessary, try looking closer! The right hand side is in the form \( ae^a\), because we can say that \( a = \ln(\frac{x+\frac{1}{2}}{e})\) (keep in mind that \( e^{\ln(x)} = x\)). Therefore, if we apply the Lambert W function on both sides, we get the following:
\[ W\left(\frac{1}{e}\ln\left(\frac{y}{\sqrt{2\pi}}\right)\right) \approx \ln\left(\frac{x + \frac{1}{2}}{e}\right) \]
This is really good, because now our variable \(x \) only appears once on the right hand side, making it easier to isolate it (remember that the end goal here is to solve in terms of \( x \)). Let's take \( e \) to the power of both sides to get rid of that natural logarithm on the right hand side!
\[ e^{W\left(\frac{1}{e}\ln\left(\frac{y}{\sqrt{2\pi}}\right)\right)} \approx \frac{x + \frac{1}{2}}{e} \]
That left hand side looks like sort of a mess, so let's clean it up! We can use this other really nifty property of the Lambert W function, \( W(a)e^{W(a)} = a \Rightarrow e^{W(a)} = \frac{a}{W(a)}\). Therefore, we can rewrite the left hand side as the following:
\[ \frac{\frac{1}{e}\ln\left(\frac{y}{\sqrt{2\pi}}\right)}{W\left(\frac{1}{e}\ln\left(\frac{y}{\sqrt{2\pi}}\right)\right)} \approx \frac{x + \frac{1}{2}}{e} \]
Now, clean up the right side so that \( x \) is by itself, and we FINALLY get a closed form equation in terms of \( x\):
\[ x \approx \frac{\ln\left(\frac{y}{\sqrt{2\pi}}\right)}{W\left(\frac{1}{e}\ln\left(\frac{y}{\sqrt{2\pi}}\right)\right)} - \frac{1}{2} \]
TADA!!!!!!!!!!! Through some algebraic tricks, we have a pretty good closed form approximation for the inverse factorial! Now, I'll leave it up to YOU to try some values. For instance, try out \( x! = 100 \) (which means plug in \( 100 \) into \( y \) in the equation above). If you are using Wolfram Alpha, you can use the Lambert W function by typing in "productlog(insert number/expression here). Have fun!!!