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 #
FinDFA α σ- A DFA with alphabetαand state spaceσ. This is likeDFA α σ, but with the accepting states given as aFinset σrather than aSet σ.FinDFA.getWordsLeqLength (n : ℕ)- Returns aFinsetof all words of length less than or equal tonover the alphabet of theFinDFA.FinDFA.IsAccessibleState- A predicate on states, true if the state is reachable from the start state by some word.FinDFA.isAccessibleStateDecidable- A decidability instance forFinDFA.IsAccessibleState.AccessibleFinDFA- A structure extendingFinDFAwith a proof that every state is accessible.FinDFA.toAccessible- A function that converts aFinDFAto anAccessibleFinDFA.
Main theorems #
FinDFA.getWordsLeqLength_correct-w ∈ M.getWordsLeqLength n ↔ w.length ≤ n.FinDFA.exists_short_access_word- In order to constructAccessibleFinDFAs fromFinDFAs, we need to define a decidability instance onFinDFA.isAccessibleState. As written, this involves searching the infinite space of all words. However, we prove inFinDFA.exists_short_access_wordthat, if a state is accessible by any word, then it is accessible by some word of length at most the number of states in theFinDFA. This allows us to search through a finite space of words using ourFinDFA.getWordsLeqLengthfunction.FinDFA.toAccessible_pres_lang- The language of aFinDFAis the same as the language of theAccessibleFinDFAobtained by applyingFinDFA.toAccessible.
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 #
One DEF entry for Mathlib's
DFALabel : dfa Lean definitions to tag : None Content : Explain that this is Mathlib's DFA defintitoin. Explain thatDFA α σhas fieldsstep,start,accept, and methodseval,evalFrom,accepts. Explain the types of these. Explain that this definition does not require the state space or alphabet to be finite or decidable. (explain what decidable equality is) Dependencies : NoneOne DEF entry for
FinDFALabel : fin-dfa lean defs :FinDFAContent : Explain the definition of theFinDFAstructure, and how it differes fromDFAby requiringFintypeandDecidableEqinstances on the alphabet and state space (explain what those classes are) and by requiring the accepting states to be aFinsetrather than aSet(explain the differnece) Explain how this allows a decidable procedure (what is that?) for determining if a state is accepting. Explain how this can be converted to aDFAin lean and how we use theDFAdefinitions for .evalFrom, .accepts, etc. Dependencies : None
One DEF entry for Accessible State and DFA definition label : accessable-fin-dfa lean defs :
FinDFA.IsAccessibleStateAccessibleFinDFAContent : Explain the definition of accessible states and theAccessibleFinDFAstructure. Dependencies : fin-dfa
One lemma entry for
FinDFA.exists_short_access_wordLabel : exists-short-access-word Lean lemmas to tag :FinDFA.exists_short_access_wordFinDFA.isAccessibleStateDecidableFinDFA.toAccessibleFinDFA.toAccessible_pres_langContent : Prove it and explain why this means that every word that is accessible is accessible by a short word. Explain how this is used to create a DECIDABLE procedure for determining if a state is accessible. Explain how that allows for a language-preserving conversion fromFinDFAtoAccessibleFinDFAby restricting the state space. Dependencies : accessible-fin-dfa
Given a word, the finset of all one-letter (preprended) extensions.
Equations
Instances For
Equations
- FinDFA.instCoeDFA = { coe := FinDFA.toDFA }
Return all words of length n in the alphabet.
Equations
- M.getWordsOfLength 0 = {[]}
- M.getWordsOfLength n_2.succ = (M.getWordsOfLength n_2).biUnion List.getNextWords
Instances For
Return all words of length at most n.
Equations
- M.getWordsLeqLength 0 = M.getWordsOfLength 0
- M.getWordsLeqLength n_2.succ = M.getWordsOfLength (n_2 + 1) ∪ M.getWordsLeqLength n_2
Instances For
Accessible States #
The finset of all accessible states.
Equations
- M.getAccessibleStates = (M.getWordsLeqLength (Fintype.card σ)).biUnion fun (s : List α) => {M.toDFA.evalFrom M.start s}
Instances For
Characterization of accessible states.
Decidability of state accessibility.
Equations
Accessible DFAs #
Convert an AccessibleFinDFA to a FinDFA.
Instances For
Convert an AccessibleFinDFA to a DFA.
Instances For
Coercion from AccessibleFinDFA to FinDFA.
Equations
Coercion from AccessibleFinDFA to DFA.
Equations
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.
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
Evaluating toAccessible from an accessible state matches the original evaluation.
Evaluating toAccessible from the start matches the original evaluation.
The language accepted by toAccessible equals the language accepted by the original DFA.