The sixteen compositions of 5 are:
Compare this with the seven partitions of 5:
It is possible to put constraints on the parts of the compositions. For example the five compositions of 5 into distinct terms are:
Compare this with the three partitions of 5 into distinct terms:
Note that the ancient Sanskrit sages discovered many years before Fibonacci that the number of compositions of any natural number n as the sum of 1's and 2's is the nth Fibonacci number! Note that these are not general compositions as defined above because the numbers are restricted to 1's and 2's only.
Conventionally the empty composition is counted as the sole composition of 0, and there are no compositions of negative integers. There are 2n−1 compositions of n ≥ 1; here is a proof:
Placing either a plus sign or a comma in each of the n − 1 boxes of the array
produces a unique composition of n. Conversely, every composition of n determines an assignment of pluses and commas. Since there are n − 1 binary choices, the result follows. The same argument shows that the number of compositions of n into exactly k parts (a k-composition) is given by the binomial coefficient ( n − 1 k − 1 ) {\displaystyle {n-1 \choose k-1}} . Note that by summing over all possible numbers of parts we recover 2n−1 as the total number of compositions of n:
For weak compositions, the number is ( n + k − 1 k − 1 ) = ( n + k − 1 n ) {\displaystyle {n+k-1 \choose k-1}={n+k-1 \choose n}} , since each k-composition of n + k corresponds to a weak one of n by the rule
It follows from this formula that the number of weak compositions of n into exactly k parts equals the number of weak compositions of k − 1 into exactly n + 1 parts.
For A-restricted compositions, the number of compositions of n into exactly k parts is given by the extended binomial (or polynomial) coefficient ( k n ) ( 1 ) a ∈ A = [ x n ] ( ∑ a ∈ A x a ) k {\displaystyle {\binom {k}{n}}_{(1)_{a\in A}}=[x^{n}]\left(\sum _{a\in A}x^{a}\right)^{k}} , where the square brackets indicate the extraction of the coefficient of x n {\displaystyle x^{n}} in the polynomial that follows it.2
The dimension of the vector space K [ x 1 , … , x n ] d {\displaystyle K[x_{1},\ldots ,x_{n}]_{d}} of homogeneous polynomial of degree d in n variables over the field K is the number of weak compositions of d into n parts. In fact, a basis for the space is given by the set of monomials x 1 d 1 ⋯ x n d n {\displaystyle x_{1}^{d_{1}}\cdots x_{n}^{d_{n}}} such that d 1 + … + d n = d {\displaystyle d_{1}+\ldots +d_{n}=d} . Since the exponents d i {\displaystyle d_{i}} are allowed to be zero, then the number of such monomials is exactly the number of weak compositions of d.
Heubach, Silvia; Mansour, Toufik (2004). "Compositions of n with parts in a set". Congressus Numerantium. 168: 33–51. CiteSeerX 10.1.1.484.5148. /wiki/Silvia_Heubach ↩
Eger, Steffen (2013). "Restricted weighted integer compositions and extended binomial coefficients" (PDF). Journal of Integer Sequences. 16. https://cs.uwaterloo.ca/journals/JIS/VOL16/Eger/eger6.pdf ↩