in reply to Re^2: Getting Binomial Distribution under Math::Pari (log) and Combinatorial Method
in thread Getting Binomial Distribution under Math::Pari (log) and Combinatorial Method
Plug that into the fact that n choose m is n!/(m!*(n-m)!) and you can come up with a good approximation that uses Perl's native arithmetic.log(n**n * exp(-n) * sqrt(2*PI*n)) = n*log(n) - n + (log(2 + log(PI) + log(n))/2
This approximation may well turn out to be the fastest approach for large numbers.
Update: From Mathworld I just found out that a significantly better approximation of n! is sqrt(2*n*PI + 1/3)*n**n/exp(n). Algebraically this is less convenient, but the improved accuracy may matter for whatever you're trying to do.
|
---|