Just another Perl shrine PerlMonks

### Re: Fastest way to calculate hypergeometric distribution probabilities (i.e. BIG factorials)?

by BrowserUk (Pope)
 on Jun 14, 2005 at 01:05 UTC ( #466334=note: print w/replies, xml ) Need Help??

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>

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
• Comment on Re: Fastest way to calculate hypergeometric distribution probabilities (i.e. BIG factorials)?

Create A New User
Node Status?
node history
Node Type: note [id://466334]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2021-05-08 08:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Perl 7 will be out ...

Results (96 votes). Check out past polls.

Notices?