Finite plane trees #
A plane tree is a finite rooted tree whose children are ordered. We use Mathlib's
WType, with Fin n indexing the children of a vertex of outdegree n.
PlaneTree.node and PlaneTree.children provide the list interface. The induction
and cases tactics produce a single node ts case, and PlaneTree.fold defines
functions by bottom-up recursion, so the WType encoding is not used outside this file.
Addresses are zero-based lists of child indices; the root has address [].
These are implementation coordinates, independent of the paper's one-based
numbering of vertices in depth-first order. Size counts vertices, including the root.
Finite rooted ordered trees, with no vertex labels.
Equations
- BGW.PlaneTree = WType fun (n : ℕ) => Fin n
Instances For
Equations
- BGW.instEncodablePlaneTree = { encode := BGW.instEncodablePlaneTree._aux_1, decode := BGW.instEncodablePlaneTree._aux_3, encodek := BGW.instEncodablePlaneTree._proof_5 }
Finite ordered forests. The empty forest is allowed.
Equations
Instances For
A tree is determined by the ordered list of subtrees attached to its root.
Equations
- BGW.PlaneTree.equivChildren = (WType.equivSigma fun (n : ℕ) => Fin n).trans List.equivSigmaTuple.symm
Instances For
Attach an ordered list of trees to a new root.
Equations
Instances For
The ordered subtrees attached to the root.
Equations
Instances For
Bottom-up recursion: fold g applies g to the values already computed at the
children of the root, in child order.
Equations
- BGW.PlaneTree.fold g = WType.elim β fun (x : (a : ℕ) × (Fin a → β)) => match x with | ⟨fst, f⟩ => g (List.ofFn f)
Instances For
The tree consisting only of its root.
Equations
Instances For
The number of vertices, including the root.
Equations
- BGW.PlaneTree.size = BGW.PlaneTree.fold fun (ns : List ℕ) => 1 + ns.sum
Instances For
Lookup of a fringe subtree. none means that the address is not a vertex.
The returned tree is re-rooted: its addresses start at [] again.