Transcript Lecture 22

Lecture 22
• Closure Properties for LFSA using NFA’s
– union (second proof)
– concatenation
– Kleene closure
1
LFSA closed under set union
(again)
2
LFSA closed under set union
• Let L1 and L2 be arbitrary languages in LFSA
• Let M1 and M2 be NFA’s s.t. L(M1) = L1, L(M2) = L2
– M1 and M2 exist by definition of L1 and L2 in LFSA and the fact
that every FSA is an NFA
•
•
•
•
Construct NFA M3 from NFA’s M1 and M2
Argue L(M3) = L1 union L2
There exists NFA M3 s.t. L(M3) = L1 union L2
L1 union L2 is in LFSA
3
Visualization
•Let L1 and L2 be arbitrary languages in LFSA
•Let M1 and M2 be NFA’s s.t. L(M1) = L1, L(M2) =
L2
•M1 and M2 exist by definition of L1 and L2
in LFSA and the fact that every FSA is an
NFA
•Construct NFA M3 from NFA’s M1 and M2
•Argue L(M3) = L1 union L2
•There exists NFA M3 s.t. L(M3) = L1 union L2
•L1 union L2 is in LFSA
L1
L1 union L2
L2
LFSA
M1
M3
M2
NFA’s
4
Algorithm Specification
• Input
– Two NFA’s M1 and M2
• Output
– NFA M3 such that L(M3) = L(M1) union L(M2)
NFA M1
NFA M2
A
NFA M3
5
Use l-transition
NFA M1
NFA M2
a
A
NFA M3
a
l
M1
a,b
a,b
a,b
l
a,b
a,b
a,b
M2
M3
6
General Case
M1
NFA M1
NFA M2
A
NFA M3
l
l
M2
M3
7
Construction
NFA M1
NFA M2
A
NFA M3
• Input
– NFA M1 = (Q1, S1, q1, d1, A1)
– NFA M2 = (Q2, S2, q2, d2, A2)
• Output
– NFA M3 = (Q3, S3, q3, d3, A3)
– What is Q3?
• Q3 = Q1 union Q2 union {p} where p is not in Q1 union Q2
– Also, we need to rename states in Q2 if any share the same name with states
in Q1
– What is S3?
•
S3 = S1 = S 2
– What is q3?
• q3 = p, the new state not in Q1 or Q2
8
Construction
NFA M1
NFA M2
A
NFA M3
• Input
– NFA M1 = (Q1, S1, q1, d1, A1)
– NFA M2 = (Q2, S2, q2, d2, A2)
• Output
– NFA M3 = (Q3, S3, q3, d3, A3)
– What is A3?
• A3 = A1 union A2
– What is d3?
•
d3 = d1 union d2 union {(p,l,q1) ,(p,l,q2)}
– That is, all the old transitions plus
 d3(p,l) = {q1, q2}
9
Comments
• You should be able to execute this algorithm
• You should understand the idea behind this algorithm
• You should understand how this algorithm can be used to
simplify design
• You should be able to design new algorithms for new
closure properties
• You should understand how this helps prove result that
regular languages and LFSA are identical
– In particular, you should understand how this is used to construct
an NFA M from a regular expression r s.t. L(M) = L(r)
– To be seen later
10
LFSA closed under set
concatenation
11
LFSA closed under set
concatenation
• Let L1 and L2 be arbitrary languages in LFSA
• Let M1 and M2 be NFA’s s.t. L(M1) = L1, L(M2) = L2
– M1 and M2 exist by definition of L1 and L2 in LFSA and the fact
that every FSA is an NFA
•
•
•
•
Construct NFA M3 from NFA’s M1 and M2
Argue L(M3) = L1 concatenate L2
There exists NFA M3 s.t. L(M3) = L1 concatenate L2
L1 concatenate L2 is in LFSA
12
Visualization
• Let L1 and L2 be arbitrary
languages in LFSA
• Let M1 and M2 be NFA’s s.t.
L(M1) = L1, L(M2) = L2
– M1 and M2 exist by definition
of L1 and L2 in LFSA and the
fact that every FSA is an NFA
• Construct NFA M3 from NFA’s
M1 and M2
• Argue L(M3) = L1 concatenate L2
• There exists NFA M3 s.t. L(M3) =
L1 concatenate L2
• L1 concatenate L2 is in LFSA
L1
L1 concatenate L2
L2
LFSA
M1
M3
M2
NFA’s
13
Algorithm Specification
• Input
– Two NFA’s M1 and M2
• Output
– NFA M3 such that L(M3) = L(M1) concatenate L(M2)
NFA M1
NFA M2
A
NFA M3
14
Use l-transition
a
NFA M1
NFA M2
A
NFA M3
a
M1
l
a,b
a,b
a,b
a,b
a,b
a,b
M2
M3
15
General Case
M1
NFA M1
NFA M2
A
NFA M3
l
l
M2
M3
16
Construction
NFA M1
NFA M2
A
NFA M3
• Input
– NFA M1 = (Q1, S1, q1, d1, A1)
– NFA M2 = (Q2, S2, q2, d2, A2)
• Output
– NFA M3 = (Q3, S3, q3, d3, A3)
– What is Q3?
• Q3 = Q1 union Q2
– Also, we need to rename states in Q2 if any share the same name with states in
Q1
– What is S3?
•
S3 = S1 = S 2
– What is q3?
• q3 = q1, the initial state of Q1
17
Construction
NFA M1
NFA M2
A
NFA M3
• Input
– NFA M1 = (Q1, S1, q1, d1, A1)
– NFA M2 = (Q2, S2, q2, d2, A2)
• Output
– NFA M3 = (Q3, S3, q3, d3, A3)
– What is A3?
• A3 = A2
– What is d3?
•
d3 = d1 union d2 union {(p,l,q2) | p in A1}
– That is, all the old transitions plus
 d3(p,l) = {q2} for all p in A1
