Key idea of this section
Count functions f : N → K with |N| = n, |K| = k, up to permutations of N and/or K, with f arbitrary, injective, or surjective.
Distributions as functions
A huge class of counting problems has the form "place n balls into k boxes." Formally, a placement is a function f : N → K from a set N of n balls to a set K of k boxes. Two further choices determine the problem. First, we may regard the balls as distinguishable or indistinguishable, and likewise the boxes; indistinguishability means that we count functions only up to the action of the symmetric group on N, on K, or on both. Second, we may impose no condition on f, require f to be injective (at most one ball per box), or require f to be surjective (no empty box). Three restrictions times four symmetry types give twelve problems. Gian-Carlo Rota organized them in this way in lectures in the 1960s; the name "twelvefold way" is due to Joel Spencer, and the table was popularized by Richard Stanley's Enumerative Combinatorics.
Stars and bars
Theorem 1.1. The number of solutions of x₁ + x₂ + ⋯ + xₖ = n in nonnegative integers (weak compositions of n into k parts) is C(n + k − 1, k − 1). The number of solutions in positive integers (compositions of n into k parts) is C(n − 1, k − 1).
Proof. A weak composition corresponds bijectively to a word consisting of n stars and k − 1 bars: x₁ is the number of stars before the first bar, xᵢ the number between bar i − 1 and bar i, and xₖ the number after the last bar. Such a word is determined by the positions of the bars among n + k − 1 slots, giving C(n + k − 1, k − 1). For positive solutions, substitute yᵢ = xᵢ − 1 ≥ 0, which gives a weak composition of n − k into k parts, counted by C(n − 1, k − 1). Alternatively, a composition of n is determined by choosing k − 1 of the n − 1 gaps between n stars in a row. ∎
The same substitution handles arbitrary lower bounds: if xᵢ ≥ bᵢ, put yᵢ = xᵢ − bᵢ and count weak compositions of n − ∑bᵢ. Upper bounds are harder and require inclusion–exclusion (Lesson 3).
The table
Write S(n, k) for the Stirling number of the second kind (the number of partitions of an n-set into k nonempty blocks) and pₖ(n) for the number of partitions of the integer n into exactly k positive parts. Write [P] for 1 if the statement P is true and 0 otherwise.
balls / boxes any f injective f surjective f distinct / distinct kⁿ (k)ₙ k!·S(n, k) identical / distinct C(n + k − 1, n) C(k, n) C(n − 1, k − 1) distinct / identical S(n,1) + ⋯ + S(n,k) [n ≤ k] S(n, k) identical / identical p₁(n) + ⋯ + pₖ(n) [n ≤ k] pₖ(n)
Proofs of the entries
Row one: an arbitrary function assigns each of n balls one of k boxes, giving kⁿ; an injective function is an arrangement of n distinct images, giving (k)ₙ = k!/(k − n)!. A surjection [n] → [k] is the same as an ordered partition of [n] into k nonempty blocks (block i is the preimage of box i); forgetting the order of the blocks loses exactly a factor of k!, so there are k!·S(n, k) surjections.
Row two: a function from indistinguishable balls is determined by the occupancy numbers (x₁, …, xₖ), which form a weak composition of n; injectivity means each xᵢ ∈ {0, 1}, which amounts to choosing n occupied boxes out of k; surjectivity means a composition. Row three: if the boxes are indistinguishable, a function is determined by its set of nonempty preimages, which is a set partition of N into at most k blocks; surjectivity forces exactly k blocks. An injective placement exists if and only if n ≤ k, and then all injective placements are equivalent. Row four: forgetting the labels on both sides leaves only the multiset of occupancy numbers, that is, an integer partition of n into at most k parts.
Worked example 1.2. Ten identical coins are distributed among four people so that each person receives at least one coin. This is a surjection from identical balls to distinct boxes: C(9, 3) = 84. If instead the ten coins are distinct, the count is 4!·S(10, 4) = 24 · 34105 = 818,520.
Remark. The table makes clear why the Stirling numbers and the partition numbers are fundamental: they are the irreducible quantities that remain after symmetry has been divided out. Neither has a closed product formula, and much of this course is devoted to understanding them.
Exercise
- (a)How many weak compositions of 12 into 5 parts are there?
- (b)In how many ways can 6 distinct balls be put into 3 identical boxes if empty boxes are allowed?
- (c)In how many ways can 8 identical balls be put into 3 identical boxes with no box empty?
Show solution
Answers: (a) C(16, 4) = 1820. (b) S(6, 1) + S(6, 2) + S(6, 3) = 1 + 31 + 90 = 122. (c) p₃(8) = 5, namely 6+1+1, 5+2+1, 4+3+1, 4+2+2, 3+3+2.