I am trying to do binomial expansions in PHP (example: the chance an event with 30% probability will occur 3 out of 5 times is 13%).

There is a formula (in the PECL stat library) that does binomial expansions. It is:

http://usphp.com/manual/en/function.stats-cdf-binomial.php
It is not documented, and so far I cannot figure out what the variables stand for by plugging in numbers. For example,

echo(stats_cdf_binomial(3,

5,0.3,1) . '<br />');

will return a value but it isn't the right one, and juggling the numbers around so far hasn't worked.

Is there somewhere I can find out how to use this function? There is no documentation file in the library itself that I can find, or anywhere else.

I tried making my own binomial expansion function, which is just formula 1 on this page: http://en.wikipedia.org/wiki/Binomial_expansion

however my problem here is that for large values of n, n! is to large to calculate. (I need to use values of n > 500.) Also, the exponent terms can be too big for certain values of n and k. Presumably there is some way to get around this problem, but I don't know how to do it.

To solve this problem, I either need to know how to use stats-cdf-binomial (assuming it can handle large n and k) or I need another function to calculate binomial expansions. My current function to handle them (works fine for low n) is:

function bin_dist($this_many,$out_of_this_many,$success_probability) { // calculates binomial distribution

$probability = fact($out_of_this_many)*(pow($success_probability,$this_many))*(pow(1-$success_probability,$out_of_this_many-$this_many))/(fact($out_of_this_many - $this_many)*fact($this_many));

return $probability;

}