Bell Numbers

lean4-proofcombinatoricsvisualization
Bn=k=0nS(n,k)B_n = \sum_{k=0}^{n} S(n, k)

Statement

The nn-th Bell number BnB_n counts the total number of partitions of a set of nn elements. It satisfies:

Bn=k=0nS(n,k)B_n = \sum_{k=0}^{n} S(n, k)

where S(n,k)S(n, k) are the Stirling NumbersStirling NumbersS(n,k)=kS(n1,k)+S(n1,k1)S(n,k) = k \cdot S(n-1,k) + S(n-1,k-1)Counting partitions of n elements into k non-empty subsetsRead more → of the second kind. Equivalently, by the Bell triangle recursion:

Bn+1=k=0n(nk)BkB_{n+1} = \sum_{k=0}^{n} \binom{n}{k} B_k

Visualization

Values B0B_0 through B6B_6:

nn0123456
BnB_n11251552203

All partitions of {1,2,3}\{1, 2, 3\} — verifying B3=5B_3 = 5:

1 block (k=1):
  { {1, 2, 3} }

2 blocks (k=2):
  { {1}, {2, 3} }
  { {2}, {1, 3} }
  { {3}, {1, 2} }

3 blocks (k=3):
  { {1}, {2}, {3} }

Five partitions total. B3=S(3,1)+S(3,2)+S(3,3)=1+3+1=5B_3 = S(3,1) + S(3,2) + S(3,3) = 1 + 3 + 1 = 5.

Bell triangle (each row gives the next Bell number and recursion weights):

Row 0:  1
Row 1:  1   2
Row 2:  2   3   5
Row 3:  5   7  10  15
Row 4: 15  20  27  37  52

Each row starts with the last element of the previous row; each subsequent element is the sum of the element to its left and the element directly above it. The first element of each row is BnB_n.

Recursion unrolled for B4=15B_4 = 15:

B4=(30)B0+(31)B1+(32)B2+(33)B3=11+31+32+15=15B_4 = \binom{3}{0}B_0 + \binom{3}{1}B_1 + \binom{3}{2}B_2 + \binom{3}{3}B_3 = 1\cdot1 + 3\cdot1 + 3\cdot2 + 1\cdot5 = 15

Proof Sketch

The recursion Bn+1=k=0n(nk)BkB_{n+1} = \sum_{k=0}^n \binom{n}{k} B_k follows from conditioning on the block containing element n+1n+1: if that block has size j+1j+1, choose the remaining jj members from {1,,n}\{1, \ldots, n\} in (nj)\binom{n}{j} ways, then partition the leftover njn-j elements in BnjB_{n-j} ways. Summing over j=0,,nj = 0, \ldots, n gives the formula (after re-indexing with k=njk = n-j).

Mathlib's Nat.bell uses the Finset-indexed form ∑ i : Fin n.succ, choose n i * Nat.bell (n - i), proved as Nat.bell_succ.

Connections

  • Stirling NumbersStirling NumbersS(n,k)=kS(n1,k)+S(n1,k1)S(n,k) = k \cdot S(n-1,k) + S(n-1,k-1)Counting partitions of n elements into k non-empty subsetsRead more →Bn=kS(n,k)B_n = \sum_k S(n,k); Bell numbers are horizontal sums of the Stirling triangle
  • Inclusion-Exclusion PrincipleInclusion-Exclusion PrincipleAB=A+BAB|A \cup B| = |A| + |B| - |A \cap B|The size of a union is the alternating sum of intersection sizesRead more → — each S(n,k)S(n,k) in the sum is itself an inclusion-exclusion formula
  • Catalan NumbersCatalan NumbersCn=1n+1(2nn)C_n = \frac{1}{n+1}\binom{2n}{n}The ubiquitous sequence counting balanced parentheses, binary trees, and Dyck pathsRead more → — both count partition-like objects; Cn<BnC_n < B_n for n3n \geq 3 since Catalan only counts non-crossing partitions
  • Pigeonhole PrinciplePigeonhole Principlef1({y})2  for some  yB  when  A>B|f^{-1}(\{y\})| \geq 2 \;\text{for some}\; y \in B \;\text{when}\; |A| > |B|If n+1 objects are placed into n boxes, some box contains at least two objectsRead more → — the rapid growth of BnB_n means that any assignment of nn objects to Bn1B_{n-1} partition-types must repeat a type for large nn
  • Binomial TheoremBinomial Theorem(x+y)n=k=0n(nk)xkynk(x+y)^n = \sum_{k=0}^{n} \binom{n}{k} x^k y^{n-k}Expanding powers of a sum via binomial coefficientsRead more → — the binomial coefficients (nk)\binom{n}{k} in the recursion come from choosing block members
  • Möbius InversionMöbius Inversionf(n)=dnμ(d)g ⁣(nd)f(n) = \sum_{d \mid n} \mu(d)\, g\!\left(\frac{n}{d}\right)If g equals the Dirichlet convolution of f with the constant 1, then f recovers via the Möbius functionRead more → — the exponential generating function nBnxn/n!=eex1\sum_n B_n x^n/n! = e^{e^x - 1} is proved via Möbius inversion on the partition lattice

Lean4 Proof

import Mathlib.Combinatorics.Enumerative.Bell

open Nat

/-- The Bell number recursion: B(n+1) = ∑ᵢ C(n,i) * B(n-i).
    This is `Nat.bell_succ` in Mathlib. -/
theorem bell_recursion (n : ) :
    Nat.bell (n + 1) = ∑ i : Fin n.succ, Nat.choose n i * Nat.bell (n - i) :=
  Nat.bell_succ n

/-- Verify small Bell numbers by computation.
    Uses `native_decide` since `Nat.bell` does not reduce under `decide`. -/
theorem bell_vals :
    Nat.bell 0 = 1  Nat.bell 1 = 1  Nat.bell 2 = 2 
    Nat.bell 3 = 5  Nat.bell 4 = 15  Nat.bell 5 = 52 := by native_decide

/-- B(0) = 1: the empty set has exactly one partition (the empty partition). -/
theorem bell_zero : Nat.bell 0 = 1 :=
  Nat.bell_zero

/-- B(5) = 52, verifying the sixth Bell number. -/
theorem bell_five : Nat.bell 5 = 52 := by native_decide