Transcript Module 19

Module 19
• LNFA subset of LFSA
– Theorem 4.1 on page 131 of Martin textbook
– Compare with set closure proofs
• Main idea
– A state in FSA represents a set of states in
original NFA
1
LNFA subset LFSA
• Let L be an arbitrary language in
• Let M be
– M exists by definition of
•
•
•
•
Construct an M’ such that L(M’)
Argue L(M’) =
There exists an M’ such that L(M’) =
L is in
– By definition of
2
Visualization
•Let L be an arbitrary language in LNFA
•Let M be an NFA such that L(M) = L
•M exists by definition of L in LNFA
•Construct FSA M’ from NFA M
•Argue L(M’) = L
•There exists an FSA M’ such that L(M’) =
L
•L is in LFSA
L
LNFA
M
NFA’s
L
LFSA
M’
FSA’s
3
Construction Specification
• We need an algorithm which does the
following
– Input: NFA M
– Output: FSA M’ such that L(M’) = L(M)
4
a,b
a,b
a
Difficulty *
(2, aaaba)
(1, aaba)
(2, aaba)
(3, aaba)
(1, aba)
(2, aba)
(3, aba)
(1, ba)
(2, ba)
(1, a)
(1, l)
b
a
Input string aaaaba
• An NFA can be in
several states after
processing an input
string x
(1, aaaaba)
(1, aaaba)
a
crash
(3, ba)
(4, a)
(2, l)
(5, l)
5
a,b
a,b
a
Observation *
(2, aaaba)
(1, aaba)
(2, aaba)
(3, aaba)
(1, aba)
(2, aba)
(3, aba)
(1, ba)
(2, ba)
(1, a)
(1, l)
b
a
Input string aaaaba
• All strings which end up
in the set of states {1,2,3}
are indistinguishable with
respect to L(M)
(1, aaaaba)
(1, aaaba)
a
crash
(3, ba)
(4, a)
(2, l)
(5, l)
6
a,b
a,b
a
Idea
a
b
a
Input string aaaaba
• Given an NFA M = (Q,S,q0,d,A), the equivalent FSA M’
will have state set 2Q (one state for each subset of Q)
• Example
– In this case there are 5 states in Q
– 2Q, the set of all subsets of Q, has 25 elements including {} and Q
– The FSA M’ will have 25 states
• What strings end up in state {1,2,3} of M’?
– The strings which end up in states 1, 2, and 3 of NFA M.
– In this case, strings which do not contain aaba and end with aa
such as aa, aaa, and aaaa.
7
a,b
a,b
a
Idea Illustrated
(1,aaaaba)
a
b
Input string aaaaba
({1}, aaaaba)
(1, aaaba)
(2, aaaba)
(1, aaba)
(2, aaba)
(3, aaba)
({1,2,3}, aaba)
(1, aba)
(2, aba)
(3, aba)
({1,2,3}, aba)
(1, ba)
(2, ba)
(3, ba)
({1,2,3}, ba)
(1, a)
(1, l)
a
(2, l)
({1,2}, aaaba)
(4, a)
({1,4}, a)
(5, l)
({1,2,5}, l)
8
a,b
Construction
a,b
NFA M
1
a
2
a
3
• Input NFA M = (Q, S, q0, d, A)
• Output FSA M’ = (Q’, S’, q’, d’, A’)
– What is Q’?
• all subsets of Q including Q and {}
• In this case, Q’ =
– What is S’?
• We always make S’ = S
• In this case, S’ = S = {a,b}
– What is q’?
• We always make q’ = {q0}
• In this case q’ =
9
a,b
Construction
a,b
NFA M
1
a
2
a
3
• Input NFA M = (Q, S, q0, d, A)
• Output FSA M’ = (Q’, S’, q’, d’, A’)
– What is A’?
• Suppose a string x ends up in states 1 and 2 of the NFA M above.
– Is x accepted by M?
– Should {1,2} be an accepting state in FSA M’?
• Suppose a string x ends up in states 1 and 2 and 3 of the NFA M above.
– Is x accepted by M?
– Should {1,2,3} be an accepting state in FSA M’?
• Suppose p = {q1, q2, …, qk} where q1, q2, …, qk are in Q
• p is in A’ iff at least one of the states q1, q2, …, qk is in A
• In this case, A’ =
10
a,b
Construction
a,b
NFA M
1
a
2
a
3
• Input NFA M = (Q, S, q0, d, A)
• Output FSA M’ = (Q’, S’, q’, d’, A’)
– What is d’?
• If string x ends up in states 1 and 2 after being processed by the
NFA above, where does string xa end up after being processed by
the NFA above?
• Figuring out d’(p,a) in general
– Suppose p = {q1, q2, …, qk} where q1, q2, …, qk are in Q
– Then d’(p,a) = d(q1,a) union d(q2,a) union … union d(qk,a)
» Similar to 2 FSA to 1 FSA construction
– In this case
» d’({1,2},a) =
11
Construction
Summary
a,b
a,b
NFA M
1
a
2
a
3
• Input NFA M = (Q, S, q0, d, A)
• Output FSA M’ = (Q’, S’, q’, d’, A’)
– Q’ = all subsets of Q including Q and {}
• In this case, Q’ = {{}, {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}}
–
S’ = S
• In this case, S’ = S = {a,b}
– q’ ={q0}
• In this case, q’ = {1}
– A’
• Suppose p = {q1, q2, …, qk} where q1, q2, …, qk are in Q
• p is in A’ iff at least one of the states q1, q2, …, qk is in A
– d’
• Suppose p = {q1, q2, …, qk} where q1, q2, …, qk are in Q
• Then d’(p,a) = d(q1,a) union d(q2,a) union … union d(qk,a)
12
Example Summary
a
b
a,b
1
a,b
a
2
a
3
a
{1}
b
b
{1,2} a {1,2,3}
a,b
NFA M
{}
b
a
{1,3}
a,b
b
{2}
a
{3}
a,b
{2,3}
FSA M’
13
Example Summary Continued
a
b
a,b
1
a,b
a
2
a
3
a
{1}
b
b
{1,2} a {1,2,3}
a,b
NFA M
{}
b
a
{1,3}
a,b
b
{2}
a
{3}
a,b
{2,3}
FSA M’
These states cannot be reached from initial state and are unnecessary.
14
Example Summary Continued
a
b
a,b
1
a,b
a
2
NFA M
a
3
a
{1}
b
b
b
{1,2} a {1,2,3}
a
{1,3}
Smaller FSA M’
By examination, we can see that state {1,3} is unnecessary.
However, this is a case by case optimization.
It is not a general technique or algorithm.
15
Example 2
a,b
A
a
B
b
C
NFA M
Step 1: name the three states of NFA M
16
a,b
Step 2:
transition table
A
a
B
b
C
NFA M
{A}
{B}
{}
{B,C}
a
{B}
{B}
b
{}
{B,C}
{}
{}
{B} {B,C}
d’({B,C},a) = d(B,a) U d(C,a)
= {B} U {}
= {B}
d’({B,C},b) = d(B,b) U d(C,b)
= {B,C} U {}
= {B,C}
17
a,b
Step 3:
accepting states
A
a
B
b
C
NFA M
{A}
{B}
{}
{B,C}
a
{B}
{B}
b
{}
{B,C}
{}
{}
{B} {B,C}
Which states should be accepting?
Any state which includes an
accepting state of M, in this case, C.
A’ = {{B,C}}
18
a,b
Step 4: Answer
A
a
B
b
C
NFA M
{A}
{B}
{}
{B,C}
a
{B}
{B}
b
{}
{B,C}
Initial state is {A}
Set of final states A’ = {{B,C}}
{}
{}
{B} {B,C}
This is sufficient. You do NOT need to turn this into a diagram.
19
a,b
Step 5:
Optional
a
A
a
b
{B}
b
C
NFA M
b
a
{A}
B
b
a
{B,C}
a,b
{}
FSA M’
20
Comments
• You should be able to execute this algorithm
– You should be able to convert any NFA into an equivalent FSA.
• You should understand the idea behind this algorithm
– For an FSA M’, strings which end up in the same state of M’ are
indistinguishable wrt L(M’)
– For an NFA M, strings which end up in the same set of states of M
are indistinguishable wrt L(M)
21
Comments
• You should understand the importance of this algorithm
– Design tool
• We can design using NFA’s
• A computer will convert this NFA into an equivalent FSA
– FSA’s can be executed by computers whereas NFA’s cannot (or at least
cannot easily be run by computers)
– Chaining together algorithms
• Perhaps it is easy to build NFA’s to accept L1 and L2
• Use this algorithm to turn these NFA’s to FSA’s
• Use previous algorithm to build FSA to accept L1 intersect L2
• You should be able to construct new algorithms for new
closure property proofs
22