up previous next
binomial    --    binomial coefficient


Syntax
binomial(N: INT, K: INT): INT
binomial(N: RINGELEM, K: INT): RINGELEM

Description
This function computes the binomial coefficient, N choose K according to the formula (N)(N-1)(N-2)...(N-K+1) / K! If K < 0 or K > abs(N) the value is 0.

The same formula is used if N is a ring element; in this case it is an error if the integer K is negative. See the example below, to see how to compute binomial(N,K) where N is a rational.

Example
/**/  binomial(4,2);
6

/**/  binomial(-4,3);
-20

/**/  N := 5/3;  // want to compute binomial(N,2)
/**/  AsRAT(binomial(RingElem(QQ,N), 2));  // trick: convert N to elem of QQ
5/9

/**/  use QQ[x,y];
/**/  binomial(x^2+2*y,3);
(1/6)*x^6 +x^4*y +(-1/2)*x^4 +2*x^2*y^2 -2*x^2*y +(4/3)*y^3 +(1/3)*x^2 -2*y^2 +(2/3)*y

/**/  It = (x^2+2*y)*(x^2+2*y-1)*(x^2+2*y-2)/6;
true

See Also