|
D.2.2.4 binomial
Procedure from library general.lib (see general_lib).
- Usage:
binomial(n,k[,p]); n,k,p integers
- Return:
binomial(n,k); binomial coefficient n choose k
- of type string (computed in characteristic 0)
binomial(n,k,p); n choose k, computed in characteristic 0 or prime(p)
- of type number if a basering, say R, is present and p=0=char(R)
or if prime(p)=char(R)
- of type string else
- Note:
In any characteristic, binomial(n,k) = coefficient of x^k in (1+x)^n
Example:
| LIB "general.lib";
binomial(200,100);""; //type string, computed in char 0
→ 90548514656103281165404177077484163874504589675413336841320
→
binomial(200,100,3);""; //type string, computed in char 3
→ 0
→
int n,k = 200,100;
ring r = 0,x,dp;
number b1 = binomial(n,k,0); //type number, computed in ring r
poly b2 = coeffs((x+1)^n,x)[k+1,1]; //coefficient of x^k in (x+1)^n
b1-b2; //b1 and b2 should coincide
→ 0
|
See also:
prime.
|