%mathpiper,def="Combinations;BinomialCoefficient"

/* Binomials -- now using partial factorial for speed */
// BinomialCoefficient(n,m) = BinomialCoefficient(n, n-m)
10 # BinomialCoefficient(0,0) 		<-- 1;
10 # BinomialCoefficient(n_IsPositiveInteger,m_IsNonNegativeInteger)_(2*m <= n) <-- ((n-m+1) *** n) / m!;
15 # BinomialCoefficient(n_IsPositiveInteger,m_IsNonNegativeInteger)_(2*m > n And m <= n) <-- BinomialCoefficient(n, n-m);
20 # BinomialCoefficient(n_IsInteger,m_IsInteger) <-- 0;

Combinations(n,m) := BinomialCoefficient(n,m);

%/mathpiper



%mathpiper_docs,name="Combinations;BinomialCoefficient",categories="User Functions;Combinatorics"
*CMD Combinations/BinomialCoefficient --- combinations/ binomial coefficient
*STD
*CALL
        Combinations(n, r)
	BinomialCoefficient(n, r)

*PARMS

{n} -- integer - total number of objects
{r} -- integer - number of objects chosen

*DESC

These functions are actually two names for a single function.

In combinatorics, the function is thought of as being the number of ways
to choose "r" objects out of a total of "n" objects if order is
not taken into account.

In mathematics the function is called the binomial coefficient function
and it is thought of as the coefficient of the x^r term in the polynomial expansion
of the binomial power (1 + x)^n.

The binomial coefficient is defined to be zero
if "r" is negative or greater than "n"; {BinomialCoefficient(0,0)}=1.


*E.G.

In> Combinations(10, 4)
Result: 210;

In> BinomialCoefficient(10, 4)
Result: 210;


*SEE CombinationsList, Permutations, PermutationsList, !, Eulerian
%/mathpiper_docs