Advanced Counting
Why Advanced Counting?
In Chapters 2 and 3 we developed the basic counting toolkit β permutations, combinations, and multinomial coefficients. These suffice when the objects we count are drawn from a single set and placed into a single structure. But many problems in probability and combinatorics require us to count partitions of a set into an unspecified number of blocks, or to enumerate permutations by their cycle structure. Stirling numbers and Bell numbers are the tools for these richer counting problems. They also preview the generating function technique that we will use systematically when we study probability generating functions in Chapter 9.
Definition: Stirling Number of the Second Kind
Stirling Number of the Second Kind
For non-negative integers and , the Stirling number of the second kind, denoted or , is the number of ways to partition a set of elements into exactly non-empty, unordered subsets (called blocks).
By convention, (the empty set has exactly one partition β the empty partition) and for .
The notation is due to Knuth. The alternative is more common in probability texts.
Theorem: Recurrence for Stirling Numbers of the Second Kind
For and : with boundary conditions and for all .
Consider element . Either it forms a singleton block (contributing partitions of the remaining elements into blocks), or it is inserted into one of the existing blocks of a partition of into blocks (contributing partitions).
Case 1: element $n$ is a singleton
If is one of the blocks, then the remaining elements must be partitioned into non-empty blocks. The number of such partitions is .
Case 2: element $n$ joins an existing block
If is not a singleton, remove from its block. The remaining elements form a partition into non-empty blocks (the block from which we removed is still non-empty since was not alone). There are such partitions, and element can be placed into any of the blocks. This gives .
Combine
Since the two cases are mutually exclusive and exhaustive:
Example: Computing Small Stirling Numbers
Compute β the number of ways to partition into exactly 2 non-empty blocks.
List all partitions
The partitions of into 2 blocks are: , , , , , , .
Count and verify
There are partitions. We can verify with the recurrence: .
Theorem: Explicit Formula for Stirling Numbers of the Second Kind
For :
The factor accounts for the fact that blocks are unordered. The alternating sum is an inclusion-exclusion over surjections from onto : we count all functions, subtract those missing at least one value in , add back those missing at least two, and so on.
Count surjections via inclusion-exclusion
Let be the set of functions that do not map any element to . The number of surjections from onto is:
Relate surjections to partitions
Each surjection defines an ordered partition into non-empty blocks. Since blocks are unordered in , each unordered partition corresponds to surjections. Therefore:
Definition: Unsigned Stirling Number of the First Kind
Unsigned Stirling Number of the First Kind
The unsigned Stirling number of the first kind, denoted or , is the number of permutations of that have exactly disjoint cycles.
The signed Stirling number of the first kind is .
Theorem: Recurrence for Unsigned Stirling Numbers of the First Kind
For and : with and for .
Consider element in a permutation of . Either forms a fixed point (a cycle of length 1), contributing from the remaining elements, or is inserted into an existing cycle of a permutation of with cycles. There are positions where can be inserted (after any of the elements in that permutation), giving .
Case 1: $n$ is a fixed point
If is a cycle of length 1, the remaining elements form a permutation with cycles. There are such permutations.
Case 2: $n$ is inserted into an existing cycle
Remove from its cycle by connecting its predecessor directly to its successor. This yields a permutation of with cycles. There are such permutations, and can be inserted after any of the elements, giving choices.
Combine
$
Example: Permutations of by Cycle Structure
List all permutations of and classify them by number of cycles. Verify the values , , .
Enumerate
The 6 permutations in cycle notation:
- 3 cycles: β the identity. Count: 1.
- 2 cycles: , , . Count: 3.
- 1 cycle: , . Count: 2.
Verify
, , . Check: .
Recurrence check: .
Duality Between Stirling Numbers
The two kinds of Stirling numbers satisfy an orthogonality relation. If we define , then: In matrix form, the matrices of signed Stirling numbers of the first and second kind are inverses of each other.
Definition: Bell Number
Bell Number
The Bell number is the total number of partitions of a set of elements into non-empty, unordered subsets: By convention, .
The first few Bell numbers are: , , , , , .
Theorem: Bell Number Recurrence
For :
Consider element . It belongs to some block of size where . Choose the other elements of that block from the remaining in ways, then partition the other elements in ways. Summing over and substituting gives the formula.
Condition on the block containing element $n$
Let the block containing have size , where . We must choose companions for from in ways, then partition the remaining elements arbitrarily in ways.
Sum over block sizes
k = n - j\qquad \square$
Theorem: Exponential Generating Function of Bell Numbers
The exponential generating function (EGF) of the Bell numbers is:
The EGF for set partitions factors as the exponential of the EGF for non-empty subsets. Since the EGF for a single non-empty subset is , the composition gives . This is a fundamental instance of the exponential formula in enumerative combinatorics.
EGF for $S(n,k)$
The EGF for the number of partitions into exactly blocks is , because each block is a non-empty subset (EGF: ) and blocks are unordered (divide by ).
Sum over $k$
$
Definition: Integer Partition
Integer Partition
An integer partition of a positive integer is a way of writing as a sum of positive integers, where the order of summands does not matter. Each summand is called a part. The number of integer partitions of is denoted .
For example, the partitions of 5 are: , , , , , , , so .
Integer partitions are distinct from set partitions. The set has set partitions, but the integer 5 has only integer partitions. Integer partitions count how many objects go in each block; set partitions also track which objects go where.
Historical Note: Euler and the Theory of Partitions
18thβ20th centuryLeonhard Euler initiated the systematic study of integer partitions in the 1740s. His key insight was to encode partitions via generating functions: the number of partitions of is the coefficient of in the product . This observation opened the door to an entire branch of combinatorics and number theory. A century and a half later, Hardy and Ramanujan (1918) established the celebrated asymptotic formula using the circle method β one of the landmarks of analytic number theory.
Theorem: Generating Function for Integer Partitions
The ordinary generating function for the partition function is:
Each factor corresponds to choosing how many parts of size appear in the partition: 0, 1, 2, and so on. The product over all generates all possible combinations of part sizes.
Expand each factor
Write , where counts the number of parts equal to .
Take the product
x^n(m_1, m_2, \ldots)\sum_{k=1}^{\infty} k \cdot m_k = nn\qquad \square$
Generating Functions: A Preview
The generating functions we encountered for Bell numbers and integer partitions are instances of a powerful general technique: encode a counting sequence as the coefficients of a formal power series (ordinary GF) or (exponential GF). Algebraic operations on power series β multiplication, composition, differentiation β then correspond to combinatorial operations on the underlying structures.
In Chapter 9 we will formalize this idea in the probabilistic setting: the probability generating function and the moment generating function will let us derive distributions of sums of independent random variables, prove the central limit theorem, and establish large deviation bounds.
Stirling number of the second kind
: the number of partitions of an -element set into exactly non-empty, unordered subsets.
Related: Bell number, set partition
Stirling number of the first kind
(unsigned): the number of permutations of with exactly cycles.
Related: Stirling number of the second kind
Bell number
: the total number of partitions of an -element set.
set partition
A collection of non-empty, pairwise disjoint subsets (blocks) of a set whose union is .
Related: Bell number
integer partition
A representation of a positive integer as an unordered sum of positive integers. The number of such representations is .
Related: set partition
Quick Check
What is ?
3
6
7
4
Correct. . Equivalently, choose which 2 of the 4 elements share a block: .
Quick Check
What is ?
14
15
16
52
Correct. .
Common Mistake: Set Partitions vs. Integer Partitions
Mistake:
Confusing the number of set partitions of (counted by ) with the number of integer partitions of (counted by ).
Correction:
Set partitions care about which elements go into each block; integer partitions care only about the sizes of the blocks. For : set partitions but only integer partitions.
Key Takeaway
Stirling numbers of the second kind count set partitions into blocks; Stirling numbers of the first kind count permutations with cycles. Both satisfy simple recurrences that parallel Pascal's identity. Bell numbers sum over all and admit the elegant EGF . Integer partitions have the Euler product generating function .