Langlib

Langlib.Classes.ContextFree.Closure.Quotient

Context-Free Right Quotients #

This file proves the sharp closure behavior for right quotients of context-free languages:

Regular Quotient Strategy #

For the positive theorem, we use an abstract, closure-property-based proof. The key idea is to "tag" each letter with whether it belongs to the kept prefix (Sum.inl) or the removed suffix (Sum.inr), then intersect with a regular "block" language that enforces the structure and R-membership, and finally erase the suffix tags via substitution.

Concretely, given a CFL L over T and a regular language R over T:

  1. Tag substitution σ : T → Language (T ⊕ T) maps each letter a to {[inl a], [inr a]}. Since each σ(a) is CF, L.subst σ is CF (by CF_of_subst_CF).

  2. Block language blockLang R over T ⊕ T consists of words of the form u.map inl ++ v.map inr where v ∈ R. This is regular (we construct a DFA).

  3. Intersection: L.subst σ ⊓ blockLang R is CF (CF ∩ Regular = CF).

  4. Erasure η : (T ⊕ T) → Language T keeps inl-tagged letters and erases inr-tagged ones. Since each η(x) is CF, (L.subst σ ⊓ blockLang R).subst η is CF.

  5. Correctness: (L.subst σ ⊓ blockLang R).subst η = L / R.

CFL Quotient Counterexample #

For the negative theorem, the witness is quotientNumerator / quotientDenominator, where

with false = a and true = b. Both languages are CFLs. Their quotient has unary regular slice exactly {a^(2^(k+1)) | k ∈ ℕ}, which is not CFL by the pumping lemma.

Main declarations #

def blockLang {T : Type} (R : Language T) :

The "block language" over the tagged alphabet T ⊕ T. A word belongs to blockLang R iff it has the form u.map Sum.inl ++ v.map Sum.inr with v ∈ R.

Equations
Instances For
    def blockLangDFA {T : Type} {σ : Type u_1} (D : DFA T σ) :
    DFA (T T) (Option (Bool × σ))

    Given a DFA D for R, build a DFA over T ⊕ T that recognises blockLang (D.accepts).

    States: Option (Bool × σ) where

    • some (false, q) = phase 1 (reading inl-tagged letters), DFA state q
    • some (true, q) = phase 2 (reading inr-tagged letters), DFA state q
    • none = dead (saw inl after inr)
    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      theorem blockLangDFA_accepts {T : Type} {σ : Type u_1} (D : DFA T σ) :
      def tagSubst {T : Type} :
      TLanguage (T T)

      Tag substitution: each letter a can be tagged as either inl a or inr a.

      Equations
      Instances For
        def eraseInr {T : Type} :
        T TLanguage T

        Erasure substitution: keep inl-tagged letters, erase inr-tagged ones.

        Equations
        Instances For
          theorem is_CF_tagSubst {T : Type} (a : T) :

          Each tagSubst a is a two-element language, hence context-free.

          theorem is_CF_eraseInr {T : Type} (x : T T) :

          Each eraseInr x is a singleton language, hence context-free.

          theorem is_CF_rightQuotient_regular {T : Type} {L R : Language T} (hL : is_CF L) (hR : R.IsRegular) :
          is_CF (L / R)

          Context-free languages are closed under right quotient with regular languages (is_CF formulation).

          Context-free languages are closed under right quotient with regular languages (Mathlib-style Language.IsContextFree formulation).

          theorem is_CF_prefixLang' {T : Type} {L : Language T} (hL : is_CF L) :

          prefixLang as a special case: if L is CF, then prefixLang L is CF.

          The class of context-free languages is closed under right quotient with regular languages.

          Standard CFL/CFL quotient witnesses #

          The eventual counterexample uses ({a^(2n)b^n | n ∈ ℕ})* / (({b^n a^n | n ∈ ℕ})* {b}). The unary slice of this quotient is unaryPow2.

          Flattened concatenation of positive left-block sizes.

          Equations
          Instances For

            Flattened concatenation of positive right-block sizes.

            Equations
            Instances For

              Denominator blocks for the explicit suffix witnessing a^(2^(k+1)) ∈ quotientNumerator / quotientDenominator.

              Equations
              Instances For

                The suffix b^(2^k)a^(2^k) ... b²a² b used for the forward slice inclusion.

                Equations
                Instances For

                  The regular unary language a*, with false = a.

                  Equations
                  Instances For

                    Since the quotient's unary regular slice is unaryPow2, the quotient cannot be CFL.

                    CFLs are not closed under right quotient by CFLs.