Documentation

Linglib.Core.Order.TreePath

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):

instancelinguistic reading
OrderBotthe root position ⟨[]⟩
PredOrderparent (mother-of): drop the last index
IsPredArchimedeanfinite ancestor chains
SemilatticeInfleast 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).

def List.commonPrefix {α : Type u_1} [DecidableEq α] :
List αList αList α

Longest common prefix of two lists.

Equations
Instances For
    theorem List.commonPrefix_prefix_left {α : Type u_1} [DecidableEq α] (l₁ l₂ : List α) :
    l₁.commonPrefix l₂ <+: l₁
    theorem List.commonPrefix_prefix_right {α : Type u_1} [DecidableEq α] (l₁ l₂ : List α) :
    l₁.commonPrefix l₂ <+: l₂
    theorem List.prefix_commonPrefix {α : Type u_1} [DecidableEq α] {r l₁ l₂ : List α} :
    r <+: l₁r <+: l₂r <+: l₁.commonPrefix l₂
    theorem List.commonPrefix_comm {α : Type u_1} [DecidableEq α] (l₁ l₂ : List α) :
    l₁.commonPrefix l₂ = l₂.commonPrefix l₁
    theorem List.IsPrefix.getElem?_eq_of_lt {α : Type u_1} {l₁ l₂ : List α} (h : l₁ <+: l₂) {i : } (hi : i < l₁.length) :
    l₂[i]? = l₁[i]?

    A prefix agrees with its extension below its length.

    theorem List.append_singleton_prefix_of_getElem? {α : Type u_1} {cp l : List α} (h : cp <+: l) {i : α} (hi : l[cp.length]? = some i) :
    cp ++ [i] <+: l

    A prefix extends by the element sitting at its length.

    theorem List.getElem?_commonPrefix_ne {α : Type u_1} [DecidableEq α] {l₁ l₂ : List α} {i j : α} :
    l₁[(l₁.commonPrefix l₂).length]? = some il₂[(l₁.commonPrefix l₂).length]? = some ji j

    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
      def Core.Order.instDecidableEqTreePath.decEq (x✝ x✝¹ : TreePath) :
      Decidable (x✝ = x✝¹)
      Equations
      Instances For
        def Core.Order.instReprTreePath.repr :
        TreePathStd.Format
        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          @[implicit_reducible]

          Dominance order: p ≤ q iff p is a prefix of q (p dominates q).

          Equations
          theorem Core.Order.TreePath.le_def {p q : TreePath} :
          p q p.toList <+: q.toList
          @[implicit_reducible]
          Equations
          • One or more equations did not get rendered due to their size.
          theorem Core.Order.TreePath.prefix_or_prefix {p q r : TreePath} (hp : p r) (hq : q r) :
          p q q p

          Two prefixes of the same list are comparable: the Connected Ancestor Condition (CAC) for the prefix order ([BP90]'s Definition 15). Delegates to List.prefix_or_prefix_of_prefix.

          The root: OrderBot #

          @[implicit_reducible]
          Equations
          theorem Core.Order.TreePath.length_strictMono {p q : TreePath} (h : p < q) :
          p.toList.length < q.toList.length

          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.

          The parent position: drop the last index. Root's parent is itself.

          Equations
          Instances For

            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.)

            @[implicit_reducible]
            Equations
            • One or more equations did not get rendered due to their size.
            @[simp]
            theorem Core.Order.TreePath.pred_eq_parent (p : TreePath) :
            Order.pred p = p.parent

            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.)

            @[implicit_reducible]
            Equations
            • One or more equations did not get rendered due to their size.
            @[reducible, inline]

            Least common ancestor, by its linguistic name. lca p q is the deepest position dominating both p and q — the smallest constituent position containing both.

            Equations
            • p.lca q = pq
            Instances For

              Sisterhood #

              Sisters: distinct positions with the same parent.

              Equations
              Instances For

                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.

                p linearly precedes q: at some shared position r, p continues into an earlier child than q.

                Equations
                • p.Precedes q = ∃ (r : List ) (i : ) (j : ), i < j r ++ [i] <+: p.toList r ++ [j] <+: q.toList
                Instances For
                  theorem Core.Order.TreePath.Precedes.not_le {p q : TreePath} (h : p.Precedes q) :
                  ¬p q

                  Precedence excludes dominance.

                  theorem Core.Order.TreePath.Precedes.not_ge {p q : TreePath} (h : p.Precedes q) :
                  ¬q p

                  Precedence excludes being dominated.

                  theorem Core.Order.TreePath.Precedes.mono {p q p' q' : TreePath} (h : p.Precedes q) (hp : p p') (hq : q q') :
                  p'.Precedes q'

                  Nontangling (downward inheritance; the third clause of Wall's tree definition, [BP90] Definition 1): precedence is inherited by descendants.

                  theorem Core.Order.TreePath.Precedes.precedes_iff {p q : TreePath} :
                  p.Precedes q ∃ (i : ) (j : ), p.toList[(p.toList.commonPrefix q.toList).length]? = some i q.toList[(p.toList.commonPrefix q.toList).length]? = some j i < j

                  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).

                  @[implicit_reducible]
                  Equations
                  • One or more equations did not get rendered due to their size.

                  Precedence is asymmetric.

                  theorem Core.Order.TreePath.Precedes.cons {p q : TreePath} (i : ) (h : p.Precedes q) :
                  { toList := i :: p.toList }.Precedes { toList := i :: q.toList }

                  Prepending a shared child index preserves precedence.

                  theorem Core.Order.TreePath.Precedes.of_index_lt {i j : } (hij : i < j) (p q : TreePath) :
                  { toList := i :: p.toList }.Precedes { toList := j :: q.toList }

                  Positions under distinct child indices are precedence-ordered by those indices (divergence at the root).

                  theorem Core.Order.TreePath.Precedes.trichotomy (p q : TreePath) :
                  p q q p p.Precedes q q.Precedes p

                  Totality over the dominance remainder: any two positions are dominance-comparable or precedence-ordered — the exhaustiveness that linear-precedence statements need.

                  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.
                  Instances For