Tree Positions: TreePath and the Rooted-Tree Order Stack #
A TreePath is a position in a rose tree, encoded as a list of child
indices (a Gorn address). Under the prefix order (dominance), TreePath
instantiates mathlib's order-theoretic rooted-tree stack
(Mathlib.Order.SuccPred.Tree):
| instance | linguistic reading |
|---|---|
OrderBot | the root position ⟨[]⟩ |
PredOrder | parent (mother-of): drop the last index |
IsPredArchimedean | finite ancestor chains |
SemilatticeInf | least common ancestor — the smallest |
| constituent position containing both |
TreePath itself is the full ℕ-branching tree of positions; a
concrete tree's valid positions form a prefix-closed subset (see
Core/Order/Branching.lean), which inherits the stack.
Moved here from Syntax/Tree/Basic.lean: positions are pure
combinatorics, instantiable by any rose-tree carrier (CFG derivation
trees via Gorn addresses, Hopf-algebra rooted trees, constituency
trees) without importing linguistic theory.
Generic list API: longest common prefix #
Upstream-shaped for Mathlib/Data/List/Prefix.lean (no
commonPrefix exists in mathlib or Batteries as of 2026-06).
Longest common prefix of two lists.
Equations
- (a :: as).commonPrefix (b :: bs) = if a = b then a :: as.commonPrefix bs else []
- x✝¹.commonPrefix x✝ = []
Instances For
A prefix agrees with its extension below its length.
A prefix extends by the element sitting at its length.
The lists genuinely diverge just past their common prefix.
A position (Gorn address) in a rose tree: a list of child indices. The empty path is the root.
- toList : List ℕ
The underlying list of child indices.
Instances For
Equations
- Core.Order.instDecidableEqTreePath.decEq { toList := a } { toList := b } = if h : a = b then h ▸ isTrue ⋯ else isFalse ⋯
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Core.Order.instReprTreePath = { reprPrec := Core.Order.instReprTreePath.repr }
Dominance order: p ≤ q iff p is a prefix of q (p dominates q).
Equations
- Core.Order.TreePath.instLE = { le := fun (p q : Core.Order.TreePath) => p.toList <+: q.toList }
Equations
- One or more equations did not get rendered due to their size.
The root: OrderBot #
Equations
- Core.Order.TreePath.instOrderBot = { bot := { toList := [] }, bot_le := Core.Order.TreePath.instOrderBot._proof_1 }
Parent: PredOrder #
Order.pred is mother-of: drop the last child index. The root is its
own predecessor (pred ⊥ = ⊥), matching mathlib's convention that
pred of a minimal element is itself.
A non-root position is properly dominated by its parent — the
Single Mother Condition reading: every node except the root has a
mother that is a proper ancestor. (Order.pred ⊥ = ⊥ is mathlib's
convention; linguistic axioms quantifying over mothers need this
≠ ⊥ guard.)
Equations
- One or more equations did not get rendered due to their size.
Finite depth: IsPredArchimedean #
Least common ancestor: SemilatticeInf #
p ⊓ q is the longest common prefix — the deepest position dominating
both, i.e. the smallest constituent position containing both.
(List.commonPrefix and its lemmas live in the _root_.List
namespace at the top of this file; they are generic list API,
upstream-shaped for Mathlib/Data/List/Prefix.lean.)
Equations
- One or more equations did not get rendered due to their size.
Sisterhood #
Linear precedence #
The PF-side order that dominance forgets: p precedes q iff their
paths diverge at some common prefix with p taking an earlier branch.
Defined only between dominance-incomparable positions
(Precedes.not_le, Precedes.not_ge) — a node neither precedes nor
follows its ancestors, the ID/LP division of labor.
Precedence excludes dominance.
Precedence excludes being dominated.
The divergence index of Precedes is exactly the common-prefix
length: p precedes q iff at index (commonPrefix p q).length both
paths continue and p's branch index is smaller. The computable
characterization behind Decidable (Precedes p q).
Equations
- One or more equations did not get rendered due to their size.
Precedence is asymmetric.
The bundled mathlib rooted tree #
TreePath carries all four classes of Mathlib.Order.SuccPred.Tree's
RootedTree; the bundling makes the alignment true by construction
and opens mathlib's findAtom/subtree API.
TreePath as a mathlib RootedTree.
Equations
- One or more equations did not get rendered due to their size.