in reply to Fastest way to calculate hypergeometric distribution probabilities (i.e. BIG factorials)?
Do you need total precision? Using one of the 'BigMath' modules would allow you to get complete accuracy, but calculating large factorials will consume large amounts of memory and take a long time. Using one of the C-based math packages will calculate a lot faster but will discard some accuracy. By way of example, the following both produce the same results to 30+ significant digits, which as your probabilities will be in the range 0->1 or percentanges, you're probably only interested in 2 or 3 digits of accuracy in the final result.
Using Math::Pari, factorial( 19937 ) takes a second or so:
[ 1:32:28.64] P:\test>perl -MMath::Pari=factorial -wle"print factorial +( 19937 )" 2.174930234150431374566653166E77066 [ 1:32:30.58] P:\test>
Using Math::BigInt takes over 100 seconds to do the same thing:
[ 1:35:13.75] P:\test>perl -MMath::BigInt -wle"$n=Math::BigInt->new( 1 +9937 ); print $n->bfac;" 2174930234150431374566653562545349453159548764005915598228287343243610 0399250094165681781366521424136575314821986705545783026313111819773987 2047105789330953704693263375025834056482446086707947547228857444817043 ... << 1000 similar lines snipped.>> ... 0000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000 [ 1:37:02.13] P:\test>
|
---|