1 Lecture 19 Closure Properties for LFSA using NFA’s –union second proof –concatenation –Kleene closure
2 LFSA closed under set union (again)
3 LFSA closed under set union Let L 1 and L 2 be arbitrary languages in LFSA Let M 1 and M 2 be NFA’s s.t. L(M 1 ) = L 1, L(M 2 ) = L 2 –M 1 and M 2 exist by definition of L 1 and L 2 in LFSA and the fact that every FSA is an NFA Construct NFA M 3 from NFA’s M 1 and M 2 Argue L(M 3 ) = L 1 union L 2 There exists NFA M 3 s.t. L(M 3 ) = L 1 union L 2 L 1 union L 2 is in LFSA
4 Visualization L 1 union L 2 L1L1 L2L2 LFSA M3M3 M1M1 M2M2 NFA’s Let L 1 and L 2 be arbitrary languages in LFSA Let M 1 and M 2 be NFA’s s.t. L(M 1 ) = L 1, L(M 2 ) = L 2 M 1 and M 2 exist by definition of L 1 and L 2 in LFSA and the fact that every FSA is an NFA Construct NFA M 3 from NFA’s M 1 and M 2 Argue L(M 3 ) = L 1 union L 2 There exists NFA M 3 s.t. L(M 3 ) = L 1 union L 2 L 1 union L 2 is in LFSA
5 Algorithm Specification Input –Two NFA’s M 1 and M 2 Output –NFA M 3 such that L(M 3 ) = L(M 1 ) union L(M 2 ) NFA M 1 NFA M 2 NFA M 3 A
6 Use -transition NFA M 1 NFA M 2 NFA M 3 A a M1M1 a,b M2M2 a M3M3
7 General Case NFA M 1 NFA M 2 NFA M 3 A M1M1 M2M2 M3M3
8 Construction Input –NFA M 1 = (Q 1, , q 1, , A 1 ) –NFA M 2 = (Q 2, , q 2, , A 2 ) Output –NFA M 3 = (Q 3, , q 3, , A 3 ) –What is Q 3 ? Q 3 = Q 1 union Q 2 union {p} where p is not in Q 1 union Q 2 –Also, we need to rename states in Q 2 if any share the same name with states in Q 1 –What is 3 ? 3 = 1 = 2 –What is q 3 ? q 3 = p, the new state not in Q 1 or Q 2 NFA M 1 NFA M 2 NFA M 3 A
9 Construction Input –NFA M 1 = (Q 1, , q 1, , A 1 ) –NFA M 2 = (Q 2, , q 2, , A 2 ) Output –NFA M 3 = (Q 3, , q 3, , A 3 ) –What is A 3 ? A 3 = A 1 union A 2 –What is 3 ? 3 = 1 union 2 union {(p,,q 1 ),(p,,q 2 )} –That is, all the old transitions plus 3 (p, ) = {q 1, q 2 } NFA M 1 NFA M 2 NFA M 3 A
10 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
11 LFSA closed under set concatenation
12 LFSA closed under set concatenation Let L 1 and L 2 be arbitrary languages in LFSA Let M 1 and M 2 be NFA’s s.t. L(M 1 ) = L 1, L(M 2 ) = L 2 –M 1 and M 2 exist by definition of L 1 and L 2 in LFSA and the fact that every FSA is an NFA Construct NFA M 3 from NFA’s M 1 and M 2 Argue L(M 3 ) = L 1 concatenate L 2 There exists NFA M 3 s.t. L(M 3 ) = L 1 concatenate L 2 L 1 concatenate L 2 is in LFSA
13 Visualization L 1 concatenate L 2 L1L1 L2L2 LFSA M3M3 M1M1 M2M2 NFA’s Let L 1 and L 2 be arbitrary languages in LFSA Let M 1 and M 2 be NFA’s s.t. L(M 1 ) = L 1, L(M 2 ) = L 2 –M 1 and M 2 exist by definition of L 1 and L 2 in LFSA and the fact that every FSA is an NFA Construct NFA M 3 from NFA’s M 1 and M 2 Argue L(M 3 ) = L 1 concatenate L 2 There exists NFA M 3 s.t. L(M 3 ) = L 1 concatenate L 2 L 1 concatenate L 2 is in LFSA
14 Algorithm Specification Input –Two NFA’s M 1 and M 2 Output –NFA M 3 such that L(M 3 ) = L(M 1 ) concatenate L(M 2 ) NFA M 1 NFA M 2 NFA M 3 A
15 Use -transition NFA M 1 NFA M 2 NFA M 3 A a M1M1 a,b M2M2 a M3M3
16 General Case NFA M 1 NFA M 2 NFA M 3 A M1M1 M2M2 M3M3
17 Construction Input –NFA M 1 = (Q 1, , q 1, , A 1 ) –NFA M 2 = (Q 2, , q 2, , A 2 ) Output –NFA M 3 = (Q 3, , q 3, , A 3 ) –What is Q 3 ? Q 3 = Q 1 union Q 2 –Also, we need to rename states in Q 2 if any share the same name with states in Q 1 –What is 3 ? 3 = 1 = 2 –What is q 3 ? q 3 = q 1, the initial state of Q 1 NFA M 1 NFA M 2 NFA M 3 A
18 Construction Input –NFA M 1 = (Q 1, , q 1, , A 1 ) –NFA M 2 = (Q 2, , q 2, , A 2 ) Output –NFA M 3 = (Q 3, , q 3, , A 3 ) –What is A 3 ? A 3 = A 2 –What is 3 ? 3 = 1 union 2 union {(p,,q 2 ) | p in A 1 } –That is, all the old transitions plus 3 (p, ) = {q 2 } for all p in A 1 NFA M 1 NFA M 2 NFA M 3 A
19 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
20 LFSA closed under Kleene Closure
21 LFSA closed under Kleene Closure Let L be arbitrary language in LFSA Let M 1 be an NFA s.t. L(M 1 ) = L –M 1 exists by definition of L 1 in LFSA and the fact that every FSA is an NFA Construct NFA M 2 from NFA M 1 Argue L(M 2 ) = L 1 * There exists NFA M 2 s.t. L(M 2 ) = L 1 * L 1 * is in LFSA
22 Visualization L1*L1* L1L1 LFSA NFA’s Let L be arbitrary language in LFSA Let M 1 be an NFA s.t. L(M 1 ) = L –M 1 exists by definition of L 1 in LFSA and the fact that every FSA is an NFA Construct NFA M 2 from NFA M 1 Argue L(M 2 ) = L 1 * There exists NFA M 2 s.t. L(M 2 ) = L 1 * L 1 * is in LFSA M1M1 M2M2
23 Algorithm Specification Input –NFA M 1 Output –NFA M 2 such that L(M 2 ) = L(M 1 ) * NFA M 1 NFA M 2 A
24 Use -transition NFA M 1 NFA M 2 A a M1M1 a M2M2
25 General Case NFA M 1 NFA M 2 A M1M1 M3M3
26 Construction Input –NFA M 1 = (Q 1, , q 1, , A 1 ) Output –NFA M 2 = (Q 2, , q 2, , A 2 ) –What is Q 2 ? Q 2 = Q 1 union {p} where p is not in Q 1 –What is 2 ? 2 = 1 –What is q 2 ? q 3 = p, the state not in Q 1 NFA M 1 NFA M 2 A
27 Construction Input –NFA M 1 = (Q 1, , q 1, , A 1 ) Output –NFA M 2 = (Q 2, , q 2, , A 2 ) –What is A 2 ? A 2 = {p} –What is 2 ? 2 = 1 union {(p,,q 1 )} union {(q,,p) | q in A 1 } –That is, all the old transitions plus 2 (p, ) = {q 1 } and 2 (q, ) = 1 (q, ) union {p} for all q in A 1 NFA M 1 NFA M 2 A
28 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) –To be seen later