Langlib

Langlib.Grammars.Indexed.NormalForm.Binarization

Binarization for Indexed Grammars #

This file constructs a binarization transformation for indexed grammars. Given an indexed grammar with no ε-productions, isolated terminals, separated flags, and a fresh start symbol, it produces an equivalent grammar in normal form.

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

Lift an RHS symbol to the binarized grammar's nonterminal type.

Equations
Instances For
    noncomputable def IndexedGrammar.binarizeChain {T : Type} (g : IndexedGrammar T) (i : ) (lhs : g.nt × ) (syms : List (IRhsSymbol T (g.nt × ) (Option g.flag))) (idx : ) :

    The auxiliary binarization function.

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

      Binarize a single rule at index i.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        noncomputable def IndexedGrammar.binarize {T : Type} (g : IndexedGrammar T) :

        The binarized grammar.

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

          Classification of rules under hypotheses #

          Helper lemmas for IsNormalForm #

          Helper lemmas for generates_iff #

          Backward direction: g.binarize generates w → g generates w #

          Strip none values from a flag stack, recovering a stack for the original grammar.

          Equations
          Instances For
            noncomputable def IndexedGrammar.unbinarizeSym {T : Type} (g : IndexedGrammar T) :

            Unbinarize a single sentential-form symbol. Maps:

            • terminal t to [terminal t]
            • indexed (Sum.inl n) σ to [indexed n (stripStack σ)]
            • indexed (Sum.inr (i, j)) σ to the remaining nonterminals of the i-th rule from position j+1 onward, each with stack stripStack σ.
            Equations
            Instances For
              noncomputable def IndexedGrammar.unbinarizeSF {T : Type} (g : IndexedGrammar T) (w : List g.binarize.ISym) :

              Unbinarize a sentential form by flatMapping each symbol.

              Equations
              Instances For

                Main theorems #

                theorem IndexedGrammar.binarize_generates_iff {T : Type} (g : IndexedGrammar T) (hne : g.NoEpsilon') (hti : g.TerminalsIsolated) (hfs : g.FlagsSeparated) (hfresh : g.StartNotOnRhs') (w : List T) :
                theorem IndexedGrammar.exists_normalForm_from_separated {T : Type} (g : IndexedGrammar T) (hne : g.NoEpsilon') (hti : g.TerminalsIsolated) (hfs : g.FlagsSeparated) (hfresh : g.StartNotOnRhs') :
                ∃ (g' : IndexedGrammar T), (∃ (x : DecidableEq g'.nt), g'.IsNormalForm) ∀ (w : List T), g'.Generates w g.Generates w
                theorem IndexedGrammar.exists_normalForm_from_separated' {T : Type} (g : IndexedGrammar T) (hne : g.NoEpsilon') (hti : g.TerminalsIsolated) (hfs : g.FlagsSeparated) (hfresh : g.StartNotOnRhs') :
                ∃ (g' : IndexedGrammar T), (∃ (x : DecidableEq g'.nt), g'.IsNormalForm) ∀ (w : List T), w [] → (g'.Generates w g.Generates w)