Deterministic Finite Automata #
This file contains the definition of a Deterministic Finite Automaton (DFA), a state machine which
determines whether a string (implemented as a list over an arbitrary alphabet) is in a regular set
in linear time.
Note that this definition allows for Automaton with infinite states, a Fintype
instance must be
supplied for true DFA's.
A DFA is a set of states (σ
), a transition function from state to state labelled by the
alphabet (step
), a starting state (start
) and a set of acceptance states (accept
).
- step : σ → α → σ
A transition function from state to state labelled by the alphabet.
- start : σ
Starting state.
- accept : Set σ
Set of acceptance states.
Instances For
M.evalFrom s x
evaluates M
with input x
starting from the state s
.
Equations
- DFA.evalFrom M start = List.foldl M.step start
Instances For
@[simp]
@[simp]
theorem
DFA.evalFrom_singleton
{α : Type u}
{σ : Type v}
(M : DFA α σ)
(s : σ)
(a : α)
:
DFA.evalFrom M s [a] = M.step s a
@[simp]
theorem
DFA.evalFrom_append_singleton
{α : Type u}
{σ : Type v}
(M : DFA α σ)
(s : σ)
(x : List α)
(a : α)
:
DFA.evalFrom M s (x ++ [a]) = M.step (DFA.evalFrom M s x) a
theorem
DFA.evalFrom_of_append
{α : Type u}
{σ : Type v}
(M : DFA α σ)
(start : σ)
(x : List α)
(y : List α)
:
DFA.evalFrom M start (x ++ y) = DFA.evalFrom M (DFA.evalFrom M start x) y
theorem
DFA.mem_accepts
{α : Type u}
{σ : Type v}
(M : DFA α σ)
(x : List α)
:
x ∈ DFA.accepts M ↔ DFA.evalFrom M M.start x ∈ M.accept
theorem
DFA.evalFrom_split
{α : Type u}
{σ : Type v}
(M : DFA α σ)
[Fintype σ]
{x : List α}
{s : σ}
{t : σ}
(hlen : Fintype.card σ ≤ List.length x)
(hx : DFA.evalFrom M s x = t)
:
∃ (q : σ) (a : List α) (b : List α) (c : List α),
x = a ++ b ++ c ∧ List.length a + List.length b ≤ Fintype.card σ ∧ b ≠ [] ∧ DFA.evalFrom M s a = q ∧ DFA.evalFrom M q b = q ∧ DFA.evalFrom M q c = t
theorem
DFA.evalFrom_of_pow
{α : Type u}
{σ : Type v}
(M : DFA α σ)
{x : List α}
{y : List α}
{s : σ}
(hx : DFA.evalFrom M s x = s)
(hy : y ∈ KStar.kstar {x})
:
DFA.evalFrom M s y = s
theorem
DFA.pumping_lemma
{α : Type u}
{σ : Type v}
(M : DFA α σ)
[Fintype σ]
{x : List α}
(hx : x ∈ DFA.accepts M)
(hlen : Fintype.card σ ≤ List.length x)
:
∃ (a : List α) (b : List α) (c : List α),
x = a ++ b ++ c ∧ List.length a + List.length b ≤ Fintype.card σ ∧ b ≠ [] ∧ {a} * KStar.kstar {b} * {c} ≤ DFA.accepts M