Langlib

Langlib.Classes.ContextFree.Closure.InverseHomomorphism

Context-Free Closure Under Inverse String Homomorphism #

This file proves that context-free languages are closed under inverse string homomorphism. Given a CFL L over β and a string homomorphism h : α → List β, the preimage h⁻¹(L) = {w : List α | h(w) ∈ L} is also context-free.

Strategy #

We decompose h⁻¹(L) as π(D ∩ f⁻¹(L)) where the intermediate alphabet is Γ = α ⊕ β:

Then:

Main declarations #

def extendHom {α β : Type} (h : αList β) (w : List α) :
List β

Extend a homomorphism to words by concatenation.

Equations
Instances For
    def Language.inverseHomomorphicImage {α β : Type} (L : Language β) (h : αList β) :

    The preimage of a language L under a string homomorphism h. This is the set of words w over α such that h(w) ∈ L, where h extends to words by concatenation: h(a₁⋯aₙ) = h(a₁) ++ ⋯ ++ h(aₙ).

    Equations
    Instances For
      def embedWord {α β : Type} (h : αList β) (a : α) :
      List (α β)

      Embed a symbol a into Γ = α ⊕ β as [inl a] ++ (h a).map inr.

      Equations
      Instances For
        def fHom {α β : Type} :
        α βList β

        Project Γ to β: erase inl, unwrap inr.

        Equations
        Instances For
          def piHom {α β : Type} :
          α βList α

          Project Γ to α: keep inl, erase inr.

          Equations
          Instances For
            theorem embedWord_flatMap_fHom {α β : Type} (h : αList β) (a : α) :
            theorem extendHom_eq_flatMap_embedWord_fHom {α β : Type} (h : αList β) (w : List α) :
            theorem embedWord_flatMap_piHom {α β : Type} (h : αList β) (a : α) :
            theorem extendHom_embedWord_piHom {α β : Type} (h : αList β) (w : List α) :
            def sLang (α β : Type) :
            Language (α β)

            S = {[inl a] | a ∈ α}, the set of single-symbol inl words.

            Equations
            Instances For
              theorem is_CF_sLang {α β : Type} [Fintype α] :
              is_CF (sLang α β)
              def fInv {α β : Type} (L : Language β) :
              Language (α β)

              f⁻¹(L) = {v : List Γ | v.flatMap fHom ∈ L}.

              Equations
              Instances For
                def substFn (α β : Type) (b : β) :
                Language (α β)

                σ(b) = S* · {[inr b]}.

                Equations
                Instances For
                  theorem allInl_mem_kstar_sLang {α β : Type} (v : List (α β)) (hv : xv, x.isLeft = true) :
                  theorem flatMap_fHom_kstar_sLang {α β : Type} (v : List (α β)) (hv : v KStar.kstar (sLang α β)) :
                  theorem flatMap_fHom_substFn {α β : Type} (v : List (α β)) (b : β) (hv : v substFn α β b) :
                  theorem decompose_sum_list {α β : Type} (v : List (α β)) :
                  ∃ (bs : List β) (ss : List (List (α β))), ss.length = bs.length + 1 (∀ sss, xs, x.isLeft = true) v = (List.zipWith (fun (s : List (α β)) (b : β) => s ++ [Sum.inr b]) ss.dropLast bs).flatten ++ ss.getLast! List.flatMap fHom v = bs
                  theorem fInv_eq {α β : Type} (L : Language β) :
                  fInv L = L.subst (substFn α β) * KStar.kstar (sLang α β)
                  theorem is_CF_fInv {α β : Type} [Fintype α] (L : Language β) (hL : is_CF L) :

                  f⁻¹(L) is CFL when L is CFL and α is finite.

                  def dLang {α β : Type} (h : αList β) :
                  Language (α β)

                  D = (⋃_a {embedWord h a})*, the set of valid encodings.

                  Equations
                  Instances For
                    @[reducible, inline]
                    abbrev DFAState (α β : Type) (h : αList β) :

                    DFA state type for recognizing D.

                    • none: dead state
                    • some none: ready/accepting state (completed all blocks)
                    • some (some ⟨a, k⟩): currently processing h(a) at position k
                    Equations
                    Instances For
                      def dStep {α β : Type} (h : αList β) :
                      DFAState α β hα βDFAState α β h

                      DFA transition function for recognizing D.

                      Equations
                      Instances For
                        def invHomDFA {α β : Type} (h : αList β) :
                        DFA (α β) (DFAState α β h)

                        The DFA recognizing D.

                        Equations
                        Instances For
                          theorem dStep_embedWord {α β : Type} (h : αList β) (a : α) :
                          theorem foldl_dStep_none {α β : Type} (h : αList β) (v : List (α β)) :
                          theorem dfa_accepts_of_dLang {α β : Type} (h : αList β) (v : List (α β)) (hv : v dLang h) :
                          theorem dfa_mid_consume {α β : Type} (h : αList β) (a : α) (k : Fin (h a).length) (v : List (α β)) (hv : List.foldl (dStep h) (some (some a, k)) v = some none) :
                          ∃ (rest : List (α β)), v = List.map Sum.inr (List.drop (↑k) (h a)) ++ rest List.foldl (dStep h) (some none) rest = some none
                          theorem dLang_of_dfa_accepts {α β : Type} (h : αList β) (v : List (α β)) (hv : List.foldl (dStep h) (some none) v = some none) :
                          theorem invHomDFA_correct {α β : Type} (h : αList β) :

                          Correctness: the DFA accepts exactly D.

                          theorem isRegular_dLang {α β : Type} [Fintype α] (h : αList β) :

                          D is a regular language when α is finite.

                          theorem CF_closed_under_inverse_homomorphism {α β : Type} [Fintype α] (L : Language β) (h : αList β) (hL : is_CF L) :

                          The class of context-free languages is closed under inverse string homomorphism.

                          Given a context-free language L over alphabet β and a string homomorphism h : α → List β (with α a finite type), the preimage h⁻¹(L) = {w | h(w) ∈ L} is also context-free.

                          The class of context-free languages is closed under inverse string homomorphism.