Langlib

Langlib.Grammars.Indexed.NormalForm.Aho.Scheduler.ParseRoutes

Parse routes for Aho scheduling #

Structural parse measures and canonical routes to consumed stack occurrences.

def IndexedGrammar.NFParse.nodeCount {T : Type} {g : IndexedGrammar T} {A : g.nt} {stack : List g.flag} {w : List T} :
g.NFParse A stack w

Number of constructors in a concrete parse. The direct scheduler decreases the sum of these counts on every grammar-facing composite step.

Equations
Instances For
    @[simp]
    theorem IndexedGrammar.NFParse.nodeCount_pos {T : Type} {g : IndexedGrammar T} {A : g.nt} {stack : List g.flag} {w : List T} (p : g.NFParse A stack w) :
    theorem IndexedGrammar.NFParse.nodeCount_cast_stack {T : Type} {g : IndexedGrammar T} {A : g.nt} {stack stack' : List g.flag} {w : List T} (p : g.NFParse A stack w) (h : stack = stack') :

    Transporting only the stack index of a parse does not change its constructor count.

    theorem IndexedGrammar.NFParse.consumesAt_of_consumesAt_succ {T : Type} {g : IndexedGrammar T} {A : g.nt} {stack : List g.flag} {w : List T} (p : g.NFParse A stack w) (k : ) :
    p.ConsumesAt (k + 1)p.ConsumesAt k

    If a concrete parse consumes stack occurrence k + 1, it also consumes occurrence k. Operationally, a derivation cannot reach a deeper stack occurrence without first popping the one immediately above it.

    theorem IndexedGrammar.NFParse.consumesAt_mono {T : Type} {g : IndexedGrammar T} {A : g.nt} {stack : List g.flag} {w : List T} (p : g.NFParse A stack w) {i j : } (hij : i j) (hj : p.ConsumesAt j) :

    Consumption is downward closed in the stack-position order.

    theorem IndexedGrammar.NFParse.not_consumesAt_of_not_consumesAt_zero {T : Type} {g : IndexedGrammar T} {A : g.nt} {stack : List g.flag} {w : List T} (p : g.NFParse A stack w) (hzero : ¬p.ConsumesAt 0) (k : ) :

    If the top inherited occurrence is unused, every deeper inherited occurrence is unused too. This is the branch in which the scheduler may safely erase the inherited stack and run a plain task.

    theorem IndexedGrammar.NFParse.consumesAt_lt_stack_length {T : Type} {g : IndexedGrammar T} {A : g.nt} {stack : List g.flag} {w : List T} (p : g.NFParse A stack w) {k : } (hk : p.ConsumesAt k) :
    k < stack.length

    A parse can only consume an occurrence which is actually present in its inherited stack.

    theorem IndexedGrammar.NFParse.not_consumesAt_of_stack_nil {T : Type} {g : IndexedGrammar T} {A : g.nt} {w : List T} (p : g.NFParse A [] w) (k : ) :

    In particular, a task with empty inherited stack is necessarily plain.

    Chosen routes to consumed stack occurrences #

    inductive IndexedGrammar.NFParse.ConsumeRoute {T : Type} (g : IndexedGrammar T) {A : g.nt} {stack : List g.flag} {w : List T} :
    g.NFParse A stack wType

    A data-carrying choice of one branch leading to the pop which consumes stack occurrence k. Every binary node crossed by such a route contributes a nonempty off-path yield interval; those intervals are the owners of uncompressed index blocks.

    Instances For
      def IndexedGrammar.NFParse.ConsumeRoute.toConsumesAt {T : Type} {g : IndexedGrammar T} {A : g.nt} {stack : List g.flag} {w : List T} {p : g.NFParse A stack w} {k : } :
      ∀ (a : ConsumeRoute g p k), p.ConsumesAt k

      Forget the chosen route and recover the proposition-valued consumption fact.

      Equations
      • =
      Instances For
        theorem IndexedGrammar.NFParse.ConsumeRoute.nonempty_of_consumesAt {T : Type} {g : IndexedGrammar T} {A : g.nt} {stack : List g.flag} {w : List T} (p : g.NFParse A stack w) (k : ) (used : p.ConsumesAt k) :

        Every proposition-valued consumption fact admits a concrete route.

        theorem IndexedGrammar.NFParse.ConsumeRoute.nonempty_iff_consumesAt {T : Type} {g : IndexedGrammar T} {A : g.nt} {stack : List g.flag} {w : List T} (p : g.NFParse A stack w) (k : ) :

        Consumption and existence of a chosen route are equivalent.

        noncomputable def IndexedGrammar.NFParse.ConsumeRoute.ofConsumesAt {T : Type} {g : IndexedGrammar T} {A : g.nt} {stack : List g.flag} {w : List T} (p : g.NFParse A stack w) (k : ) (used : p.ConsumesAt k) :

        Choose a route from a known consumption fact.

        Equations
        Instances For

          Disjoint terminal owners along a consumption route #

          Embed a position in a left child yield into the concatenated parent yield.

          Equations
          Instances For

            Embed a position in a right child yield into the concatenated parent yield.

            Equations
            Instances For
              def IndexedGrammar.NFParse.ConsumeRoute.barrierOwners {T : Type} {g : IndexedGrammar T} {A : g.nt} {stack : List g.flag} {w : List T} {p : g.NFParse A stack w} {k : } :
              ConsumeRoute g p kList (Fin w.length)

              At a binary event, charge the fresh block to the first terminal position of the child not followed by the consumption route. Recursively chosen barriers lie inside the followed child, so all of these owners are distinct.

              Equations
              Instances For
                theorem IndexedGrammar.NFParse.ConsumeRoute.barrierOwners_nodup {T : Type} {g : IndexedGrammar T} {A : g.nt} {stack : List g.flag} {w : List T} {p : g.NFParse A stack w} {k : } (route : ConsumeRoute g p k) :

                Off-path owners selected at distinct binary events on one route are pairwise distinct.

                theorem IndexedGrammar.NFParse.ConsumeRoute.barrierOwners_length_le {T : Type} {g : IndexedGrammar T} {A : g.nt} {stack : List g.flag} {w : List T} {p : g.NFParse A stack w} {k : } (route : ConsumeRoute g p k) :

                Consequently the number of productive barriers on any one consumption route is bounded by the terminal yield length.

                def IndexedGrammar.NFParse.ConsumeRoute.NoBinary {T : Type} {g : IndexedGrammar T} {A : g.nt} {stack : List g.flag} {w : List T} {p : g.NFParse A stack w} {k : } :
                ConsumeRoute g p kProp

                A route has no productive barrier exactly when it reaches its pop using only unary push/pop constructors.

                Equations
                Instances For
                  @[simp]
                  theorem IndexedGrammar.NFParse.ConsumeRoute.noBinary_iff_barrierOwners_nil {T : Type} {g : IndexedGrammar T} {A : g.nt} {stack : List g.flag} {w : List T} {p : g.NFParse A stack w} {k : } (route : ConsumeRoute g p k) :