AFTD Auto-Formalizing Theoretical Domains

bin_tree_num_leaves

def

The function bin_tree_num_leaves computes the number of leaves in an ordered full binary tree: 1 for a leaf, and bin_tree_num_leaves l + bin_tree_num_leaves r for a node with left child l and right child r.

Statement

def bin_tree_num_leaves : BinTree → ℕ
Defined in
arXiv:2611.19659, Section 2
Verified
20 Nov 2026
Axioms
none listed
Built on 1
  • BinTreeThe inductive type BinTree of ordered full binary trees with constructors leaf and node left right.
Used by 1
  • associahedronGraphFor each natural number n, the associahedron graph associahedronGraph n is the simple graph whose vertices are ordered full binary trees T…

Read back from the Lean

The function bin_tree_num_leaves, which maps a binary tree BinTree to a natural number (ℕ), defined by structural recursion: mapping .leaf to 1, and mapping .node l r to the sum bin_tree_num_leaves l + bin_tree_num_leaves r.

Written by a model that saw only the Lean, never the English above. If the two disagree, that is worth a challenge.

Lean source view module on GitHub

/-- Number of leaves in an ordered full binary tree. -/
def bin_tree_num_leaves : BinTree → ℕ
  | .leaf => 1
  | .node l r => bin_tree_num_leaves l + bin_tree_num_leaves r
See it in the graphDiscuss this resultChallenge it