Langlib

Langlib.Grammars.Indexed.NormalForm.FlagSeparation

Flag Separation for Indexed Grammars #

This file constructs a flag-separation transformation for indexed grammars.

This is Step 4 of Aho's Normal Form theorem.

Does this RHS symbol have a flag push?

Equations
Instances For

    Lift an RHS symbol to the new nonterminal type, keeping flags.

    Equations
    Instances For
      def IndexedGrammar.fsReplaceRhsSym {T : Type} (g : IndexedGrammar T) (ruleIdx posIdx : ) :

      Replace a pushed nonterminal with a fresh intermediate (no push).

      Equations
      Instances For

        Strip flag push from an RHS symbol in the lifted type.

        Equations
        Instances For
          def IndexedGrammar.fsSingleRule {T : Type} (g : IndexedGrammar T) (i : ) (r : IRule T g.nt g.flag) :

          Transform a single rule at index i into flag-separated rules.

          Note: The consume check is done first (before the terminal check) to ensure that rules with consume = some and terminal RHS are properly separated. This is required for flagSeparate_flagsSeparated to hold.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For

            The flag-separated grammar.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For

              Properties #

              theorem IndexedGrammar.fsSingleRule_rhs_ne_nil {T : Type} (g : IndexedGrammar T) (i : ) (r : IRule T g.nt g.flag) (hr : r.rhs []) (r' : IRule T (g.nt × ) g.flag) (hr' : r' g.fsSingleRule i r) :
              theorem IndexedGrammar.fsReplaceRhsSym_map_all_nt {T : Type} (g : IndexedGrammar T) (ri : ) (l : List (IRhsSymbol T g.nt g.flag)) (h : sl, ∃ (n : g.nt) (f : Option g.flag), s = IRhsSymbol.nonterminal n f) (s : IRhsSymbol T (g.nt × ) g.flag) :
              s List.map (fun (x : IRhsSymbol T g.nt g.flag × ) => match x with | (s, j) => g.fsReplaceRhsSym ri j s) l.zipIdx∃ (n : g.nt × ) (f : Option g.flag), s = IRhsSymbol.nonterminal n f
              theorem IndexedGrammar.fsLiftRhsSym_map_all_nt {T : Type} (g : IndexedGrammar T) (l : List (IRhsSymbol T g.nt g.flag)) (h : sl, ∃ (n : g.nt) (f : Option g.flag), s = IRhsSymbol.nonterminal n f) (s : IRhsSymbol T (g.nt × ) g.flag) :
              s List.map g.fsLiftRhsSym l∃ (n : g.nt × ) (f : Option g.flag), s = IRhsSymbol.nonterminal n f
              theorem IndexedGrammar.fsStripPushRhsSym_map_all_nt {T : Type} (g : IndexedGrammar T) (l : List (IRhsSymbol T g.nt g.flag)) (h : sl, ∃ (n : g.nt) (f : Option g.flag), s = IRhsSymbol.nonterminal n f) (s : IRhsSymbol T (g.nt × ) g.flag) :
              theorem IndexedGrammar.hti_all_nt_of_not_terminal_cond {T : Type} (g : IndexedGrammar T) (r : IRule T g.nt g.flag) (hti : (∃ (a : T), r.rhs = [IRhsSymbol.terminal a]) sr.rhs, ∃ (n : g.nt) (f : Option g.flag), s = IRhsSymbol.nonterminal n f) (h : ¬((r.rhs.any fun (s : IRhsSymbol T g.nt g.flag) => match s with | IRhsSymbol.terminal a => true | x => false) && r.rhs.length == 1) = true) (s : IRhsSymbol T g.nt g.flag) :
              s r.rhs∃ (n : g.nt) (f : Option g.flag), s = IRhsSymbol.nonterminal n f
              theorem IndexedGrammar.fsSingleRule_terminalsIsolated {T : Type} (g : IndexedGrammar T) (i : ) (r : IRule T g.nt g.flag) (hti : (∃ (a : T), r.rhs = [IRhsSymbol.terminal a]) sr.rhs, ∃ (n : g.nt) (f : Option g.flag), s = IRhsSymbol.nonterminal n f) (r' : IRule T (g.nt × ) g.flag) (hr' : r' g.fsSingleRule i r) :
              (∃ (a : T), r'.rhs = [IRhsSymbol.terminal a]) sr'.rhs, ∃ (n : g.nt × ) (f : Option g.flag), s = IRhsSymbol.nonterminal n f
              theorem IndexedGrammar.fsSingleRule_flagsSeparated {T : Type} (g : IndexedGrammar T) (i : ) (r : IRule T g.nt g.flag) (hti : (∃ (a : T), r.rhs = [IRhsSymbol.terminal a]) sr.rhs, ∃ (n : g.nt) (f : Option g.flag), s = IRhsSymbol.nonterminal n f) (r' : IRule T (g.nt × ) g.flag) (hr' : r' g.fsSingleRule i r) :
              theorem IndexedGrammar.fsSingleRule_startNotOnRhs {T : Type} (g : IndexedGrammar T) (i : ) (r : IRule T g.nt g.flag) (hfresh : sr.rhs, match s with | IRhsSymbol.nonterminal n a => n g.initial | IRhsSymbol.terminal a => True) (r' : IRule T (g.nt × ) g.flag) (hr' : r' g.fsSingleRule i r) (s : IRhsSymbol T (g.nt × ) g.flag) :
              s r'.rhsmatch s with | IRhsSymbol.nonterminal n a => n Sum.inl g.initial | IRhsSymbol.terminal a => True
              theorem IndexedGrammar.fsSingleRule_mem_flagSeparate {T : Type} (g : IndexedGrammar T) {r : IRule T g.nt g.flag} {i : } (hr : (r, i) g.rules.zipIdx) (r' : IRule T (g.nt × ) g.flag) (hr' : r' g.fsSingleRule i r) :
              theorem IndexedGrammar.resolveIntermediates {T : Type} (g : IndexedGrammar T) (rhs : List (IRhsSymbol T g.nt g.flag)) (i offset : ) (hri : ∀ (s : IRhsSymbol T g.nt g.flag) (j : ), (s, j) rhs.zipIdxg.hasPush s = true{ lhs := Sum.inr (i, j + offset), consume := none, rhs := [match s with | IRhsSymbol.nonterminal n (some f) => IRhsSymbol.nonterminal (Sum.inl n) (some f) | x => IRhsSymbol.nonterminal (Sum.inl g.initial) none] } g.flagSeparate.rules) (σ : List g.flag) :
              g.flagSeparate.Derives (g.flagSeparate.expandRhs (List.map (fun (x : IRhsSymbol T g.nt g.flag × ) => match x with | (s, j) => g.fsReplaceRhsSym i (j + offset) s) rhs.zipIdx) σ) (g.flagSeparate.expandRhs (List.map g.fsLiftRhsSym rhs) σ)

              When hasPush is false, fsStripPushRhsSym agrees with fsLiftRhsSym on the list.

              theorem IndexedGrammar.fsLift_rule_simulation {T : Type} (g : IndexedGrammar T) (r : IRule T g.nt g.flag) (i : ) (hri : (r, i) g.rules.zipIdx) (σ : List g.flag) :

              Simulation of a single rule: from the nonterminal with appropriate stack, flagSeparate can derive the lifted expansion.

              noncomputable def IndexedGrammar.fsUnsepIntermediate {T : Type} (g : IndexedGrammar T) (idx : × ) (σ : List g.flag) :
              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                noncomputable def IndexedGrammar.fsUnsepSF {T : Type} (g : IndexedGrammar T) (w : List g.flagSeparate.ISym) :
                Equations
                Instances For