02_finite_automata
02_finite_automata
1
Topics
2
Deterministic Finite Accepters
3
Deterministic Finite Accepters
Definition 2.1
5
Deterministic Finite Accepters
Extended Transition Function
• δ* : Q × Σ* → Q.
• Transition is processed on strings, rather than a single symbol.
• e.g.)
• If δ(q0, a) = q1, δ(q1, b) = q2, then δ*(q0, ab) = q2.
• We can define it recursively.
• δ*(q, λ) = q, δ*(q, wa) = δ(δ*(q, w), a),
• ∀q, q ∈ Q, w ∈ Σ*, a ∈ Σ.
6
Languages and DFAs
Definition 2.2
• The language accepted by a dfa M = (Q, Σ, δ, q0, F) is the set of all strings
on Σ accepted by M.
7
Languages and DFAs Figure 2.2
Example 2.2
• Figure 2.2 show the dfa accepts the following language. Trap State
n
• L = {a b : n ≥ 0}.
• M = ({q0, q1, q2}, {a, b}, δ, q0, {q1}), where δ is given by
• δ(q0, a) = q0, δ(q0, b) = q1,
• δ(q1, a) = q2, δ(q1, b) = q2,
• δ(q2, a) = q2, δ(q2, b) = q2. ← Why do we need these?
8
Languages and DFAs
Theorem 2.1
9
Languages and DFAs
Theorem 2.1
• Proof.
• Assume that the claim is true for all strings v with | v | ≤ n. (1)
• Consider then any w of length n + 1 can be written as
• w = va.
• Suppose that δ*(qi, v) = qk.
• Since | v | = n and (1), there must be a walk in GM labeled v from qi to qk. (2)
10
Languages and DFAs
Theorem 2.1
12
Finding DFA
Example 2.4
• Find a dfa that accepts all the strings on {0, 1}, except those containing the
substring 001.
13
Figure 2.5
Finding DFA
Example 2.4
• Each internal state name indicates how close a substring so far to 001.
• At first, it starts with λ, and as long as the input symbol is 1, it stays there.
• Once 0 is processed, it moves to 0.
• The next 0 makes it move to the next state 00.
• Then it moves to 001 with a consecutive 1.
• For any other input symbols, it moves to other internal states accordingly.
• Note that 001 is a trap state, and all other states are final states.
14
Regular Languages
Definition 2.3
• L = L(M).
• If we consider all possible finite automata, we get a set of languages
accepted by them.
15
Regular Languages
Example 2.5
2
• Let L be the language in Example 2.5. Show that L is regular.
2
• L = {aw1aaw2a : w1, w2 ∈ {a, b}*}
Figure 2.7
17
Non-deterministic Finite
Accepters
18
Nondeterministic Finite Automata
Definition 2.4
19
Nondeterministic Finite Automata
Definition 2.4
Q
• δ : Q × (Σ ∪ {λ}) → 2 .
Q
• What’s 2 ?
Q
• Q = {q0, q1}, then 2 = {Ø, {q0}, {q1}, {q0, q1}}.
• There are three major differences between DFAs and NFAs.
• Diff.1: The next state can be represented as a set of internal states.
• δ(q1, a) = {q0, q1}
20
Nondeterministic Finite Automata
Definition 2.4
Q
• δ : Q × (Σ ∪ {λ}) → 2 .
• Diff. 2: an NFA also allows to have λ as its argument, which means that it can
change states w/o consuming input symbol.
• In DFA, when a transition happens, it always moves to the right on the input
string.
• Now an NFA can stay at the same location on the input string while changing its
states.
• Diff. 3: It’s possible that δ(qi, a) is empty, which means that there is no transition for
a certain situation.
21
Nondeterministic Finite Automata
Example 2.7
Figure 2.8
22
Nondeterministic Finite Automata
Example 2.8
Figure 2.9
• q1 has two transitions for input 0.
• There exists a λ-transition for q0.
• δ(q0,0), δ(q2,0), δ(q2,1) are not defined.
• δ(q2,0) = Ø.
• The automaton accepts λ, 1010, 101010, …, but not 110 and 10100.
• How about 10? - We can choose an appropriate edge to accept it.
23
The Extended Transition Function
Definition 2.5
24
The Extended Transition Function
Example 2.9 Figure 2.10
• ( | w | + 1) × Λ + | w | = Λ + (1 + Λ) | w | .
27
Find a Walk for a String
28
Languages and NFAs
Definition 2.6
• Formally,
• L(M) = {w ∈ Σ* : δ*(q0, w) ∩ F ≠ Ø}.
• L consists of all strings w for which there is a walk labeled w from the initial
vertex to one of the final vertices.
29
Languages and NFAs
Example 2.10
Figure 2.9
31
Why Nondeterminism?
32
Equivalence of DFA and NFA
33
Equivalence of Automata
Definition 2.7
34
Equivalence of Automata
Example 2.11 Figure 2.11
35
Which is More Powerful?
• e.g.) if a set of possible state after reading w is {q0, ⋯, qk} in an NFA, then we
label the corresponding next state as "{q0, ⋯, qk}".
38
Equivalence of NFAs and DFAs
Theorem 2.2
• Then there exists a deterministic finite accepter MD = (QD, Σ, δD, {q0}, FD),
such that
• L = L(MD).
39
Equivalence of NFAs and DFAs
Theorem 2.2
• Procedure: NFA-to-DFA
1. Create a graph GD with vertex {q0}. Identify this vertex as the initial
vertex.
40
Equivalence of NFAs and DFAs
Theorem 2.2
• Take any vertex {qi, qj, ⋯, qk} of GD that has no outgoing edge for some
a ∈ Σ.
• Compute δ*(q
N i
, a), δ*(q
N j
, a), ⋯, δ*(q
N k
, a) .
• If δ* (q
N i
, a) ∪ δ*(q
N j
, a) ∪ , ⋯ ∪ δ*(q
N k
, a) = {q ,
l mq , ⋯, qn} ,
• create a vertex for GD labeled {ql, qm, ⋯, qn} if it does not exist.
• Add to GD an edge from {qi, qj, ⋯, qk} to {ql, qm, ⋯, qn} and label it with a.
41
Equivalence of NFAs and DFAs
Theorem 2.2
42
Equivalence of NFAs and DFAs
Theorem 2.2
44
Equivalence of NFAs and DFAs
Theorem 2.2
• Whenever δ* (q
N 0
, w) contains a final state qf, so does the label of δ* (q
D 0
, w) .
45
Equivalence of NFAs and DFAs
Figure 2.14
Example 2.13
• Σ = {0,1}.
• We are drawing GD.
• Take any vertex from GD w/o having 0 or
1.
46
Distinguishable States
Definition 2.8
Example 2.14
• State q5 is useless.
• States q1, q2 and q3, q4 are
indistinguishable.
48
Reducing States
Mark Procedure
2. Consider all pairs of states (p, q): if p ∈ F and q ∉ F, or vice versa, mark the pair as
distinguishable.
3. Repeat the following step until no previously unmarked pairs are marked.
49
Reducing States
Example 2.15
Figure 2.18
• Start with
• (a){q0, q1, q3} and (b){q2, q4}.
• (a) ➞ {q0}, {q1, q3}.
• (b) ➞ {q2}, {q4}.
50
Reducing States
Theorem 2.3
• The mark procedure, applied to any dfa M = (Q, Σ, δ, q0, F), terminates and
determines all pairs of distinguishable states.
M ̂ = ( Q ,̂ Σ, δ ,̂ q0 ,̂ F )̂ as follows.
• Given M = (Q, Σ, δ, q0, F), we can construct a reduced dfa
1. Use procedure mark to generate the equivalence classes, say {qi, qj, ⋯, qk}.
M .̂
2. For each set of such indistinguishable states, create a state labeled ij⋯k for
52
Reducing States
Reduce Procedure
Example 2.16
• Equivalence classes:
• {q0}, {q1, q3},{q2}, {q4}.
• Add new transition rules for new
states.
• Given any dfa M, application of the reduce procedure yields another dfa M̂
s.t.
• L(M) = L( M )̂ .