Langlib

Langlib.Grammars.LeftRegular.Equivalence.LGEquivRG

Equivalence of Left-Regular and Right-Regular Grammars #

This file proves that the class of languages generated by left-regular grammars coincides with the class of languages generated by right-regular grammars, i.e., both define exactly the regular languages.

Proof strategy #

The key observation is that reversing the output of each rule converts a left-regular grammar into a right-regular grammar (and vice versa), and a derivation step in one corresponds to a derivation step on the reversed sentential form in the other.

Concretely, if g is a left-regular grammar, we construct a right-regular grammar RG_of_LG g such that LG_language g = (RG_language (RG_of_LG g)).reverse. Since the class of right-regular languages is closed under reversal (via Mathlib's Language.isRegular_reverse_iff and is_RG_iff_isRegular), this gives is_LG L → is_RG L. The converse direction is symmetric.

Main results #

References #

def RG_rule_of_LG_rule {T N : Type} :
LG_rule T NRG_rule T N

Convert a left-regular rule to a right-regular rule by reversing the output.

  • A → Ba becomes A → aB
  • A → a stays A → a
  • A → ε stays A → ε
Equations
Instances For
    def LG_rule_of_RG_rule {T N : Type} :
    RG_rule T NLG_rule T N

    Convert a right-regular rule to a left-regular rule by reversing the output.

    • A → aB becomes A → Ba
    • A → a stays A → a
    • A → ε stays A → ε
    Equations
    Instances For
      def RG_of_LG {T : Type} (g : LG_grammar T) :

      Convert a left-regular grammar to a right-regular grammar.

      Equations
      Instances For
        def LG_of_RG {T : Type} (g : RG_grammar T) :

        Convert a right-regular grammar to a left-regular grammar.

        Equations
        Instances For
          theorem RG_transforms_reverse_of_LG_transforms {T : Type} {g : LG_grammar T} {w₁ w₂ : List (symbol T g.nt)} (h : LG_transforms g w₁ w₂) :

          An LG transformation step corresponds to an RG transformation step on the reversed sentential form.

          theorem LG_transforms_of_RG_transforms_reverse {T : Type} {g : LG_grammar T} {w₁ w₂ : List (symbol T g.nt)} (h : RG_transforms (RG_of_LG g) w₁ w₂) :

          An RG transformation step on RG_of_LG g corresponds to an LG transformation step on the reversed sentential form.

          theorem RG_derives_reverse_of_LG_derives {T : Type} {g : LG_grammar T} {w₁ w₂ : List (symbol T g.nt)} (h : LG_derives g w₁ w₂) :

          LG derivation corresponds to RG derivation on reversed sentential forms.

          theorem LG_derives_of_RG_derives_reverse {T : Type} {g : LG_grammar T} {w₁ w₂ : List (symbol T g.nt)} (h : RG_derives (RG_of_LG g) w₁ w₂) :

          RG derivation on RG_of_LG g corresponds to LG derivation on reversed sentential forms.

          theorem LG_transforms_reverse_of_RG_transforms {T : Type} {g : RG_grammar T} {w₁ w₂ : List (symbol T g.nt)} (h : RG_transforms g w₁ w₂) :

          An RG transformation step corresponds to an LG transformation step on the reversed sentential form.

          theorem RG_transforms_of_LG_transforms_reverse {T : Type} {g : RG_grammar T} {w₁ w₂ : List (symbol T g.nt)} (h : LG_transforms (LG_of_RG g) w₁ w₂) :
          theorem LG_derives_reverse_of_RG_derives {T : Type} {g : RG_grammar T} {w₁ w₂ : List (symbol T g.nt)} (h : RG_derives g w₁ w₂) :
          theorem RG_derives_of_LG_derives_reverse {T : Type} {g : RG_grammar T} {w₁ w₂ : List (symbol T g.nt)} (h : LG_derives (LG_of_RG g) w₁ w₂) :
          theorem is_RG_of_is_LG {T : Type} [Fintype T] {L : Language T} (h : is_LG L) :

          Every left-regular language is right-regular.

          theorem is_LG_of_is_RG {T : Type} [Fintype T] {L : Language T} (h : is_RG L) :

          Every right-regular language is left-regular.

          theorem is_LG_iff_is_RG {T : Type} [Fintype T] {L : Language T} :

          A language is left-regular if and only if it is right-regular.

          theorem LG_eq_RG {T : Type} [Fintype T] :

          The class of left-regular languages equals the class of right-regular languages.