31

I don't want to do this through trial and error, and the best way I have found so far was to start dividing from 1.

$n! = \text {a really big number}$

Ex. $n! = 9999999$

Is there a way to approximate n or solve for n through a formula of some sort?

Update (Here is my attempt):

Stirling's Approximation: $$n! \approx \sqrt{2 \pi n} \left( \dfrac{n}{e} \right ) ^ n$$

So taking the log:

$(2\cdot \pi\cdot n)^{1/2} \cdot n^n \cdot e^{-n}$
$(2\cdot \pi)^{1/2} \cdot n^{1/2} \cdot n^n \cdot e^{-n}$
$.5\log (2\pi) + .5\log n + n\log n \cdot -n \log e$
$.5\log (2\pi) + \log n(.5+n) - n$

Now to solve for n:

$.5\log (2\pi) + \log n(.5+n) - n = r$
$\log n(.5+n) - n = r - .5 \log (2\pi)$

Now I am a little caught up here.

3 Answers3

21

A good approximation for $n!$ is that of Stirling: $n!$ is approximately $n^ne^{-n}\sqrt{2\pi n}$. So if $n!=r$, where $r$ stands for "really large number," then, taking logs, you get $\left(n+\frac12\right)\log n-n+\frac12\log(2\pi)$ is approximately $\log r$. Now you can use Newton's method to solve $\left(n+\frac12\right)\log n-n+\frac12\log(2\pi)=\log r$ for $n$.

Gerry Myerson
  • 179,216
  • Shouldn't it be n+(1/2)? in the first part of: (n−(1/2))logn−n+(1/2)log(2π). And what does taking the log of stirling's approximation mean? I honestly am a little bit unclear with logs when trying to isolate n. Could you show me step by step how to do that? – Strawberry Sep 04 '11 at 09:27
  • 1
    @Doug: you're right. Gerry, I hope you don't mind that I fixed your sign slip. – J. M. ain't a mathematician Sep 04 '11 at 09:35
  • I just added my attempt, hopefully someone can give me a hand. Also, should I start a new question for explanation of what is the log actually doing? – Strawberry Sep 04 '11 at 09:41
  • 4
    Thanks for fixing the sign. I made another mistake, writing $r$ where I needed $\log r$ at the end. I'll fix that one. Doug, all the log is doing is making the problem look a little nicer. You can't isolate $n$; what you can do, as I said, is use Newton's Method, which you can look up. Newton's Method uses Calculus. If you haven't done Calculus yet, you could start by seeing how close $n=\log r/\log\log r$ is to a solution, and then go a little higher or lower as necessary. – Gerry Myerson Sep 04 '11 at 12:31
6

$\exp(1+W(\log(n!)/e))-\frac{1}{2}\searrow n$ as $n\to\infty$where $W$ is the Lambert W function. For integer $n\ge2$, the floor is exact.

I just took the expansion out a bit more and the approximation I gave above overestimates $n$ by $\log\left(\sqrt{2\pi}\right)/\log(n)$.

robjohn
  • 345,667
1

I believe you can solve Sterling’s formula for $n$ by way of the Lambert $W$ function, but that just leads to another expression, which can not be directly evaluated with elementary operations. (Although, I wish scientific calculators included the Lambert $W$, at least the principal branch).

I’ve derived a formula which is moderately accurate. If you are rounding to integer values of $n$, it will provide exact results through $170!$, and perhaps further. The spreadsheet app on my iPad will not compute factorials beyond $170!$.

If you are seeking rational solutions for $n$, in other words, trying to calculate values of a sort of inverse Gamma function, it will provide reasonably close approximations for $n$ in $[2, 170]$, and as I remarked above, possibly greater.

My Clumsy Little Equation:

I also have derived a variant which is much more accurate for $n$ in $[2, 40\text{ish}]$, however it starts to diverge beyond that.

I initially derived these approximations for my daughter, who, while working on Taylor/Maclaurin series, wanted a quick way to check for potential factorial simplifications in the denominator of terms.

I couldn’t find any solutions, except the obvious path through Stirling’s formula and the Lambert $W$ function. If more competent mathematicians can find a tweak which can improve accuracy, please share it.

I apologize in advance, as I am new here (as a contributor, that is), and I am not yet allowed to directly embed an image. Hopefully, the linked one works.

311411
  • 3,537
  • 9
  • 19
  • 36