This is documentation for Mathematica 6, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

Combinatorial Functions

n!factorial n (n-1) (n-2)×...×1
n!!double factorial n (n-2) (n-4)×...
Binomial[n,m]binomial coefficient
Multinomial[n1,n2,...]multinomial coefficient (n1+n2+...)!/ (n1!n2!...)
CatalanNumber[n]Catalan number cn
Subfactorial[n]number of derangements of n objects
Fibonacci[n]Fibonacci number Fn
Fibonacci[n,x]Fibonacci polynomial Fn (x)
LucasL[n]Lucas number Ln
HarmonicNumber[n]harmonic number Hn
HarmonicNumber[n,r]harmonic number of order r
BernoulliB[n]Bernoulli number Bn
BernoulliB[n,x]Bernoulli polynomial Bn (x)
NorlundB[n,a]Nörlund polynomial
NorlundB[n,a,x]generalized Bernoulli polynomial
EulerE[n]Euler number En
EulerE[n,x]Euler polynomial En (x)
StirlingS1[n,m]Stirling number of the first kind
StirlingS2[n,m]Stirling number of the second kind
BellB[n]Bell number Bn
BellB[n,x]Bell polynomial Bn (x)
PartitionsP[n]the number p (n) of unrestricted partitions of the integer n
IntegerPartitions[n]partitions of an integer
PartitionsQ[n]the number q (n) of partitions of n into distinct parts
Signature[{i1,i2,...}]the signature of a permutation

Combinatorial functions.

