Documentation

Linglib.Core.Computability.NonRegular.AnBn

{ aⁿ bⁿ | n ≥ 0 }: a two-symbol non-regular witness language #

The classical two-symbol witness language showing that the regular languages are a proper subclass of the context-free languages: aⁿbⁿ is context-free (trivially) but not regular. The non-regularity proof is the textbook Myhill–Nerode argument: distinct prefixes aⁿ give distinct left quotients of { aⁿ bⁿ }, so Set.range balancedAB.leftQuotient is infinite, contradicting Language.IsRegular.finite_range_leftQuotient.

Sibling of Linglib/Core/Computability/NonContextFree/{AnBnCn, AnBnCnDn, AmBnCmDn}.lean (those use the CFL pumping lemma to escape the context-free hierarchy; this one uses Myhill–Nerode to escape the regular hierarchy). Independent of those files — uses its own AB alphabet rather than the ThreeSymbol/FourSymbol alphabets there.

Main definitions #

Main results #

Mathlib placement #

Promotable to Mathlib.Computability.NonRegular.AnBn as a sibling of the existing Mathlib.Computability.MyhillNerode machinery. The proof uses only mathlib primitives (Language.IsRegular.finite_range_leftQuotient, Set.infinite_of_injective_forall_mem, List.count_replicate, List.count_append).

inductive AB :

The two-symbol alphabet {a, b}.

Instances For
    @[implicit_reducible]
    instance instDecidableEqAB :
    DecidableEq AB
    Equations
    @[implicit_reducible]
    instance instReprAB :
    Repr AB
    Equations
    def instReprAB.repr :
    ABStd.Format
    Equations
    • instReprAB.repr AB.a prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ 1024 then 1 else 2) (Std.Format.text "AB.a")).group prec✝
    • instReprAB.repr AB.b prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ 1024 then 1 else 2) (Std.Format.text "AB.b")).group prec✝
    Instances For
      @[implicit_reducible]
      instance instFintypeAB :
      Fintype AB

      AB has exactly two inhabitants.

      Equations
      def IsBalanced (w : List AB) :

      A word over AB is balanced iff it consists of n copies of a followed by n copies of b, where n = w.length / 2. The total length of any balanced word is 2 n, so n is recoverable from the length and the equation is decidable via list equality.

      Equations
      • IsBalanced w = (w = List.replicate (w.length / 2) AB.a ++ List.replicate (w.length / 2) AB.b)
      Instances For
        @[implicit_reducible]
        Equations
        def balancedAB :
        Language AB

        The classical non-regular language { aⁿ bⁿ | n ≥ 0 }, packaged as a Language AB.

        Equations
        Instances For
          @[simp]
          theorem mem_balancedAB (w : List AB) :
          theorem replicate_a_append_replicate_b_isBalanced (n : ) :
          IsBalanced (List.replicate n AB.a ++ List.replicate n AB.b)

          The witness side: aⁿ ++ bⁿ is balanced. The forward direction of the language description, packaged for use in the Myhill–Nerode distinguishing-prefix argument.

          theorem replicate_a_append_replicate_b_not_isBalanced {m n : } (hmn : m n) :
          ¬IsBalanced (List.replicate m AB.a ++ List.replicate n AB.b)

          The anti-witness side: aᵐ ++ bⁿ with m ≠ n is not balanced. The proof counts as and bs on both sides of the supposed balanced decomposition.

          theorem leftQuotient_replicate_a_injective :
          Function.Injective fun (n : ) => balancedAB.leftQuotient (List.replicate n AB.a)

          The Myhill–Nerode separation: for m ≠ n, the test word bⁿ is in leftQuotient balancedAB (replicate n a) but not in leftQuotient balancedAB (replicate m a). Hence the two left quotients differ, and the map n ↦ balancedAB.leftQuotient (replicate n a) is injective.

          { aⁿ bⁿ } is not regular. Classical Myhill–Nerode argument: the left quotients by aⁿ for distinct n are all distinct, so Set.range balancedAB.leftQuotient is infinite, contradicting Language.IsRegular.finite_range_leftQuotient.