Tree positions #
A TreePath is a position in a rose tree, written as its Gorn address: the list of child indices
on the way down from the root. Under the prefix order, with p ≤ q when p dominates q, the
positions form the rooted tree in which every node has a child for each natural number. It carries
the order structure of Mathlib/Order/SuccPred/Tree.lean: the root ⊥ is the empty address,
Order.pred drops the last index, p ⊓ q is the longest common prefix, and strict dominance is
well founded, so ancestor chains are finite. The positions of a concrete tree form a prefix-closed
subset (RoseTree.validPaths).
p precedes q when the two part at some position with p taking the earlier child. Precedence
is lexicographic order between positions neither of which dominates the other. It is a decidable
strict order, it passes to dominated positions, and any two positions are related by dominance or
by precedence.
Two positions are left-aligned when their addresses differ only in trailing first-daughter steps, so that the subtrees at them begin with the same leaf. Left-alignment is a decidable equivalence relation, and left-aligned positions lie on one branch.
Main definitions #
Core.Order.TreePath: Gorn addresses under the prefix order.Core.Order.TreePath.Precedes: linear precedence of positions.Core.Order.TreePath.LeftAligned: positions sharing a left edge.
Main results #
TreePath.covBy_iff:qcoverspexactly whenqextendspby one index.TreePath.precedes_iff_lt_and_not_le: precedence is lexicographic order minus dominance.TreePath.Precedes.trichotomy: two positions are related by dominance or by precedence.TreePath.leftAligned_iff_exists: positions are left-aligned exactly when descending through first daughters from each reaches a common position.
A position in a rose tree is given by its Gorn address, the child indices on the path from the root. The empty address is the root.
- toList : List ℕ
The child indices, from the root down.
Instances For
Equations
- Core.Order.instDecidableEqTreePath.decEq { toList := a } { toList := b } = if h : a = b then h ▸ isTrue ⋯ else isFalse ⋯
Instances For
Equations
- Core.Order.instReprTreePath = { reprPrec := Core.Order.instReprTreePath.repr }
Equations
- One or more equations did not get rendered due to their size.
Instances For
A position dominates another when its address is a prefix of the other's.
Equations
- Core.Order.TreePath.instLE = { le := fun (p q : Core.Order.TreePath) => p.toList <+: q.toList }
Equations
- x✝¹.instDecidableLE x✝ = decidable_of_iff (x✝¹.toList <+: x✝.toList) ⋯
Equations
- One or more equations did not get rendered due to their size.
Equations
- x✝¹.instDecidableLT x✝ = decidable_of_iff (x✝¹ ≤ x✝ ∧ ¬x✝ ≤ x✝¹) ⋯
Equations
- Core.Order.TreePath.instOrderBot = { bot := { toList := [] }, bot_le := Core.Order.TreePath.instOrderBot._proof_1 }
Parents #
Equations
- Core.Order.TreePath.instPredOrder = { pred := Core.Order.TreePath.parent, pred_le := Core.Order.TreePath.parent_le, min_of_le_pred := ⋯, le_pred_of_lt := ⋯ }
A position is covered exactly by its daughters, the extensions by one index.
Least common ancestors #
The meet of two positions is their longest common prefix, the deepest position dominating both.
Equations
- One or more equations did not get rendered due to their size.
Linear precedence #
A position precedes no position it dominates.
A position precedes no position that dominates it.
Precedence passes to the positions each relatum dominates.
Equations
- p.instDecidablePrecedes q = decidable_of_iff (p.toList < q.toList ∧ ¬p ≤ q) ⋯
Any two positions are related by dominance or by precedence.
Left edges #
Two positions are left-aligned when their addresses agree once trailing first-daughter steps are dropped, so that the subtrees at them begin with the same leaf.
Equations
- p.LeftAligned q = (List.dropWhile (fun (x : ℕ) => x == 0) p.toList.reverse = List.dropWhile (fun (x : ℕ) => x == 0) q.toList.reverse)
Instances For
Equations
Positions are left-aligned exactly when descending through first daughters from each reaches a common position.
Left-aligned positions lie on one branch.