Documentation

MyProject.Defs

FinDFA: Computable DFAs #

This file defines structures FinDFA and AccessibleFinDFA, and a function FinDFA.toAccessible that converts a FinDFA to an AccessibleFinDFA. This function is proven to preserve the language accepted by FinDFA.toAccessible_pres_lang.

Main definitions #

Main theorems #

Implementation notes #

We provide coercions from FinDFA and AccessibleFinDFA to DFA. This means that when you have M : FinDFA α σ or M : AccessibleFinDFA α σ, you can use functions defined on DFA α σ such as eval, evalFrom, and accepts by writing (M : DFA α σ).eval or M.toDFA.eval.

Note that, just like DFA, the definitions of FinDFA and AccessibleFinDFA do not require the state space or alphabet to be finite or to have decidable equality.

Blueprint #

@[reducible, inline]
abbrev List.prependInjection {α : Type u_1} (w : List α) :
α List α

Given a word, the injection sending each letter to its prepending to that word.

Equations
Instances For
    @[reducible, inline]
    abbrev List.getNextWords {α : Type u_1} [Fintype α] (w : List α) :

    Given a word, the finset of all one-letter (preprended) extensions.

    Equations
    Instances For
      structure FinDFA (α : Type u) (σ : Type v) :
      Type (max u v)

      A computable DFA. Just like DFA but accept is a Finset

      • step : σασ

        Transition function.

      • start : σ

        Start state.

      • accept : Finset σ

        Accepting states as a Finset.

      Instances For
        def FinDFA.toDFA {α : Type u} {σ : Type v} (M : FinDFA α σ) :
        DFA α σ

        Convert a FinDFA to a DFA.

        Equations
        Instances For
          instance FinDFA.instCoeDFA {α : Type u} {σ : Type v} :
          Coe (FinDFA α σ) (DFA α σ)

          Coercion from FinDFA to DFA.

          Equations
          @[simp]
          theorem FinDFA.coe_start {α : Type u} {σ : Type v} (M : FinDFA α σ) :
          @[simp]
          theorem FinDFA.coe_step {α : Type u} {σ : Type v} (M : FinDFA α σ) :
          @[simp]
          theorem FinDFA.coe_accept {α : Type u} {σ : Type v} (M : FinDFA α σ) :
          def FinDFA.getWordsOfLength {α : Type u} {σ : Type v} [Fintype α] [DecidableEq α] (M : FinDFA α σ) (n : ) :

          Return all words of length n in the alphabet.

          Equations
          Instances For
            @[simp]
            theorem FinDFA.getWordsOfLength_correct {α : Type u} {σ : Type v} [Fintype α] [DecidableEq α] (M : FinDFA α σ) (n : ) (w : List α) :
            def FinDFA.getWordsLeqLength {α : Type u} {σ : Type v} [Fintype α] [DecidableEq α] (M : FinDFA α σ) (n : ) :

            Return all words of length at most n.

            Equations
            Instances For
              @[simp]
              theorem FinDFA.getWordsLeqLength_correct {α : Type u} {σ : Type v} [Fintype α] [DecidableEq α] (M : FinDFA α σ) {n : } {w : List α} :

              Accessible States #

              @[reducible, inline]
              abbrev FinDFA.IsAccessibleState {α : Type u} {σ : Type v} (M : FinDFA α σ) (s : σ) :

              A state is accessible if there exists some word that reaches it from the start state.

              Equations
              Instances For
                theorem FinDFA.exists_short_access_word {α : Type u} {σ : Type v} [Fintype σ] (M : FinDFA α σ) (s : σ) {w : List α} (hw : M.toDFA.evalFrom M.start w = s) :
                ∃ (v : List α), v.length Fintype.card σ s = M.toDFA.evalFrom M.start v

                Every accessible state is reachable by a word of length at most the number of states.

                def FinDFA.getAccessibleStates {α : Type u} {σ : Type v} [Fintype α] [DecidableEq α] [Fintype σ] [DecidableEq σ] (M : FinDFA α σ) :

                The finset of all accessible states.

                Equations
                Instances For
                  @[simp]
                  theorem FinDFA.getAccessibleStates_correct {α : Type u} {σ : Type v} [Fintype α] [DecidableEq α] [Fintype σ] [DecidableEq σ] (M : FinDFA α σ) (s : σ) :

                  Characterization of accessible states.

                  Decidability of state accessibility.

                  Equations

                  Accessible DFAs #

                  structure AccessibleFinDFA (α : Type u) (σ : Type v) extends FinDFA α σ :
                  Type (max u v)

                  A DFA where every state is accessible from the start state.

                  Instances For
                    def AccessibleFinDFA.toFinDFA {α : Type u} {σ : Type v} (M : AccessibleFinDFA α σ) :
                    FinDFA α σ

                    Convert an AccessibleFinDFA to a FinDFA.

                    Equations
                    Instances For
                      def AccessibleFinDFA.toDFA {α : Type u} {σ : Type v} (M : AccessibleFinDFA α σ) :
                      DFA α σ

                      Convert an AccessibleFinDFA to a DFA.

                      Equations
                      Instances For
                        @[simp]
                        theorem AccessibleFinDFA.coe_start' {α : Type u} {σ : Type v} (M : AccessibleFinDFA α σ) :
                        @[simp]
                        theorem AccessibleFinDFA.coe_step' {α : Type u} {σ : Type v} (M : AccessibleFinDFA α σ) :
                        @[simp]
                        theorem AccessibleFinDFA.coe_accept' {α : Type u} {σ : Type v} (M : AccessibleFinDFA α σ) :
                        @[simp]
                        theorem AccessibleFinDFA.coe_start {α : Type u} {σ : Type v} (M : AccessibleFinDFA α σ) :
                        @[simp]
                        theorem AccessibleFinDFA.coe_step {α : Type u} {σ : Type v} (M : AccessibleFinDFA α σ) :
                        @[simp]
                        theorem AccessibleFinDFA.coe_accept {α : Type u} {σ : Type v} (M : AccessibleFinDFA α σ) :

                        FinDFA → AccessibleFinDFA #

                        By restricting the state space to only the accessible states, we can convert any FinDFA to an AccessibleFinDFA. We prove that this conversion preserves the language accepted by the DFA.

                        def FinDFA.toAccessible {α : Type u} {σ : Type v} [Fintype α] [DecidableEq α] [Fintype σ] [DecidableEq σ] (M : FinDFA α σ) :

                        Convert a FinDFA to an AccessibleFinDFA by restricting to accessible states.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          @[simp]
                          theorem FinDFA.toAccessible_step_val {α : Type u} {σ : Type v} [Fintype α] [DecidableEq α] [Fintype σ] [DecidableEq σ] (M : FinDFA α σ) (s : { s : σ // M.IsAccessibleState s }) (a : α) :
                          (M.toAccessible.step s a) = M.step (↑s) a
                          theorem FinDFA.toAccessible_evalFrom_val {α : Type u} {σ : Type v} [Fintype α] [DecidableEq α] [Fintype σ] [DecidableEq σ] (M : FinDFA α σ) (s : { s : σ // M.IsAccessibleState s }) (w : List α) :
                          (M.toAccessible.toDFA.evalFrom s w) = M.toDFA.evalFrom (↑s) w

                          Evaluating toAccessible from an accessible state matches the original evaluation.

                          theorem FinDFA.toAccessible_eval_val {α : Type u} {σ : Type v} [Fintype α] [DecidableEq α] [Fintype σ] [DecidableEq σ] (M : FinDFA α σ) (w : List α) :

                          Evaluating toAccessible from the start matches the original evaluation.

                          The language accepted by toAccessible equals the language accepted by the original DFA.