15
$\begingroup$

The factorial function cannot have an inverse, $0!$ and $1!$ having the same value. However, Stirling's approximation of the factorial $x! \sim x^xe^{-x}\sqrt{2\pi x}$ does not have this problem, and could provide a ballpark inverse to the factorial function. But can this actually be derived, and if so how? Here is my work:

$$ \begin{align} y &= x^xe^{-x}\sqrt{2\pi x}\\ y^2 &= 2\pi x^{2x + 1}e^{-2x}\\ \frac{y^2}{2\pi} &= x^{2x + 1}e^{-2x}\\ \ln \frac{y^2}{2\pi} &= (2x + 1)\ln x - 2x\\ \ln \frac{y^2}{2\pi} &= 2x\ln x + \ln x - 2x\\ \ln \frac{y^2}{2\pi} &= 2x(\ln x - 1) + \ln x \end{align} $$

That is as far as I can go. I suspect the solution may require the Lambert W function.

Edit: I have just realized that after step 3 above, one can divide both sides by e to get

$$\left(\frac{x}{e}\right)^{2x + 1} = \frac{y^2}{2e\pi}$$

Can this be solved?

$\endgroup$
6
  • 1
    $\begingroup$ This question may be of interest to you. $\endgroup$ Jun 26, 2013 at 18:00
  • 2
    $\begingroup$ That's not Stirling's approximation. $\endgroup$
    – Lee Sleek
    Jun 28, 2013 at 17:45
  • 6
    $\begingroup$ @LeeSleek an approximation to the inverse gamma function will give you something similar to an inverse Stirling approximation. If that's what you want, it'll work. $\endgroup$
    – icurays1
    Jun 28, 2013 at 17:52
  • 1
    $\begingroup$ I said "may be of interest to you", not that it answers your question. Otherwise I would've posted it as an answer. $\endgroup$ Jun 29, 2013 at 18:43
  • 2
    $\begingroup$ @diophantine $n! = n(n-1)!, 1! = 1(1 - 1)!, 1 = 1(0!), 0! = 1.$ Furthermore, the convention is that the product of no numbers at all is 1. $\endgroup$
    – Lee Sleek
    Jun 30, 2013 at 0:54

3 Answers 3

32
$\begingroup$

It is better to start with $$ x! \approx \left( {\frac{{x + \frac{1}{2}}}{\mathrm{e}}} \right)^{x + \frac{1}{2}} \sqrt {2\pi } . $$ Setting $$ y = \left( {\frac{{x + \frac{1}{2}}}{\mathrm{e}}} \right)^{x + \frac{1}{2}} \sqrt {2\pi } , $$ we find $$ \frac{1}{\mathrm{e}}\log \left( {\frac{y}{{\sqrt {2\pi } }}} \right) = \frac{{x + \frac{1}{2}}}{\mathrm{e}}\log \left( {\frac{{x + \frac{1}{2}}}{\mathrm{e}}} \right) = \exp \left( {\log \left( {\frac{{x + \frac{1}{2}}}{\mathrm{e}}} \right)} \right)\log \left( {\frac{{x + \frac{1}{2}}}{\mathrm{e}}} \right). $$ We use the Lambert $W$-function defined by $W(z)\mathrm{e}^{W(z)} = z$ for $z>0$. From the above we see that $$ \log \left( {\frac{{x + \frac{1}{2}}}{\mathrm{e}}} \right) = W\!\left( {\frac{1}{\mathrm{e}}\log \left( {\frac{y}{{\sqrt {2\pi } }}} \right)} \right). $$ Whence $$ \frac{{x + \frac{1}{2}}}{\mathrm{e}} = \exp \left( {W\!\left( {\frac{1}{\mathrm{e}}\log \left( {\frac{y}{{\sqrt {2\pi } }}} \right)} \right)} \right) = \frac{{\frac{1}{\mathrm{e}}\log \left( {\frac{y}{{\sqrt {2\pi } }}} \right)}}{{W\!\left( {\frac{1}{\mathrm{e}}\log \left( {\frac{y}{{\sqrt {2\pi } }}} \right)} \right)}}, $$ i.e., $$ x = \frac{{\log \left( {\frac{y}{{\sqrt {2\pi } }}} \right)}}{{W\!\left( {\frac{1}{\mathrm{e}}\log \left( {\frac{y}{{\sqrt {2\pi } }}} \right)} \right)}} - \frac{1}{2}. $$ For example, if $y=720$ then $$ x = \frac{{\log \left( {\frac{{720}}{{\sqrt {2\pi } }}} \right)}}{{W\!\left( {\frac{1}{\mathrm{e}}\log \left( {\frac{{720}}{{\sqrt {2\pi } }}} \right)} \right)}} - \frac{1}{2} \approx 5.99658, $$ which is a very good approximation.

