NFA's versus FA's NFA's versus FA's

advertisement
NFA’s versus FA’s
„
Show that: For any FA
M = (Q, Σ, δ, q0, F), there exists an NFA
M1 = (Q1, Σ, δ1, q1, F1) such that
L(M) = L(M1).
NFA’s versus FA’s
„
NFA’s may look more powerful than FA’s,
but they are not!
„
Theorem: For any NFA
M = (Q, Σ, δ, q0, F), there exists a FA
M1 = (Q1, Σ, δ1, q1, F1) such that
L(M) = L(M1).
1
NFA’s versus FA’s
„
What is the real difference between a FA
and a NFA?
NFA’s versus FA’s
„
The idea is that the states of the FA
correspond to a set of states of the NFA.
… The
DFA keeps track of the set of states that
the NFA can be in.
… Construct an FA transition diagram equivalent
to the following NFA transition diagram.
a
q0
a
b
a
q2
q1
b a
2
Proof of Theorem NFA = DFA
„
Let M = (Q, Σ, q0, F, δ) be a NFA. Define an
equivalent FA M1 as follows:
M1 = (Q1, Σ, q1, F1, δ1) such that
… Q1
= P(Q)
… q1 = { q0 }
… A1 = { q∈ Q1 | q I F ≠ ∅ }
… for all q∈Q1 and a∈Σ, δ1(q, a) = U p∈q δ(p, a)
We still have to prove that L(M) = L(M1).
Proof of Theorem NFA = DFA
„
The proof is by induction. The main problem
is to formulate what we are going to prove in
the proper way.
example, try to prove that for all x ∈ Σ*:
x∈L(M) iff x∈ L(M1) by induction on the length of
x.
… For
„
This statement is clearly true, and it implies that L(M)
= L(M1). But if you try to prove it, you’ll get stuck!
3
Proof of Theorem NFA = DFA
example, try to prove that for all x ∈Σ*.
δ*1 (q1, x) = δ*(q0, x) by structural induction on
x.
… For
„
This implies that L(M) = L(M1).
NFA to DFA
„
Given an NFA M it can be converted to a DFA
M1.
1.
2.
3.
Determine the states in M1. If M has n states then M1
has 2n states.
Label each of M1’s states with the corresponding
subset of M’s states.
Determine M1’s start and accepting states.
…
4.
Start state is the set of states reachable from M’s start state
via the ε arrows plus the M’s start state.
Determine M1’s transition function.
4
NFA to DFA example
0,1
q0
1
q1
0,1
q2
0,1
q3
How many states could the DFA have?
What are the start states?
What are the accept states?
Convert this NFA to a DFA.
NFA-ε’s vs. NFA’s
„
Theorem: For any NFA-ε
M = (Q, Σ, q0, F, δ), there exists a NFA
M1 = (Q1, Σ, q1, F1, δ1) such that L(M) = L(M1).
5
NFA-ε’s vs NFA’s
„
Convert the following NFA-ε to an NFA.
C
0
A
ε
0
ε
0
B
ε
D
NFA-ε’s vs. NFA’s vs. DFA’s
„
NFA-ε’s, NFA’s and FA’s are all
equivalent.
6
Kleene’s Theorem
„
Kleene’s Theorem: A language L over the
alphabet Σ is regular if and only if there is a
FA that accepts L.
Theorem: Any regular language can be
accepted by an FA.
„ Theorem: The language accepted by any FA
is regular.
„
Corollary
„
Corollary: A language is regular if and only
if some nondeterministic finite automaton
recognizes it.
7
Closure: Union
„
Theorem: The class of regular languages
is closed under the union operation.
… Can
now prove using NFAs rather than
having to prove using a Cartesian product
construction.
Closure: Union
„
Proof:
N1 = (Q1, Σ, δ1, q1, F1) recognize A1 and
N2 = (Q2, Σ, δ2, q2, F2) recognize A2
… Construct N = (Q, Σ, δ, q, F)
… Let
Q = {q0} U Q1 U Q2
„ The state q0 is the start state of N
„ The accept states F = F1 U F2
„ Define δ so that for any q∈ Q and an a ∈ Σε
δ(q,a) = δ1(q,a) q∈Q1
δ2(q,a) q ∈Q2
„
{q1,q2} q = q0 and a = ε
q = q0 and a ≠ ε
∅
8
Closure: Concatenation
„
Theorem: The class of regular languages
is closed under the concatenation
operation.
Closure: Concatenation
„
Proof:
N1 = (Q1, Σ, δ1, q1, F1) recognize A1 and
N2 = (Q2, Σ, δ2, q2, F2) recognize A2
… Construct N = (Q, Σ, δ, q, F)
… Let
Q = Q1 U Q2
„ The state q1 is the start state of N
„ The accept states F = F2
„ Define δ so that for any q∈ Q and an a ∈ Σε
δ(q,a) = δ1(q,a)
q∈Q1 and q∉F1
δ1(q,a)
q ∈F1 and a ≠ ε
„
δ1(q,a) U {q2} q = F1 and a = ε
δ2(q,a)
q = Q2
9
Closure: Kleene Star
„
Theorem: The class of regular languages
is closed under the Kleene star operation.
Closure: Kleene Star
„
Proof:
N1 = (Q1, Σ, δ1, q1, F1) recognize A1
… Construct N = (Q, Σ, δ, q, F) to recognize A*1
… Let
Q = {q0} U Q1
„ The state q0 is the start state of N
„ The accept states F = {q0} U F1
„ Define δ so that for any q ∈ Q and an a ∈ Σε
„
δ(q,a) = δ1(q,a)
δ1(q,a)
δ1(q,a) U {q1}
{q1}
∅
q∈Q1 and q∉F1
q ∈F1 and a ≠ ε
q = F1 and a = ε
q = q0 and a = ε
q = q0 and a ≠ ε
10
Download