n-ary trees (generalized Merge) #
n-ary tree: generalization of SyntacticObject to n-ary branching. When n = 2 this recovers binary trees (= SyntacticObject). When n ≥ 3 this models hypothetical n-ary Merge.
Instances For
Leaf count of an n-ary tree
Equations
- Minimalism.NaryTree.leaf.leafCount = 1
- (Minimalism.NaryTree.node children).leafCount = ∑ i : Fin n, (children i).leafCount
Instances For
Achievable leaf counts (Lemma 4.4) #
For n-ary trees:
- Binary (n=2): every k ≥ 1 is achievable
- n-ary (n≥3): only k ≡ 1 (mod n-1) are achievable, i.e. k = j(n-1) + 1
The set of leaf counts achievable by n-ary trees
Equations
- Minimalism.achievableLeafCounts n = {k : ℕ | ∃ (t : Minimalism.NaryTree n), t.leafCount = k}
Instances For
A single leaf achieves count 1 for any arity
Binary trees achieve leaf count 2 (a single node with two leaves)
Replace the leftmost leaf of a binary tree with a node of two leaves. This increases leafCount by exactly 1.
Equations
- One or more equations did not get rendered due to their size.
- Minimalism.NaryTree.leaf.expandLeaf = Minimalism.NaryTree.node fun (x : Fin 2) => Minimalism.NaryTree.leaf
Instances For
Binary trees achieve all leaf counts k ≥ 1.
Proof: induction on k. Base k=1: single leaf. Step: expand a leaf to
get one more, via expandLeaf which increases leafCount by exactly 1.
Node count of an n-ary tree
Equations
- Minimalism.NaryTree.leaf.nodeCount = 0
- (Minimalism.NaryTree.node children).nodeCount = 1 + ∑ i : Fin n, (children i).nodeCount
Instances For
For n-ary trees (n ≥ 2), leaf count k must satisfy k ≡ 1 (mod n-1).
Each n-ary node replaces 1 "slot" with n children, net gain of n-1 leaves. Starting from 1 leaf, after j nodes we have j(n-1) + 1 leaves.
For n ≥ 3, not all leaf counts are achievable. Specifically, 2 is not achievable when n ≥ 3 (since 2-1 = 1 is not divisible by n-1 ≥ 2).
Binary Merge is uniquely optimal: it's the only n ≥ 2 that achieves all leaf counts (Lemma 4.4).
Catalan bridge #
The number of binary tree shapes with n internal nodes equals the nth Catalan number. We connect this to SyntacticObject via the FreeMagma equivalence.
Binary tree shape: SO with Unit tokens (only tree structure matters)
Equations
Instances For
Count internal nodes of a FreeMagma tree
Equations
Instances For
The nodeCount of an SO equals the nodeCount of its FreeMagma image
Internal node count = FreeMagma.length - 1 for FreeMagma trees
SO.nodeCount = FreeMagma.length - 1 via the isomorphism.
Bridges leaf_node_relation to FreeMagma.length.
Map an SO to its shape (forget token identity, keep tree structure)
Equations
- so.toShape = (FreeMagma.map fun (x : Minimalism.LIToken) => ()) (Minimalism.toFreeMagma so)
Instances For
The number of binary tree shapes with n internal nodes equals the nth Catalan number.
This is a direct application of mathlib's treesOfNumNodesEq_card_eq_catalan,
which counts Tree Unit shapes. The connection to SyntacticObject goes through
the FreeMagma ≃ SO equivalence and the well-known bijection between
full binary trees and Tree Unit.