The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V30. Combinatorics

Mathlib.Combinatorics.Enumerative.Catalan.Tree

10 declarations and 1 deprecated aliases. Mathlib docs · Source

Main results

  • treesOfNumNodesEq_card_eq_catalan: The number of binary trees with n internal nodes is catalan n

theorem BinaryTree.treesOfNumNodesEq.match_1.congr_eq_1 E1 #

∀ (motive : ℕ → Sort u_1) (x : ℕ) (h_1 : Unit → motive 0) (h_2 : (n : ℕ) → motive n.succ),
  x = 0 →
    (match x with
      | 0 => h_1 ()
      | n.succ => h_2 n) ≍
      h_1 ()

theorem BinaryTree.treesOfNumNodesEq.match_1.congr_eq_2 E1 #

∀ (motive : ℕ → Sort u_1) (x : ℕ) (h_1 : Unit → motive 0) (h_2 : (n : ℕ) → motive n.succ) (n : ℕ),
  x = n.succ →
    (match x with
      | 0 => h_1 ()
      | n.succ => h_2 n) ≍
      h_2 n

abbrev BinaryTree.pairwiseNode E1 #

Finset (BinaryTree Unit) → Finset (BinaryTree Unit) → Finset (BinaryTree Unit)

Given two finsets, find all trees that can be formed with left child in a and right child in b

def BinaryTree.treesOfNumNodesEq E1 #

ℕ → Finset (BinaryTree Unit)

A Finset of all trees with n nodes. See mem_treesOfNodesEq

theorem BinaryTree.treesOfNumNodesEq_zero E0 #

BinaryTree.treesOfNumNodesEq 0 = {BinaryTree.nil}

theorem BinaryTree.treesOfNumNodesEq_succ E1 #

∀ (n : ℕ),
  BinaryTree.treesOfNumNodesEq (n + 1) =
    (Finset.HasAntidiagonal.antidiagonal n).biUnion fun ij ↦
      BinaryTree.pairwiseNode (BinaryTree.treesOfNumNodesEq ij.1) (BinaryTree.treesOfNumNodesEq ij.2)

theorem BinaryTree.mem_treesOfNumNodesEq E0 #

∀ {x : BinaryTree Unit} {n : ℕ}, x ∈ BinaryTree.treesOfNumNodesEq n ↔ x.numNodes = n

theorem BinaryTree.mem_treesOfNumNodesEq_numNodes E0 #

∀ (x : BinaryTree Unit), x ∈ BinaryTree.treesOfNumNodesEq x.numNodes

theorem BinaryTree.coe_treesOfNumNodesEq E0 #

∀ (n : ℕ), ↑(BinaryTree.treesOfNumNodesEq n) = {x | x.numNodes = n}

theorem BinaryTree.treesOfNumNodesEq_card_eq_catalan E3 #

∀ (n : ℕ), (BinaryTree.treesOfNumNodesEq n).card = catalan n

Deprecated aliases

NameNew nameSince
Tree.treesOfNumNodesEqBinaryTree.treesOfNumNodesEq2026-06-07