http://www.perlmonks.org?node_id=466422


in reply to Re^3: Fastest way to calculate hypergeometric distribution probabilities (i.e. BIG factorials)?
in thread Fastest way to calculate hypergeometric distribution probabilities (i.e. BIG factorials)?

if your calculations over the factorial numbers are only multiplications and divisions (as I think they are), you can operate over their log values instead, transforming multiplications and divisions to additions and substractions respectively. i.e.:
log ($n! / ($r! * ($n-$r)!) = Sum(log(1)..log($n)) - Sum(log(1)..log($r)) - Sum(log(1)..log($n-$r))
and as your operations will only involve a small number of integers, you can cache log($n) and log($n!) to speed up the calculations.
  • Comment on Re^4: Fastest way to calculate hypergeometric distribution probabilities (i.e. BIG factorials)?
  • Download Code