# Combinatorial Functions

 n! factorial n!! double factorial Binomial[n,m] binomial coefficient Multinomial[n1,n2,…] multinomial coefficient CatalanNumber[n] Catalan number Hyperfactorial[n] hyperfactorial BarnesG[n] Barnes G-function Subfactorial[n] number of derangements of objects Fibonacci[n] Fibonacci number Fibonacci[n,x] Fibonacci polynomial LucasL[n] Lucas number LucasL[n,x] Lucas polynomial HarmonicNumber[n] harmonic number HarmonicNumber[n,r] harmonic number of order BernoulliB[n] Bernoulli number BernoulliB[n,x] Bernoulli polynomial NorlundB[n,a] Nörlund polynomial NorlundB[n,a,x] generalized Bernoulli polynomial EulerE[n] Euler number EulerE[n,x] Euler polynomial StirlingS1[n,m] Stirling number of the first kind StirlingS2[n,m] Stirling number of the second kind BellB[n] Bell number BellB[n,x] Bell polynomial PartitionsP[n] the number of unrestricted partitions of the integer IntegerPartitions[n] partitions of an integer PartitionsQ[n] the number of partitions of into distinct parts Signature[{i1,i2,…}] the signature of a permutation

Combinatorial functions.

The factorial function gives the number of ways of ordering objects. For noninteger , the numerical value of 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 objects from a collection of 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 objects that leave no object fixed. Such a permutation is called a derangement. The subfactorial is given by .

The multinomial coefficient Multinomial[n1,n2,], denoted , gives the number of ways of partitioning distinct objects into sets of sizes (with ).

The Wolfram Language gives the exact integer result for the factorial of an integer.
 In[1]:=
 Out[1]=
For nonintegers, the Wolfram Language evaluates factorials using the gamma function.
 In[2]:=
 Out[2]=
The Wolfram Language can give symbolic results for some binomial coefficients.
 In[3]:=
 Out[3]=
This gives the number of ways of partitioning objects into sets containing 6 and 5 objects.
 In[4]:=
 Out[4]=
The result is the same as .
 In[5]:=
 Out[5]=

The Fibonacci numbers Fibonacci[n] satisfy the recurrence relation with . They appear in a wide range of discrete mathematical problems. For large , approaches the golden ratio. The Lucas numbers LucasL[n] satisfy the same recurrence relation as the Fibonacci numbers do, but with initial conditions and .

The Fibonacci polynomials Fibonacci[n,x] appear as the coefficients of in the expansion of .

The harmonic numbers are given by ; the harmonic numbers of order 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 . The Bernoulli numbers BernoulliB[n] are given by . The appear as the coefficients of the terms in the EulerMaclaurin summation formula for approximating integrals. The Bernoulli numbers are related to the Genocchi numbers by .

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 , 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 . For other positive integer values of , 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 .
 In[6]:=
 Out[6]=
You can also get Bernoulli polynomials by explicitly computing the power series for the generating function.
 In[7]:=
 Out[7]=
BernoulliB[n] gives exact rationalnumber results for Bernoulli numbers.
 In[8]:=
 Out[8]=

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 elements which contain exactly cycles. These Stirling numbers satisfy the generating function relation . Note that some definitions of the differ by a factor from what is used in the Wolfram Language.

Stirling numbers of the second kind StirlingS2[n,m], sometimes denoted , give the number of ways of partitioning a set of elements into nonempty subsets. They satisfy the relation .

The Bell numbers BellB[n] give the total number of ways that a set of elements can be partitioned into nonempty 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 as a sum of positive integers, without regard to order. PartitionsQ[n] gives the number of ways of writing as a sum of positive integers, with the constraint that all the integers in each sum are distinct.

gives a list of the partitions of , with length Null.

This gives a table of Stirling numbers of the first kind.
 In[9]:=
 Out[9]=
The Stirling numbers appear as coefficients in this product.
 In[10]:=
 Out[10]=
Here are the partitions of 4.
 In[11]:=
 Out[11]=
The number of partitions is given by PartitionsP[4].
 In[12]:=
 Out[12]=
This gives the number of partitions of 100, with and without the constraint that the terms should be distinct.
 In[13]:=
 Out[13]=
The partition function 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.
 In[14]:=
 Out[14]=

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 for even permutations (composed of an even number of transpositions), and to for odd permutations. The signature function can be thought of as a totally antisymmetric tensor, LeviCivita 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.

ClebschGordan coefficients and j symbols arise in the study of angular momenta in quantum mechanics, and in other applications of the rotation group. The ClebschGordan coefficients ClebschGordan[{j1,m1},{j2,m2},{j,m}] give the coefficients in the expansion of the quantum mechanical angular momentum state in terms of products of states .

The 3j symbols or Wigner coefficients ThreeJSymbol[{j1,m1},{j2,m2},{j3,m3}] are a more symmetrical form of ClebschGordan coefficients. In the Wolfram Language, the ClebschGordan coefficients are given in terms of 3j symbols by .

The 6j 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 6j symbols.

You can give symbolic parameters in 3j symbols.
 In[15]:=
 Out[15]=