Stirling Numbers
Statement
The Stirling number of the second kind counts the number of ways to partition a set of distinct elements into exactly non-empty subsets.
They satisfy:
with boundary conditions , for , and for .
The explicit formula is:
Visualization
Triangle for :
n\k | 0 1 2 3 4 5
----+------------------------------
0 | 1 0 0 0 0 0
1 | 0 1 0 0 0 0
2 | 0 1 1 0 0 0
3 | 0 1 3 1 0 0
4 | 0 1 7 6 1 0
5 | 0 1 15 25 10 1
Reading the recursion — :
Partitions of into 2 non-empty subsets:
{ {1}, {2,3} } { {2}, {1,3} } { {3}, {1,2} }
Three ways. The recursion confirms this.
Why the factor ? To build a partition of into blocks, either:
- Element forms a singleton block: arrange the rest into blocks — ways.
- Element joins one of the existing blocks: choose which block — ways.
: Partitions of into 2 non-empty subsets:
{1}, {2,3,4} {2}, {1,3,4} {3}, {1,2,4} {4}, {1,2,3}
{1,2}, {3,4} {1,3}, {2,4} {1,4}, {2,3}
Seven. Verified.
Proof Sketch
The recursion follows directly from the case analysis on whether element is alone in its block or joined to one of existing blocks. The boundary cases and for encode the empty-partition convention.
Mathlib's Nat.stirlingSecond is defined by this exact recursion, making stirlingSecond_succ_succ hold by rfl.
Connections
- Inclusion-Exclusion PrincipleInclusion-Exclusion PrincipleThe size of a union is the alternating sum of intersection sizesRead more → — the explicit formula is an inclusion-exclusion sum
- Bell NumbersBell NumbersThe total number of partitions of a set of n elementsRead more → — ; Bell numbers are row sums of the Stirling triangle
- Catalan NumbersCatalan NumbersThe ubiquitous sequence counting balanced parentheses, binary trees, and Dyck pathsRead more → — both count tree-like structures; counts binary trees, counts set-forests
- Pigeonhole PrinciplePigeonhole PrincipleIf n+1 objects are placed into n boxes, some box contains at least two objectsRead more → — when , reflecting that you cannot form more blocks than elements
- Binomial TheoremBinomial TheoremExpanding powers of a sum via binomial coefficientsRead more → — the explicit formula uses binomial coefficients; the falling factorial
- Möbius InversionMöbius InversionIf g equals the Dirichlet convolution of f with the constant 1, then f recovers via the Möbius functionRead more → — Stirling numbers of both kinds are related by Möbius inversion on the partition lattice
Lean4 Proof
import Mathlib.Combinatorics.Enumerative.Stirling
open Nat
/-- The Stirling recursion S(n+1, k+1) = (k+1)·S(n,k+1) + S(n,k).
Mathlib's definition makes this hold by `rfl`. -/
theorem stirling_recursion (n k : ℕ) :
stirlingSecond (n + 1) (k + 1) =
(k + 1) * stirlingSecond n (k + 1) + stirlingSecond n k :=
rfl
/-- Verify the triangle entries by computation. -/
theorem stirling_vals :
stirlingSecond 3 2 = 3 ∧
stirlingSecond 4 2 = 7 ∧
stirlingSecond 5 3 = 25 := by decide
/-- S(n, n) = 1 for all n: only one way to partition n elements into n singletons.
This is `stirlingSecond_self` in Mathlib. -/
theorem stirling_diagonal (n : ℕ) : stirlingSecond n n = 1 :=
stirlingSecond_self n
/-- S(n, k) = 0 when k > n: cannot have more blocks than elements.
This is `stirlingSecond_eq_zero_of_lt` in Mathlib. -/
theorem stirling_zero_of_lt {n k : ℕ} (h : n < k) : stirlingSecond n k = 0 :=
stirlingSecond_eq_zero_of_lt hReferenced by
- Inclusion-Exclusion PrincipleCombinatorics
- Catalan NumbersCombinatorics
- Pascal's IdentityCombinatorics
- Pigeonhole PrincipleCombinatorics
- Bell NumbersCombinatorics
- Bell NumbersCombinatorics