$\endgroup$
11
  • 1
    $\begingroup$ In my time on this site I have seen two beautiful answers. This is the second. I want to upvote this a thousand times. Thank you so much! $\endgroup$
    – Lee Sleek
    Aug 6, 2013 at 18:56
  • $\begingroup$ Note: using the laws of logarithms, we can avoid nested fractions and write the formula as $\frac{\ln y - \ln \sqrt{2\pi}}{W(\ln \sqrt[e]{y} - \ln \sqrt[2e]{2\pi})} - \frac{1}{2}$. $\endgroup$
    – Lee Sleek
    Aug 6, 2013 at 19:47
  • 1
    $\begingroup$ The link does not work properly, but I would like to point out that this formula is an asymptotic one, i.e., valid for large $y$. In fact, it can be shown that $$ x = \frac{{\log \left( {\frac{y}{{\sqrt {2\pi } }}} \right)}}{{W\left( {\frac{1}{e}\log \left( {\frac{y}{{\sqrt {2\pi } }}} \right)} \right)}} - \frac{1}{2} + \mathcal{O}\left( {\frac{1}{{\log y}}} \right) $$ as $y \to +\infty$. $\endgroup$
    – Gary
    Aug 7, 2013 at 13:59
  • 2
    $\begingroup$ I did not claim that those two are equal. However, both of them is asymptotic to $x!$ as $$\frac{{\left( {\frac{{x + \frac{1}{2}}}{e}} \right)^{x + \frac{1}{2}} \sqrt {2\pi } }}{{\left( {\frac{x}{e}} \right)^x \sqrt {2\pi x} }} = e^{ - \frac{1}{2}} \left( {1 + \frac{1}{{2x}}} \right)^{x + \frac{1}{2}} \to e^{ - \frac{1}{2}} e^{\frac{1}{2}} = 1 $$ when $x\to +\infty$. $\endgroup$
    – Gary
    Aug 15, 2013 at 13:38
  • 6
    $\begingroup$ My approximation for the inverse is correct. Please, do not try to find errors in it. You asked a question and I answered it. What is your goal? $\endgroup$
    – Gary
    Aug 15, 2013 at 13:40
9
+100
$\begingroup$

As $n$ increases to infinity we want to know roughly the size of the $x$ that satisfies the equation $x! = n$. By Stirling $$ x^x e^{-x} \sqrt{2\pi x} \sim n $$ Just focusing on $x^x$ a first approximation is $\log n / \log\log n$. Now writing $x = \log n / \log\log n + x_1$ and solving approximately for $x_1$, this time using $x^x e^{-x}$ we get $$ x = \frac{\log n}{\log\log n} + \frac{\log n \cdot ( \log\log\log n + 1)}{(\log\log n)^2} + x_2 $$ with a yet smaller $x_2$ which can be also determined by plugging this into $x^x e^{-x}$. You'll notice eventually that the $\sqrt{2\pi x}$ is too small to contribute. You can continue in this way, and this will give you an asymptotic (non-convergent) serie (in powers of $\log\log n$). For more I recommend looking at De Brujin's book "Asymptotic methods in analysis". He specifically focuses on the case of $n!$ case in one of the Chapters (don't have the book with me to check).

$\endgroup$
3
  • 1
    $\begingroup$ I second your recommendation of De Brujin's book - it is a classic well worth reading. $\endgroup$ Jun 30, 2013 at 5:38
  • $\begingroup$ I am only awarding you this bounty because I don't want it to go to waste and yours is the only answer. $\endgroup$
    – Lee Sleek
    Jul 5, 2013 at 19:31
  • $\begingroup$ Could you please explain why $\log n/\log \log n$ is an approximation for $s$ if $n=s^s$? (pointing to a source would be enough) Thank you. $\endgroup$ Oct 16, 2018 at 5:59
1
$\begingroup$

If you wish to make an inverse of the factorial for a fractional value, try starting with one of the aproximations here and solving for $x$. The two formulas are $$x!\approx\sqrt{2\pi}x^xe^{-x}\sqrt{x+\frac{1}{6}+\frac{1}{72x}-\frac{31}{6480x^2}-\frac{139}{155520x^3}+\frac{9871}{6531840x^4}}\\ x!\approx\sqrt{2\pi}x^xe^{-x}\root{\LARGE{4}}\of{x^2+\frac{x}{3}+\frac{1}{18}-\frac{2}{405x}-\frac{31}{9720x^2}}$$ They may not be as simple to solve as your Stirling approximation, but they're much more accurate for smaller values of $x$. Read the article while you're at it.

Update: apparently Ramanujan's approximation is even more accurate. $$x!\approx\sqrt{\pi}\left(\frac{x}{e}\right)^x\root{\LARGE{6}}\of{8x^3+4x^2+x+\frac{1}{30}}$$

$\endgroup$
2
  • $\begingroup$ Um, I think I spoke too soon. I tried plugging $.1$ into the first formula, and I think I got $9$-point-something. But they're very accurate for $x\ge1$. $\endgroup$ Feb 13, 2014 at 4:14
  • $\begingroup$ If you look at math.stackexchange.com/questions/3629388/… the extension $P_6(n)$ gives $1.00011$ for $n=1$ $\endgroup$ May 12, 2020 at 11:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .