Catalan Numbers

lean4-proofcombinatoricsvisualization
Cn=1n+1(2nn)C_n = \frac{1}{n+1}\binom{2n}{n}

Statement

The nn-th Catalan number is:

Cn=1n+1(2nn)=(2nn)(2nn+1)C_n = \frac{1}{n+1}\binom{2n}{n} = \binom{2n}{n} - \binom{2n}{n+1}

They satisfy the recursion:

C0=1,Cn+1=i=0nCiCniC_0 = 1, \qquad C_{n+1} = \sum_{i=0}^{n} C_i \cdot C_{n-i}

Visualization

Values C0C_0 through C8C_8:

nn012345678
CnC_n112514421324291430

Balanced parentheses for n=3n=3 (all C3=5C_3 = 5 arrangements):

((()))    (()())    (())()    ()(())    ()()()

Dyck paths for n=3n=3 — lattice paths from (0,0)(0,0) to (6,0)(6,0) that never go below the xx-axis:

Path 1: ((()))       U U U D D D
         /\
        /  \
       /    \___

Path 2: (()())       U U D U D D
         /\
        /  \/\

Path 3: (())()       U U D D U D
         /\
        /  \   /\

Path 4: ()(())       U D U U D D
        /\  /\
            /  \

Path 5: ()()()       U D U D U D
        /\ /\ /\

Each up-step UU corresponds to ( and each down-step DD to ). The path must stay at or above height 0.

Recursion unrolled for C4=14C_4 = 14:

C4=C0C3+C1C2+C2C1+C3C0=15+12+21+51=14C_4 = C_0 C_3 + C_1 C_2 + C_2 C_1 + C_3 C_0 = 1\cdot5 + 1\cdot2 + 2\cdot1 + 5\cdot1 = 14

Proof Sketch

Ballot problem / reflection argument: Count lattice paths from (0,0)(0,0) to (2n,0)(2n, 0) with +1+1 and 1-1 steps that stay non-negative. Total paths: (2nn)\binom{2n}{n}. Bad paths (those that go negative) biject with unrestricted paths from (2,0)(-2, 0) to (2n,0)(2n, 0) via the reflection principle, numbering (2nn+1)\binom{2n}{n+1}. So:

Cn=(2nn)(2nn+1)=1n+1(2nn)C_n = \binom{2n}{n} - \binom{2n}{n+1} = \frac{1}{n+1}\binom{2n}{n}

Mathlib's Catalan number satisfies catalan_succ: Cn+1=i:Fin(n+1)CiCniC_{n+1} = \sum_{i : \text{Fin}(n+1)} C_i \cdot C_{n-i}.

Connections

  • 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 ballot problem uses a pigeonhole argument to count bad paths
  • 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 → — bad paths counted via complementary counting
  • 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 → — both sequences count partition-like structures; Cn=S(2n,n)/(n+1)!C_n = S(2n, n)/(n+1)! (approximately)
  • Bell NumbersBell NumbersBn=k=0nS(n,k)B_n = \sum_{k=0}^{n} S(n, k)The total number of partitions of a set of n elementsRead more → — Bell numbers grow faster; Bn(n/lnn)nB_n \approx (n/\ln n)^n vs Cn4n/(n3/2π)C_n \approx 4^n / (n^{3/2}\sqrt{\pi})
  • 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 closed form Cn=(2nn)/(n+1)C_n = \binom{2n}{n}/(n+1) directly uses binomial coefficients
  • Lucas's TheoremLucas's Theorem(mn)i(mini)(modp)\binom{m}{n} \equiv \prod_{i} \binom{m_i}{n_i} \pmod{p}Binomial coefficients mod a prime p reduce digit-by-digit in base pRead more → — Lucas's theorem gives Cp2(modp)C_p \equiv 2 \pmod{p} for prime pp

Lean4 Proof

import Mathlib.Combinatorics.Enumerative.Catalan

/-- The Catalan recursion: C(n+1) = ∑ᵢ C(i) * C(n-i).
    This is `catalan_succ` in Mathlib. -/
theorem catalan_recursion (n : ) :
    catalan (n + 1) = ∑ i : Fin n.succ, catalan i * catalan (n - i) :=
  catalan_succ n

/-- Verify small values by computation. -/
theorem catalan_vals :
    catalan 0 = 1  catalan 1 = 1  catalan 2 = 2 
    catalan 3 = 5  catalan 4 = 14 := by decide

/-- The number of Dyck words of semilength n equals C(n).
    This is `DyckWord.card_dyckWord_semilength_eq_catalan` in Mathlib. -/
theorem dyck_count_eq_catalan (n : ) :
    Fintype.card { p : DyckWord // p.semilength = n } = catalan n :=
  DyckWord.card_dyckWord_semilength_eq_catalan n