18
Comments
• You should be able to execute this algorithm
• You should understand the idea behind this algorithm
• You should understand how this algorithm can be used to
simplify design
• You should be able to design new algorithms for new
closure properties
• You should understand how this helps prove result that
regular languages and LFSA are identical
– In particular, you should understand how this is used to construct
an NFA M from a regular expression r s.t. L(M) = L(r)
– To be seen later
19
LFSA closed under Kleene
Closure
20
LFSA closed under Kleene
Closure
• Let L be arbitrary language in LFSA
• Let M1 be an NFA s.t. L(M1) = L
– M1 exists by definition of L1 in LFSA and the fact that every FSA
is an NFA
•
•
•
•
Construct NFA M2 from NFA M1
Argue L(M2) = L1*
There exists NFA M2 s.t. L(M2) = L1*
L1* is in LFSA
21
Visualization
• Let L be arbitrary language
in LFSA
• Let M1 be an NFA s.t. L(M1)
=L
L1
– M1 exists by definition of L1
in LFSA and the fact that
every FSA is an NFA
• Construct NFA M2 from
NFA M1
• Argue L(M2) = L1*
• There exists NFA M2 s.t.
L(M2) = L1*
• L1* is in LFSA
L1*
LFSA
M1
M2
NFA’s
22
Algorithm Specification
• Input
– NFA M1
• Output
– NFA M2 such that L(M2) = L(M1)*
NFA M1
A
NFA M2
23
Use l-transition
NFA M1
NFA M2
l
a
M1
A
l
a
M2
24
General Case
NFA M1
A
NFA M2
l
l
M1
l M
3
25
Construction
NFA M1
A
NFA M2
• Input
– NFA M1 = (Q1, S1, q1, d1, A1)
• Output
– NFA M2 = (Q2, S2, q2, d2, A2)
– What is Q2?
• Q2 = Q1 union {p} where p is not in Q1
– What is S2?
•
S2 = S1
– What is q2?
• q3 = p, the state not in Q1
26
Construction
NFA M1
A
NFA M2
• Input
– NFA M1 = (Q1, S1, q1, d1, A1)
• Output
– NFA M2 = (Q2, S2, q2, d2, A2)
– What is A2?
• A2 = {p}
– What is d2?
•
d2 = d1 union {(p,l,q1)} union {(q,l,p) | q in A1}
– That is, all the old transitions plus
 d2(p,l) = {q1} and
 d2(q,l) = d1(q,l) union {p} for all q in A1
27
Comments
• You should be able to execute this algorithm
• You should understand the idea behind this algorithm
– Why do we need to make an extra state p?
• You should understand how this algorithm can be used to
simplify design
• You should be able to design new algorithms for new
closure properties
• You should understand how this helps prove result that
regular languages and LFSA are identical
– In particular, you should understand how this is used to construct
an NFA M from a regular expression r s.t. L(M) = L(r)
28
– To be seen later