Planar n-ary rooted trees with vertex labels in α #
@cite{marcolli-chomsky-berwick-2025} @cite{foissy-introduction-hopf-algebras-trees}
A planar rooted tree has: a distinguished root vertex, an α-label at every vertex, and an ordered (list-valued) sequence of children at each non-leaf vertex. Each vertex's "arity" is the length of its child list; leaves are vertices with empty child lists. There is no global arity bound — vertices may have any number of children.
This is the most general planar tree carrier the Connes-Kreimer-style Hopf algebra needs. Specializations as subtypes:
Binary(every internal vertex has exactly 2 children) ≃FreeMagma α(the existing linglib binary planar carrier).NaryAtMost n(every vertex has ≤ n children).NaryExactly n(every internal vertex has exactly n children, leaves 0).
The nonplanar version (children as multiset, not list) is in
RootedTree.Nonplanar (sibling file), defined as a quotient by
permutations of children at each level.
Why list-of-children, not multiset directly #
Lean 4's strict positivity check rejects
inductive Tree | node : α → Multiset (Tree α) → Tree α because
Multiset = Quot (List _) _ is opaque to the positivity checker. The
standard workaround: define the planar (list-valued) version as a
genuine inductive, then quotient by a permutation relation to get the
nonplanar version. This file provides the list-valued primitive;
Nonplanar.lean provides the quotient.
MCB anchor #
@cite{marcolli-chomsky-berwick-2025} §1.11 introduces n-ary syntactic
objects SO^(n) ≃ ℑ^(n)_{SO_0} as the free nonassociative commutative
n-magma; book p. 96 Definition 1.11.2. §1.17 uses the n-ary
Connes-Kreimer Hopf algebra of rooted trees in the recursive
construction of solutions to combinatorial Dyson-Schwinger equations
(book p. 149-150). The carrier here is parameterized over arity (no
fixed n), subsuming all n-ary cases via subtypes.
@cite{foissy-introduction-hopf-algebras-trees} §1.1 (p. 3) introduces
rooted trees as finite graphs, connected and without cycles, with a
distinguished root vertex; this file's Planar is the planar / ordered
variant (Foissy's H_PR setting, §2). The nonplanar variant (Foissy's
H_R, §1) is the quotient in Nonplanar.lean.
Status #
[UPSTREAM] candidate; future home something like
Mathlib.Combinatorics.RootedTree.Planar. No sorries, no
noncomputable, no decide in this file.
§1: The Planar inductive #
A planar rooted tree is built by node a cs where a : α is the root
label and cs : List (Planar α) is the ordered list of children.
Leaves are node a [].
§2: Basic projections #
The (ordered) list of children at the root.
Equations
- (RootedTree.Planar.node a cs).children = cs
Instances For
§3: Counting — weight, arity, depth #
Defined by structural recursion (mutual with the list-of-trees aux).
The weight of a tree: total number of vertices.
Equations
- (RootedTree.Planar.node a cs).weight = 1 + RootedTree.Planar.weightList cs
Instances For
Auxiliary: total weight of a list of trees.
Equations
- RootedTree.Planar.weightList [] = 0
- RootedTree.Planar.weightList (t :: ts) = t.weight + RootedTree.Planar.weightList ts
Instances For
The depth of a tree: longest root-to-leaf path length (in edges). A leaf has depth 0.
Equations
- (RootedTree.Planar.node a cs).depth = 1 + RootedTree.Planar.depthMaxList cs
Instances For
Auxiliary: max depth across a list of trees (0 for empty).
Equations
- RootedTree.Planar.depthMaxList [] = 0
- RootedTree.Planar.depthMaxList (t :: ts) = max t.depth (RootedTree.Planar.depthMaxList ts)
Instances For
The arity of the root vertex: number of children. Leaves have arity 0.
Equations
- (RootedTree.Planar.node a cs).arity = cs.length
Instances For
A tree is a leaf if its root has no children.
Equations
- (RootedTree.Planar.node a []).isLeaf = true
- (RootedTree.Planar.node a (head :: tail)).isLeaf = false
Instances For
§4: Smart constructors #
A leaf with the given α-label.
Equations
Instances For
A unary node: single child.
Equations
- RootedTree.Planar.unary a c = RootedTree.Planar.node a [c]
Instances For
A binary node: two children, in left-to-right order.
Equations
- RootedTree.Planar.binary a l r = RootedTree.Planar.node a [l, r]
Instances For
An n-ary node: list of children.
Equations
- RootedTree.Planar.nary a cs = RootedTree.Planar.node a cs
Instances For
§5: Functoriality #
Planar is a functor in the vertex-label parameter: a function f : α → β
lifts to Planar α → Planar β by relabeling every vertex. Defined by
mutual structural recursion on (tree, list-of-trees). Counterpart
of mathlib's Tree.map for binary trees and List.map for lists.
Map a function over the vertex labels of a planar rooted tree.
Equations
- RootedTree.Planar.map f (RootedTree.Planar.node a cs) = RootedTree.Planar.node (f a) (RootedTree.Planar.mapList f cs)
Instances For
Auxiliary: map across a list of children.
Equations
- RootedTree.Planar.mapList f [] = []
- RootedTree.Planar.mapList f (t :: ts) = RootedTree.Planar.map f t :: RootedTree.Planar.mapList f ts
Instances For
Counting interactions #
§5b: Sanity tests at compile time #
§6: Inhabited #
Equations
- RootedTree.Planar.instInhabited = { default := RootedTree.Planar.leaf default }