Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Computation of binomial #172

Open
soegaard opened this issue Jul 1, 2023 · 0 comments
Open

Computation of binomial #172

soegaard opened this issue Jul 1, 2023 · 0 comments

Comments

@soegaard
Copy link

soegaard commented Jul 1, 2023

Currently the text book formula

binomial(n, k) = n! / k! / (n - k)!

is used to compute binomial coefficients.

I suggest using the algorithm below.
The text is from [1].

Binomial Coefficients

Binomial coefficients C(n,k) are calculated by first arranging k <= n/2 using C(n,k) = C(n,n-k) if necessary, and then evaluating the following product simply from i=2 to i=k.

                     k       (n-k+i)
C(n,k) =  (n-k+1) * prod  -----------
                    i=2        i

It's easy to show that each denominator i will divide the product so far, so the exact division algorithm is used (see Exact Division).

[1] https://web.archive.org/web/20111229055708/https://www.gnu.org/software/gmp/manual/html_node/Binomial-Coefficients-Algorithm.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant