Draft — mutable and not usable as a dependency; its citation marks the draft state.

Lax194892.ChildConfigurationGraphs

Children of a configuration and child configuration graphs

concepts/Lax194892/ChildConfigurationGraphs.lean · lax-194892

definition

Loading review…

Sign in with ORCID

Community review

Flags

Each flag is tied to a public ORCID identity and explains why this concept may be incorrect.

No flags have been submitted.

    Community review

    Flag this concept

    State precisely what appears incorrect. This explanation will be public under your ORCID name.

    No source line selected.

    Concept map

    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    In the paper

    Definition

    Section D.2 of Transducers organises a run of a pebble transducer as a tree: the children of a configuration of height \ell are the configurations of height +1\ell + 1 that the run visits after it before coming back down to height \ell; between two consecutive children the run stays above height +1\ell + 1. The children are described by the child configuration graph: a directed graph whose vertices are pairs of a state and a gap — the position of the moving pebble +1\ell + 1 — with an edge for the run between two consecutive children, annotated with the input string and the positions of the fixed pebbles 1,,1, \ldots, \ell. Like a configuration, a child configuration graph is represented as a string over a fixed finite alphabet with one letter per gap of the input, and the output of the graph is the concatenation of the string representations of the children in order of execution. Lemma D.2.5 and Claims D.2.6–D.2.7 say that a for-transducer computes the graph from the configuration and the children from the graph.

    Lean source view on GitHub

    1import Mathlib.Data.Nat.Find
    2import Mathlib.Data.Finite.Defs
    3import Lax194892.PebbleConfigurationEncoding
    4
    5/-!
    6---
    7title: Children of a configuration and child configuration graphs
    8type: definition
    9---
    10Section D.2 of *Transducers* organises a run of a pebble transducer as a
    11tree: the *children* of a configuration of height \ell are the configurations
    12of height +1\ell + 1 that the run visits after it before coming back down to
    13height \ell; between two consecutive children the run stays above height
    14+1\ell + 1. The children are described by the *child configuration graph*: a
    15directed graph whose vertices are pairs of a state and a gap — the position of
    16the moving pebble +1\ell + 1 — with an edge for the run between two consecutive
    17children, annotated with the input string and the positions of the fixed
    18pebbles 1,,1, \ldots, \ell. Like a configuration, a child configuration graph is
    19represented as a string over a fixed finite alphabet with one letter per gap of
    20the input, and the *output* of the graph is the concatenation of the string
    21representations of the children in order of execution. Lemma D.2.5 and Claims
    22D.2.6–D.2.7 say that a for-transducer computes the graph from the configuration
    23and the children from the graph.
    24
    25# Formalization notes
    26
    27A child is the vertex `(q, p)` standing for the configuration whose stack is
    28the parent's with the gap `p` on top (`cfgOf`); `FirstChild` and `NextChild` are
    29runs that stay strictly above the children's height (`StrictAbove`, a run of at
    30least one step whose intermediate configurations have height at least `h`),
    31and `IsChildSeq M w q st ch m` says that `ch 0, …, ch m` is the list of the
    32children of `(q, st)`. `confEnc` is the string representation of a single
    33configuration (the shape of `PebbleConfigurationEncoding`, for one
    34configuration). A letter of the child configuration graph carries the input
    35letter, the fixed pebbles of the gap, the index of the moving pebble, which
    36states are the first child in this column, and for every state the outgoing
    37and the incoming edge of the vertex, the latter redundant but what makes the
    38representation locally checkable (`Chk`). `cgOfChildren` is the representation
    39of the graph of a configuration with children `ch`, and `CGOutIs u v` says
    40that `v` is the concatenation of the children's representations read off the
    41graph `u` (`CGPath`); a string determines at most one such `v`.
    42-/
    43
    44namespace Lax194892.ChildConfigurationGraphs
    45
    46open Lax194892.PebbleTransducers Lax194892.PebbleConfigurationEncoding
    47
    48-- ## The children of a configuration
    49
    50/-- The stack has height at least `h`; the halting vertex has no height. -/
    51def HeightGe {Q : Type} (h : ℕ) : PebbleCfg Q → Prop
    52 | PebbleCfg.conf _ st => h ≤ st.length
    53 | PebbleCfg.halt => False
    54
    55/-- A run of at least one step whose intermediate configurations have height at
    56least `h`. -/
    57inductive StrictAbove {A B Q : Type} {k : ℕ} (M : Pebble A B Q k) (w : List A) (h : ℕ) :
    58 PebbleCfg Q → PebbleCfg Q → Prop
    59 /-- A single step. -/
    60 | one {c c' : PebbleCfg Q} {o : List B} : M.stepCfg w c = some (o, c') → StrictAbove M w h c c'
    61 /-- A step to a configuration of height at least `h`, followed by such a run. -/
    62 | cons {c c' c'' : PebbleCfg Q} {o : List B} : M.stepCfg w c = some (o, c') → HeightGe h c' →
    63 StrictAbove M w h c' c'' → StrictAbove M w h c c''
    64
    65/-- A vertex of a child configuration graph: a state and a gap. -/
    66abbrev Vtx (Q : Type) := Q × ℕ
    67
    68/-- The configuration of the child `v` of a configuration with stack `st`: the
    69moving pebble sits on top. -/
    70def cfgOf {Q : Type} (st : List ℕ) (v : Vtx Q) : PebbleCfg Q := PebbleCfg.conf v.1 (st ++ [v.2])
    71
    72/-- `v'` is the child following the child `v`: the run from `v` first returns to
    73the children's height at `v'`. -/
    74def NextChild {A B Q : Type} {k : ℕ} (M : Pebble A B Q k) (w : List A) (st : List ℕ)
    75 (v v' : Vtx Q) : Prop :=
    76 StrictAbove M w (st.length + 2) (cfgOf st v) (cfgOf st v')
    77
    78/-- `v` is the first child of the configuration `(q, st)`. -/
    79def FirstChild {A B Q : Type} {k : ℕ} (M : Pebble A B Q k) (w : List A) (q : Q) (st : List ℕ)
    80 (v : Vtx Q) : Prop :=
    81 StrictAbove M w (st.length + 2) (PebbleCfg.conf q st) (cfgOf st v)
    82
    83/-- `ch 0, …, ch m` is the list of the children of `(q, st)`, in order of
    84execution. -/
    85structure IsChildSeq {A B Q : Type} {k : ℕ} (M : Pebble A B Q k) (w : List A) (q : Q)
    86 (st : List ℕ) (ch : ℕ → Vtx Q) (m : ℕ) : Prop where
    87 /-- The list starts with the first child. -/
    88 first : FirstChild M w q st (ch 0)
    89 /-- Each child is followed by the next one. -/
    90 next : ∀ t < m, NextChild M w st (ch t) (ch (t + 1))
    91 /-- The last child has no successor. -/
    92 stop : ∀ v, ¬ NextChild M w st (ch m) v
    93
    94-- ## String representations
    95
    96/-- A letter of the representation of a configuration: the state, the input letter
    97following the gap, and the pebbles in the gap. -/
    98abbrev ConfLetter (A Q : Type) (k : ℕ) := Q × Option A × (Fin k → Bool)
    99
    100/-- The string representation of the configuration `(q, st)` of `w`: one letter per
    101gap. -/
    102def confEnc {A Q : Type} {k : ℕ} (q : Q) (st : List ℕ) (w : List A) : List (ConfLetter A Q k) :=
    103 (List.range (w.length + 1)).map fun p => (q, w[p]?, ann k st p)
    104
    105/-- The direction of an edge: inside the column, one column right, one column left. -/
    106abbrev Dir := Option Bool
    107
    108/-- The column that the direction `d` leads to from the column `p`. -/
    109def dest (p : ℕ) : Dir → Option ℕ
    110 | none => some p
    111 | some true => some (p + 1)
    112 | some false => if p = 0 then none else some (p - 1)
    113
    114/-- The direction from the column `a` to the adjacent column `b`. -/
    115def dirOf (a b : ℕ) : Dir := if b = a then none else if a < b then some true else some false
    116
    117/-- A letter of the representation of a child configuration graph: one gap of the
    118input, with the input letter, the fixed pebbles, the index of the moving pebble,
    119the states that are the first child in this column, and the outgoing and
    120incoming edges of the vertices of this column. -/
    121structure CGLetter (A Q : Type) (k : ℕ) where
    122 /-- The input letter following this gap, absent for the last gap. -/
    123 lett : Option A
    124 /-- The fixed pebbles sitting in this gap. -/
    125 peb : Fin k → Bool
    126 /-- The index of the moving pebble. -/
    127 nid : Fin k
    128 /-- The states `q` for which `(q, this column)` is the first child. -/
    129 src : Q → Bool
    130 /-- The outgoing edge of `(q, this column)`. -/
    131 nxt : Q → Option (Q × Dir)
    132 /-- The incoming edge of `(q, this column)`. -/
    133 prv : Q → Option (Q × Dir)
    134
    135open scoped Classical in
    136/-- The index at which `v` occurs among the first `m` children, if any. -/
    137noncomputable def idxAt {Q : Type} (ch : ℕ → Vtx Q) (m : ℕ) (v : Vtx Q) : Option ℕ :=
    138 if h : ∃ t, t < m ∧ ch t = v then some (Nat.find h) else none
    139
    140open scoped Classical in
    141/-- The index `t < m` such that `v` is the child following `ch t`, if any. -/
    142noncomputable def idxSuccAt {Q : Type} (ch : ℕ → Vtx Q) (m : ℕ) (v : Vtx Q) : Option ℕ :=
    143 if h : ∃ t, t < m ∧ ch (t + 1) = v then some (Nat.find h) else none
    144
    145open scoped Classical in
    146/-- The representation of the child configuration graph whose children are
    147`ch 0, …, ch m`, over an input with `n + 1` gaps carrying the letters `lett` and
    148the fixed pebbles `peb`, the moving pebble having the index `nid`. -/
    149noncomputable def cgOfPath {A Q : Type} {k : ℕ} (lett : ℕ → Option A) (peb : ℕ → Fin k → Bool)
    150 (nid : Fin k) (n : ℕ) (ch : ℕ → Vtx Q) (m : ℕ) : List (CGLetter A Q k) :=
    151 (List.range (n + 1)).map fun j =>
    152 { lett := lett j
    153 peb := peb j
    154 nid := nid
    155 src := fun q' => decide ((q', j) = ch 0)
    156 nxt := fun q' => (idxAt ch m (q', j)).map fun t => ((ch (t + 1)).1, dirOf j (ch (t + 1)).2)
    157 prv := fun q' => (idxSuccAt ch m (q', j)).map fun t => ((ch t).1, dirOf (ch t).2 j) }
    158
    159/-- The representation of the child configuration graph of a configuration of `w`
    160with stack `st`, moving pebble `nid` and children `ch 0, …, ch m`. -/
    161noncomputable def cgOfChildren {A Q : Type} {k : ℕ} (w : List A) (st : List ℕ) (nid : Fin k)
    162 (ch : ℕ → Vtx Q) (m : ℕ) : List (CGLetter A Q k) :=
    163 cgOfPath (fun j => w[j]?) (fun j => ann k st j) nid w.length ch m
    164
    165-- ## Reading the children off a represented graph
    166
    167/-- The vertex that the edge out of `v` leads to, if any. -/
    168def succOf {A Q : Type} {k : ℕ} (u : List (CGLetter A Q k)) (v : Vtx Q) : Option (Vtx Q) :=
    169 (u[v.2]?).bind fun c => (c.nxt v.1).bind fun x => (dest v.2 x.2).map fun p' => (x.1, p')
    170
    171/-- `v` is marked as the first child. -/
    172def IsSrc {A Q : Type} {k : ℕ} (u : List (CGLetter A Q k)) (v : Vtx Q) : Prop :=
    173 ∃ c, u[v.2]? = some c ∧ c.src v.1 = true
    174
    175/-- The representation of the child that the vertex `v` stands for: the state of
    176`v`, the input letters and the fixed pebbles of the graph, and the moving pebble
    177in the column of `v`. -/
    178def confAt {A Q : Type} {k : ℕ} (u : List (CGLetter A Q k)) (v : Vtx Q) :
    179 List (ConfLetter A Q k) :=
    180 u.mapIdx fun j c => (v.1, c.lett, fun i => c.peb i || (decide (i = c.nid) && decide (v.2 = j)))
    181
    182/-- The letter to the left of the gap `i`. -/
    183def leftLet {A Q : Type} {k : ℕ} (u : List (CGLetter A Q k)) (i : ℕ) : Option (CGLetter A Q k) :=
    184 if i = 0 then none else u[i - 1]?
    185
    186open Classical in
    187/-- The local consistency test on two adjacent letters: every edge recorded by
    188`nxt` between or inside their columns is recorded by `prv` at its target, and a
    189vertex marked as the first child has no incoming edge. -/
    190noncomputable def pairOK {A Q : Type} {k : ℕ} (a b : Option (CGLetter A Q k)) : Bool := decide (
    191 (∀ q q' : Q, ∀ ca cb, a = some ca → b = some cb → ca.nxt q = some (q', some true) →
    192 cb.prv q' = some (q, some true)) ∧
    193 (∀ q q' : Q, ∀ ca cb, a = some ca → b = some cb → cb.nxt q = some (q', some false) →
    194 ca.prv q' = some (q, some false)) ∧
    195 (∀ q q' : Q, ∀ cb, b = some cb → cb.nxt q = some (q', none) → cb.prv q' = some (q, none)) ∧
    196 (∀ q : Q, ∀ cb, b = some cb → cb.src q = true → cb.prv q = none))
    197
    198/-- The string is locally consistent at every gap. -/
    199def Chk {A Q : Type} {k : ℕ} (u : List (CGLetter A Q k)) : Prop :=
    200 ∀ i ≤ u.length, pairOK (leftLet u i) u[i]? = true
    201
    202/-- `p 0, …, p m` is the run of children described by the locally consistent
    203string `u`: `p 0` is the unique first child, each `p (t+1)` is reached from `p t`
    204by the recorded edge, and `p m` has no outgoing edge. -/
    205structure CGPath {A Q : Type} {k : ℕ} (u : List (CGLetter A Q k)) (m : ℕ) (p : ℕ → Vtx Q) :
    206 Prop where
    207 /-- The string is locally consistent. -/
    208 chk : Chk u
    209 /-- `p 0` is the unique vertex marked as the first child. -/
    210 srcEq : ∀ v, IsSrc u v ↔ v = p 0
    211 /-- Every vertex of the run sits in a real column. -/
    212 inRange : ∀ t ≤ m, (u[(p t).2]?).isSome
    213 /-- Consecutive children are joined by the recorded edge. -/
    214 step : ∀ t < m, succOf u (p t) = some (p (t + 1))
    215 /-- The last child has no outgoing edge. -/
    216 last : succOf u (p m) = none
    217
    218/-- The concatenation of the representations of the children, in order. -/
    219def cgOut {A Q : Type} {k : ℕ} (u : List (CGLetter A Q k)) (m : ℕ) (p : ℕ → Vtx Q) :
    220 List (ConfLetter A Q k) :=
    221 ((List.range (m + 1)).map fun t => confAt u (p t)).flatten
    222
    223/-- `v` is the string representation of the children of the configuration whose
    224child configuration graph `u` represents. -/
    225def CGOutIs {A Q : Type} {k : ℕ} (u : List (CGLetter A Q k)) (v : List (ConfLetter A Q k)) :
    226 Prop :=
    227 ∃ m p, CGPath u m p ∧ v = cgOut u m p
    228
    229end Lax194892.ChildConfigurationGraphs
    230

    Formalization notes

    A child is the vertex (q,p)(q, p) standing for the configuration whose stack is the parent's with the gap pp on top (cfgOfcfgOf); FirstChildFirstChild and NextChildNextChild are runs that stay strictly above the children's height (StrictAboveStrictAbove, a run of at least one step whose intermediate configurations have height at least hh), and IsChildSeqMwqstchmIsChildSeq M w q st ch m says that ch0,,chmch 0, …, ch m is the list of the children of (q,st)(q, st). confEncconfEnc is the string representation of a single configuration (the shape of PebbleConfigurationEncodingPebbleConfigurationEncoding, for one configuration). A letter of the child configuration graph carries the input letter, the fixed pebbles of the gap, the index of the moving pebble, which states are the first child in this column, and for every state the outgoing and the incoming edge of the vertex, the latter redundant but what makes the representation locally checkable (ChkChk). cgOfChildrencgOfChildren is the representation of the graph of a configuration with children chch, and CGOutIsuvCGOutIs u v says that vv is the concatenation of the children's representations read off the graph uu (CGPathCGPath); a string determines at most one such vv.

    Community review

    Discussion

    Ask a question or add context. Endorsements and structured flags are kept in the review panel above; your ORCID profile must share a public name.

    0 comments

    Loading discussion…