in reply to Calculate propabilities without recursion? Coin toss.

Your function fac results in n * (n-1) * (n-2) ... * 1. This can be easily calculated using a loop:
my $res = 1; for(my $i = 2; $i <= $_[0]; $i++) { $res *= $i; } return $res;
update: However that is probably not solving your issue with -1.#IND, which indicates that your numbers are getting too big; others propose to add
use bignum;
to the beginning of your script...

Replies are listed 'Best First'.
Re^2: Calculate propabilities without recursion? Coin toss.
by Microcebus (Beadle) on Mar 16, 2011 at 13:11 UTC
    Thanks allot, using bignum works. But makes the whole very very slowly. I want to run this script up to 10000 times with n=up to 5000. This will take weeks... Any suggestions?
      It wouldn't surprise me if 5000! is larger than the number of atoms in the universe. Would you care to reconsider that?

        In fact, a measly 65! = 8x1090, which is significantly bigger than the number of atoms in the visible universe (1078 to 1082).

Re^2: Calculate propabilities without recursion? Coin toss.
by Anonymous Monk on Mar 17, 2011 at 15:01 UTC
    This is the factorial function, which is a special case of the gamma function. If you are going to use this number in ratios, especially in combination with other gamma functions, what you might be better off calculating is the log-gamma function.