views:

258

answers:

3

Is there some way to calculate the inverse factorials of real numbers?

For example - 1.5 ! = 1.32934039

Is there some way to obtain 1.5 back if I have the value 1.32934039?

I am trying

http://www.wolframalpha.com/input/?i=Gamma^(-1)[1.32934039]

but that is a fail.

+2  A: 

For integers you can do:

i = 2
n = someNum
while (n != 1):
    n /= i
    i += 1
return (i==1 ? i : None)

The factorial for real numbers has no inverse. You say that "each function must have an inverse". That is incorrect. Consider the constant function f(x)=0. What is f^-1(42)? For a function to be inverse it must be both an injection and a surjection.

Yuval A
It should be `i = 1`, the division and increment should be swapped, and you can just return `i`.
Matthew Flaschen
He doesn't say "each function" (but maybe he edited it?). But `Γ(x)` on `[2,∞)` is (unlike `f(x)=0`) injective. There should be an inverse on at least that subdomain.
Ken
@Yuval A: thanks, I understand the inverse concepts though. What I said was in context of the gamma function - because it appears that it is a one-one non-decreasing function, atleast for positive real numbers.
Lazer
+4  A: 

Using wolframalpha.com, you can ask for

Solve[Gamma[x+1]==1.32934039,x]

As mentioned in the comments, Gamma does not have a unique inverse. True even when you are solving for a conventional factorial, e.g.

Solve[Gamma[x+1]==6,x]

yields several answers, of which one is 3.

Instead of using Gamma[] in WolframAlpha, you can also use Factorial[]:

Solve[Factorial[x]==6,x]
Solve[Factorial[x]==1.32934039,x]
brainjam
"The convential factorial" is only defined on the natural numbers {0, 1, 2, ...}, and for this the only problem here is that 0! = 1!. (For instance, x! = 6 has only one root in the natural numbers, namely 3.)
Andreas Rejbrand
@Andreas, OP is asking about a generalization of conventional factorials known as the gamma function. This is implemented in Mathematica/WolphramAlpha as Gamma[x+1] or Factorial[x]. Give it a try.
brainjam
Of course I know that. I am very well familiar with the Gamma function. But brainjam says that "Gamma does not have a unique inverse. True even when you are solving for a conventional factorial, e.g. Solve[Gamma[x+1]==6,x]yields several answers, of which one is 3." This can be interpreted as if x! = 6 has several solutions on the natural numbers, which is false. The only solution is 3. Maybe it is just bad wording.
Andreas Rejbrand
@Andreas, thanks for the clarification. Sorry for implying you didn't know about Gamma, you probably know more about than I do.
brainjam
Do anyone get some result for `Solve[Gamma[x+1]==2^1024,x]`? I am getting nothing.
Lazer
@Lazer, nope, it fails silently. I believe it's solving numerically, and that the big numbers in question are probably causing it to get lost (i.e. not converge on a solution). 2^1024 is in the ballpark of 170!, which is pretty big.
brainjam
@Lazer - For large values, you should use `FindRoot` (and `LogGamma`) instead. In Mathematica 7: `FindRoot[LogGamma[x + 1] - Log[2^1024] == 0, {x, Log[2^1024]}]` `Out[1]= {x -> 170.624}`.
Rex Kerr
@Lazer Wolfram alpha calculates OK till 2^268. With 2^269 it fails silently (MBS: manual binary search :) )
belisarius
@Rex Kerr: thanks!
Lazer
+4  A: 

David Cantrell gives a good approximation of Γ-1(n) on this page:

k = the positive zero of the digamma function, approximately 1.461632
c = Sqrt(2*pi)/e - Γ(k), approximately 0.036534
L(x) = ln((x+c)/Sqrt(2*pi))
W(x) = Lambert W function
ApproxInvGamma(x) = L(x) / W(L(x) / e) + 1/2
BlueRaja - Danny Pflughoeft