Nondeterministic Finite Automata #
A Nondeterministic Finite Automaton (NFA) is a state machine which decides membership in a particular Language, by following every possible path that describes an input string.
We show that DFAs and NFAs can decide the same languages, by constructing an equivalent DFA for every NFA, and vice versa.
As constructing a DFA from an NFA uses an exponential number of states, we re-prove the pumping lemma instead of lifting DFA.pumping_lemma, in order to obtain the optimal bound on the minimal length of the string.
Like DFA, this definition allows for automata with infinite states; a Fintype instance must be supplied for true NFAs.
Main definitions #
NFA α σ: automaton over alphabetαand set of statesσNFA.evalFrom M S x: set of possible ending states for an input wordxand set of initial statesSNFA.accepts M: the language accepted by the NFAMNFA.Path M s t x: a specific path fromstotfor an input wordxNFA.Path.supp p: set of states visited by the pathp
Main theorems #
NFA.pumping_lemma: every sufficiently long string accepted by the NFA has a substring that can be repeated arbitrarily many times (and have the overall string still be accepted)
An NFA is a set of states (σ), a transition function from state to state labelled by the alphabet (step), a set of starting states (start) and a set of acceptance states (accept). Note the transition function sends a state to a Set of states. These are the states that it may be sent to.
- step : σ → α → Set σ
The NFA's transition function
- start : Set σ
Set of starting states
- accept : Set σ
Set of accepting states
Instances For
M.Path represents a concrete path through the NFA from a start state to an end state for a particular word.
Note that due to the non-deterministic nature of the automata, there can be more than one Path for a given word.
Also note that this is Type and not a Prop, so that we can speak about the properties of a particular Path, such as the set of states visited along the way (defined as Path.supp).
- nil {α : Type u} {σ : Type v} {M : NFA α σ} (s : σ) : M.Path s s []
- cons {α : Type u} {σ : Type v} {M : NFA α σ} (t s u : σ) (a : α) (x : List α) : t ∈ M.step s a → M.Path t u x → M.Path s u (a :: x)
Instances For
M.reverse constructs an NFA with the same states as M, but all the transitions reversed. The resulting automaton accepts a word x if and only if M accepts List.reverse x.