The factorial function n! gives the number of ways of ordering n objects. For non-integer n, the numerical value of n! is obtained from the gamma function, discussed in "Special Functions".
The binomial coefficient Binomial[n, m] can be written as . It gives the number of ways of choosing m objects from a collection of n objects, without regard to order. The Catalan numbers, which appear in various tree enumeration problems, are given in terms of binomial coefficients as .
The subfactorial Subfactorial[n] gives the number of permutations of n objects that leave no object fixed. Such a permutation is called a derangement. The subfactorial is given by n! (-1)k/k!.
The multinomial coefficient Multinomial[n1, n2, ...], denoted (N;n1, n2, ..., nm)=N!/ (n1!n2!... nm!), gives the number of ways of partitioning N distinct objects into m sets of sizes ni (with N=ni).
Mathematica gives the exact integer result for the factorial of an integer.
Click for copyable input
For non-integers, Mathematica evaluates factorials using the gamma function.
Click for copyable input
Mathematica can give symbolic results for some binomial coefficients.
Click for copyable input
This gives the number of ways of partitioning 6+5=11 objects into sets containing 6 and 5 objects.
Click for copyable input
The result is the same as .
Click for copyable input
The Fibonacci numbers Fibonacci[n] satisfy the recurrence relation Fn=Fn-1+Fn-2 with F1=F2=1. They appear in a wide range of discrete mathematical problems. For large n, Fn/Fn-1 approaches the golden ratio. The Lucas numbers LucasL[n] satisfy the same recurrence relation as the Fibonacci numbers do, but with initial conditions L1=1 and L2=3.
The Fibonacci polynomials Fibonacci[n, x] appear as the coefficients of tn in the expansion of t/ (1-xt-t2)=Fn (x)tn .
The harmonic numbers HarmonicNumber[n] are given by Hn=1/i; the harmonic numbers of order r HarmonicNumber[n, r] are given by . Harmonic numbers appear in many combinatorial estimation problems, often playing the role of discrete analogs of logarithms.
The Bernoulli polynomials BernoulliB[n, x] satisfy the generating function relation tex t/ (et-1)=Bn (x)tn/n! . The Bernoulli numbers BernoulliB[n] are given by Bn=Bn (0). The Bn appear as the coefficients of the terms in the Euler-Maclaurin summation formula for approximating integrals. The Bernoulli numbers are related to the Genocchi numbers by Gn=2 (1-2n)Bn.
Numerical values for Bernoulli numbers are needed in many numerical algorithms. You can always get these numerical values by first finding exact rational results using BernoulliB[n], and then applying N.
The Euler polynomials EulerE[n, x] have generating function 2ex t/ (et+1)=En (x)tn/n! , and the Euler numbers EulerE[n] are given by .
The Nörlund polynomials NorlundB[n, a] satisfy the generating function relation . The Nörlund polynomials give the Bernoulli numbers when a=1. For other positive integer values of a, the Nörlund polynomials give higher-order Bernoulli numbers. The generalized Bernoulli polynomials NorlundB[n, a, x] satisfy the generating function relation .
This gives the second Bernoulli polynomial B2 (x).
Click for copyable input
You can also get Bernoulli polynomials by explicitly computing the power series for the generating function.
Click for copyable input
BernoulliB[n] gives exact rational-number results for Bernoulli numbers.
Click for copyable input
Stirling numbers show up in many combinatorial enumeration problems. For Stirling numbers of the first kind StirlingS1[n, m], gives the number of permutations of n elements which contain exactly m cycles. These Stirling numbers satisfy the generating function relation . Note that some definitions of the differ by a factor (-1)n-m from what is used in Mathematica.
Stirling numbers of the second kind StirlingS2[n, m], sometimes denoted , give the number of ways of partitioning a set of n elements into m non-empty subsets. They satisfy the relation .
The Bell numbers BellB[n] give the total number of ways that a set of n elements can be partitioned into non-empty subsets. The Bell polynomials BellB[n, x] satisfy the generating function relation .
The partition function PartitionsP[n] gives the number of ways of writing the integer n as a sum of positive integers, without regard to order. PartitionsQ[n] gives the number of ways of writing n as a sum of positive integers, with the constraint that all the integers in each sum are distinct.
IntegerPartitions[n] gives a list of the partitions of n, with length PartitionsP[n].
This gives a table of Stirling numbers of the first kind.
Click for copyable input
The Stirling numbers appear as coefficients in this product.
Click for copyable input
Here are the partitions of 4.
Click for copyable input
The number of partitions is given by PartitionsP[4].
Click for copyable input
This gives the number of partitions of 100, with and without the constraint that the terms should be distinct.
Click for copyable input
The partition function p (n) increases asymptotically like . Note that you cannot simply use Plot to generate a plot of a function like PartitionsP because the function can only be evaluated with integer arguments.
Click for copyable input
Most of the functions here allow you to count various kinds of combinatorial objects. Functions like IntegerPartitions and Permutations allow you instead to generate lists of various combinations of elements.
The signature function Signature[{i1, i2, ...}] gives the signature of a permutation. It is equal to +1 for even permutations (composed of an even number of transpositions), and to -1 for odd permutations. The signature function can be thought of as a totally antisymmetric tensor, Levi-Civita symbol or epsilon symbol.
ClebschGordan[{j1,m1},{j2,m2},{j,m}]Clebsch-Gordan coefficient
ThreeJSymbol[{j1,m1},{j2,m2},{j3,m3}]Wigner 3-j symbol
SixJSymbol[{j1,j2,j3},{j4,j5,j6}]Racah 6-j symbol

Rotational coupling coefficients.

Clebsch-Gordan coefficients and n-j symbols arise in the study of angular momenta in quantum mechanics, and in other applications of the rotation group. The Clebsch-Gordan coefficients ClebschGordan[{j1, m1}, {j2, m2}, {j, m}] give the coefficients in the expansion of the quantum mechanical angular momentum state j, m in terms of products of states j1, m1 j2, m2.
The 3-j symbols or Wigner coefficients ThreeJSymbol[{j1, m1}, {j2, m2}, {j3, m3}] are a more symmetrical form of Clebsch-Gordan coefficients. In Mathematica, the Clebsch-Gordan coefficients are given in terms of 3-j symbols by .
The 6-j symbols SixJSymbol[{j1, j2, j3}, {j4, j5, j6}] give the couplings of three quantum mechanical angular momentum states. The Racah coefficients are related by a phase to the 6-j symbols.
You can give symbolic parameters in 3-j symbols.
Click for copyable input