Documentation

Cslib.Computability.Languages.MyhillNerode

Myhill-Nerode Theorem #

Let l be a language on an alphabet α. The Nerode congruence (referred to as c_l in comments below) of a language l is a right congruence on strings where two strings are related iff all their right extensions are either both in the language or both not in it.

The Myhill-Nerode theorem has three parts [Wik26]:

(1) l is regular iff c_l has a finite number N of equivalence classes.

(2) N is the number of states of the minimal DFA accepting l.

(3) The minimal DFA is unique up to unique isomorphism. That is, for any minimal DFA accepting l, there exists exactly an isomorphism from it to the canonical DFA whose states are the equivalence classses of c_l, whose state transitions are of the form ⟦ x ⟧ → ⟦ x ++ [a] ⟧ (where a : α and x : List α), whose initial state is ⟦ [] ⟧, and whose accepting states are { ⟦ x ⟧ | x ∈ l }.

References #

@[implicit_reducible]

The Nerode congruence (henceforth called c_l) of a language l is a right congruence on strings where two strings are related iff all their right extensions are either both in the language or both not in it.

Equations
Instances For
    @[reducible, inline]
    abbrev Language.NerodeQuotient {α : Type} (l : Language α) :

    The quotient type of a Nerode congruence.

    Equations
    Instances For

      The Nerode congruence of a language l gives rise to a DFA where each state corresponds to an equivalence class of the language under the Nerode congruence. Note that this is simply the DFA given rise to by the underlying right congruence with only the accept states specified here as {⟦ x ⟧ | x ∈ l}.

      Equations
      Instances For
        @[simp]

        The DFA constructed from the Nerode congruence c_l on l accepts l.

        theorem Language.da_nerodeCongruence_iff {α : Type} {State : Type u_1} (M : Cslib.Automata.DA.FinAcc State α) (x y : List α) :

        The statement (two strings are related by the Nerode congruence c_l on l iff all their right extensions are either both in the language or both not in it) is equivalent to stating that (all their right extensions are either both accepted or rejected by the DFA given rise to by c_l.)

        If l is regular then the Nerode congruence on l has finitely many equivalence classes.

        l is regular iff the Nerode congruence on l has finitely many equivalence classes.

        theorem Language.dfa_num_state_ge {α : Type} {l : Language α} {ws : Set (List α)} [Finite ws] (hws : ws.Pairwise fun (x1 x2 : List α) => ¬l.NerodeCongruence.eq x1 x2) {State : Type u_1} [Finite State] {M : Cslib.Automata.DA.FinAcc State α} (hm : Cslib.Automata.Acceptor.language M = l) :
        Nat.card State Nat.card ws

        Given a set of strings all distinguishable by l (i.e., not related to each other by the Nerode congruence on l), the number of states in the DFA accepting l is at least the number of strings in the set.

        All DFAs accepting l must have at least as many states as the number of equivalence classes of the Nerode congruence on l.

        def Cslib.Automata.DA.FinAcc.IsMinimalAutomaton {α : Type} {State : Type u_1} (M : FinAcc State α) (l : Language α) :

        The minimal DFA accepting l has the same number of states as the number of equivalence classes of the Nerode congruence on l.

        Equations
        Instances For
          @[implicit_reducible]
          def Cslib.Automata.DA.FinAcc.StateCongruence {α : Type} {State : Type u_1} (M : FinAcc State α) :

          Given a DFA M, two strings are related iff they reach the same state under when run through M. The Nerode congruence is the state congruence with respect to the minimal DFA accepting l.

          Equations
          Instances For

            The Nerode congruence is the most coarse state congruence given a language.

            theorem Cslib.Automata.DA.FinAcc.unique_minimal {State : Type u_1} {α : Type} {M : FinAcc State α} [Finite State] (l : Language α) (hr : l.IsRegular) (hm : M.IsMinimalAutomaton l) :
            ∃! φ : State l.NerodeQuotient, ∀ (x : List α), φ (M.mtr M.start x) = x

            The minimal DFA M accepting the language l is unique up to unique isomorphism.