Documentation

Linglib.Core.Order.TreePath

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 #

Main results #

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
    theorem Core.Order.TreePath.ext {x y : TreePath} (toList : x.toList = y.toList) :
    x = y
    theorem Core.Order.TreePath.ext_iff {x y : TreePath} :
    x = y ↔ x.toList = y.toList
    def Core.Order.instDecidableEqTreePath.decEq (x✝ x✝¹ : TreePath) :
    Decidable (x✝ = x✝¹)
    Equations
    Instances For
      def Core.Order.instReprTreePath.repr :
      TreePath → ℕ → Std.Format
      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        @[instance_reducible]

        A position dominates another when its address is a prefix of the other's.

        Equations
        theorem Core.Order.TreePath.le_def {p q : TreePath} :
        p ≤ q ↔ p.toList <+: q.toList
        @[simp]
        theorem Core.Order.TreePath.mk_le_mk {l m : List ℕ} :
        { toList := l } ≤ { toList := m } ↔ l <+: m
        @[instance_reducible]
        Equations
        @[instance_reducible]
        Equations
        • One or more equations did not get rendered due to their size.
        @[instance_reducible]
        Equations
        • x✝¹.instDecidableLT x✝ = decidable_of_iff (x✝¹ ≤ x✝ ∧ ¬x✝ ≤ x✝¹) ⋯
        @[instance_reducible]
        Equations
        theorem Core.Order.TreePath.length_strictMono :
        StrictMono fun (p : TreePath) => p.toList.length

        Parents #

        The parent of a position drops its last index. The root is its own parent.

        Equations
        Instances For
          theorem Core.Order.TreePath.le_parent_of_lt {p q : TreePath} (h : p < q) :
          p ≤ q.parent
          @[instance_reducible]
          Equations
          @[simp]
          theorem Core.Order.TreePath.pred_eq_parent (p : TreePath) :
          Order.pred p = p.parent
          theorem Core.Order.TreePath.covBy_iff {p q : TreePath} :
          p ⋖ q ↔ ∃ (i : ℕ), q.toList = p.toList ++ [i]

          A position is covered exactly by its daughters, the extensions by one index.

          Least common ancestors #

          @[instance_reducible]

          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 #

          p precedes q when, at some common position, 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

            A position comes lexicographically before every position it precedes.

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

            A position precedes no position it dominates.

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

            A position precedes no position that dominates it.

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

            Precedence passes to the positions each relatum dominates.

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

            Prefixing a common index preserves precedence.

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

            Positions under distinct daughters of the root are ordered as the daughters are.

            p precedes q exactly when p comes lexicographically before q without dominating it.

            @[instance_reducible]
            Equations
            theorem Core.Order.TreePath.Precedes.trans {p q r : TreePath} (h₁ : p.Precedes q) (h₂ : q.Precedes r) :
            theorem Core.Order.TreePath.Precedes.trichotomy (p q : TreePath) :
            p ≤ q ∨ q ≤ p ∨ p.Precedes q ∨ q.Precedes p

            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
              theorem Core.Order.TreePath.leftAligned_iff_exists {p q : TreePath} :
              p.LeftAligned q ↔ ∃ (j : ℕ) (k : ℕ), p.toList ++ List.replicate j 0 = q.toList ++ List.replicate k 0

              Positions are left-aligned exactly when descending through first daughters from each reaches a common position.

              theorem Core.Order.TreePath.LeftAligned.le_or_ge {p q : TreePath} (h : p.LeftAligned q) :
              p ≤ q ∨ q ≤ p

              Left-aligned positions lie on one branch.