Module 17

63 Views

Download Presentation
## Module 17

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -

**Module 17**• Closure Properties of Language class LFSA • Remember ideas used in solvable languages unit • Set complement • Set intersection, union, difference, symmetric difference**LFSA is closed under set complement**• If L is in LFSA, then Lc is in LFSA • Proof • Let L be an arbitrary language in LFSA • Let M be the FSA such that L(M) = L • M exists by definition of L in LFSA • Construct FSA M’ from M • Argue L(M’) = Lc • There exists an FSA M’ such that L(M’) = Lc • Lc is in LFSA**L**Lc M M’ FSA’s Visualization • Let L be an arbitrary language in LFSA • Let M be the FSA such that L(M) = L • M exists by definition of L in LFSA • Construct FSA M’ from M • Argue L(M’) = Lc • Lc is in LFSA LFSA**Construct FSA M’ from M ***• What did we do when we proved that REC, the set of solvable languages, is closed under set complement? • Construct program P’ from program P • Can we translate this to the FSA setting?**Construct FSA M’ from M**• M = (Q, S, q0, A, d) • M’ = (Q’, S’, q’, A’, d’) • M’ should say yes when M says no • M’ should say no when M says yes • How? • Q’ = Q • S’ = S • q’ = q0 • d’ = d • A’ = Q-A**a**a b 2 1 b b 3 FSA M’ a • Q’ = Q • S’ = S • q’ = q0 • d’ = d • A’ = Q-A Example a a b 2 1 b b 3 FSA M a**Construction is an algorithm ***FSA M FSA M’ Construction Algorithm • Set Complement Construction • Algorithm Specification • Input: FSA M • Output: FSA M’ such that L(M’) = L(M)c • Comments • This algorithm can be in any computational model. • It does not have to be (and typically is not) an FSA • These set closure constructions are useful. • More on this later**Specification of the algorithm**FSA M FSA M’ Construction Algorithm • Your algorithm must give a complete specification of M’ in terms of M • Example: • Let input FSA M = (Q, S, q0, A, d) • Output FSA M’ = (Q’, S’, q’, A’, d’) where • Q’ = Q • S’ = S • q’ = q0 • d’ = d • A’ = Q-A • When I ask for such a construction algorithm specification, this type of answer is what I am looking for. Further algorithmic details on how such an algorithm would work are unnecessary.**LFSA closed under Set Intersection Operation**(also set union, set difference, and symmetric difference)**LFSA closed under set intersection operation ***• Let L1 and L2 be arbitrary languages in LFSA • Let M1 and M2 be FSA’s s.t. L(M1) = L1, L(M2) = L2 • M1 and M2 exist by definition of L1 and L2 in LFSA • Construct FSA M3 from FSA’s M1 and M2 • Argue L(M3) = L1 intersect L2 • There exists FSA M3 s.t. L(M3) = L1 intersect L2 • L1 intersect L2 is in LFSA**L1**L1 intersect L2 L2 M1 M3 M2 FSA’s Visualization • Let L1 and L2 be arbitrary languages in LFSA • Let M1 and M2 be FSA’s s.t. L(M1) = L1, L(M2) = L2 • M1 and M2 exist by definition of L1 and L2 in LFSA • Construct FSA M3 from FSA’s M1 and M2 • Argue L(M3) = L1 intersect L2 • There exists FSA M3 s.t. L(M3) = L1 intersect L2 • L1 intersect L2 is in LFSA LFSA**Alg**Algorithm Specification • Input • Two FSA’s M1 and M2 • Output • FSA M3 such that L(M3) = L(M1) intersection L(M2) FSA M1 FSA M2 FSA M3**FSA M1**FSA M2 Alg FSA M3 Use Old Ideas * • Key concept: Try ideas from previous closure property proofs • Example • How did the algorithm that was used to prove that REC is closed under set intersection work? • If we adapt this approach, what should M3 do with respect to M1, M2, and the input string?**FSA M1**FSA M2 Alg FSA M3 l,A 0,A 1,A 2,A 1 0,1 l,B 0,B 1,B 2,B A 0 B M2 M3 Run M1 and M2 Simultaneously 0 1 1 0 l 0 0 1 2 1 0 1 M1 What happens when M1 and M2 run on input string 11010?**Input**FSA M1 = (Q1, S1, q1, d1, A1) FSA M2 = (Q2, S2, q2, d2, A2) Output FSA M3 = (Q3, S3, q3, d3, A3) What is Q3? Q3 = Q1 X Q2 where X is cartesian product In this case, Q3 = {(l,A), (l,B), (0,A), (0,B), (1,A), (1,B), (2,A), (2,B)} What is S3? S3 = S1 = S2 In this case, S3 = {0,1} 0 1 1 0 l 0 0 1 2 1 0 1 M1 1 0,1 0 A B M2 Construction ***Input**FSA M1 = (Q1, S1, q1, d1, A1) FSA M2 = (Q2, S2, q2, d2, A2) Output FSA M3 = (Q3, S3, q3, d3, A3) What is q3? q3 = (q1, q2) In this case, q3 = (l,A) What is A3? A3 = {(p, q) | p in A1 and q in A2} In this case, A3 = {(0,B)} 0 1 1 0 l 0 0 1 2 1 0 1 M1 1 0,1 0 A B M2 Construction ***Input**FSA M1 = (Q1, S1, q1, d1, A1) FSA M2 = (Q2, S2, q2, d2, A2) Output FSA M3 = (Q3, S3, q3, d3, A3) What is d3? For all p in Q1, q in Q2, a in S, d3((p,q),a) = (d1(p,a),d2(q,a)) In this case, d3((0,A),0) = (d1(0,0),d2(A,0)) = (0,B) d3((0,A),1) = (d1(0,1),d2(A,1)) = (1,A) 0 1 1 0 l 0 0 1 2 1 0 1 M1 1 0,1 0 A B M2 Construction**1**0,1 A 0 B M2 Example Summary 1 0 1 1 1 0 l 0 0 1 2 l,A 0,A 1 1,A 2,A 1 0 1 0 0 0 M1 1 0 0 1 l,B 0,B 1,B 2,B 0 1 M3**Observation**• Input • FSA M1 = (Q1, S1, q1, d1, A1) • FSA M2 = (Q2, S2, q2, d2, A2) • Output • FSA M3 = (Q3, S3, q3, d3, A3) • What is A3? • A3 = {(p, q) | p in A1 and q in A2} • What if operation were different? • Set union, set difference, symmetric difference**Observation continued ***• Input • FSA M1 = (Q1, S1, q1, d1, A1) • FSA M2 = (Q2, S2, q2, d2, A2) • Output • FSA M3 = (Q3, S3, q3, d3, A3) • What is A3? • Set intersection: A3 = {(p, q) | p in A1and q in A2} • Set union: A3 = {(p, q) | p in A1or q in A2} • Set difference: A3 = {(p, q) | p in A1 and q not in A2} • Symmetric difference: A3 = {(p, q) | (p in A1 and q not in A2) or (p not in A1 and q in A2) }**Observation conclusion**• LFSA is closed under • set intersection • set union • set difference • symmetric difference • The constructions used to prove these closure properties are essentially identical**Comments ***• You should be able to execute this algorithm • Convert two FSA’s into a third FSA with the correct properties. • You should understand the idea behind this algorithm • The third FSA essentially runs both input FSA’s simultaneously on any input string • How we set A3 depending on the specific set operation • You should understand how this algorithm can be used to simplify design of FSA’s • You should be able to construct new algorithms for new closure property proofs**L**L1 L1 intersect L2 L LFSA L2 REC LFSA M1 M3 C++ Programs M M2 P FSA’s FSA’s Comparison *