Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.

Similar presentations


Presentation on theme: "CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons."— Presentation transcript:

1 CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. Based on a work at http://peerinstruction4cs.org. Permissions beyond the scope of this license may be available at http://peerinstruction4cs.org.

2 CLOSURE PROOFS REVIEWING OUR EXAMPLE Guaranteed to be on exams

3 From last time Are regular languages closed under union? a) True b) False

4 Union of two regular languages L1 = {w | b’s never appear after a’s} L2 = {w | length(w) is odd} L1 U L2 = {w | b’s never appear after a’s OR length(w) is odd} Regular because there’s a DFA

5 Union of two regular languages L1 U L2 = {w | b’s never appear after a’s OR length(w) is odd} Does this prove that regular languages are closed under union? – (a) True or (b) False It’s just one example

6 Thm. The class of regular languages is closed under the union operation. Proof: Given: Two regular languages L 1, L 2. Want to show: L 1 U L 2 is regular. Because L 1 and L 2 are regular, we know there exist DFAs M 1 = (Q 1,Σ,δ 1,q 01,F 1 ) and M 2 = (Q 2,Σ,δ 2,q 02,F 2 ) that recognize L 1 and L 2. We construct a DFA M = (Q,Σ,δ,q 0,F), s.t.: – Q = Q 1 x Q 2 – δ((x,y),c) = (δ 1 (x,c), δ 2 (y,c)), for c in Σ and (x,y) in Q – q 0 = (q 01, q 02 ) – F = {(x,y) in Q | x in F 1 or y in F 2 } M recognizes L 1 U L 2. Correctness: ___________________________________ A DFA recognizes L 1 U L 2, so L 1 U L 2 is regular, and the class of regular languages is closed under union. Q.E.D. Final form for your homework/test: Could you come up with this, and write it correctly, in a short amount of time on an exam??

7 NONDETERMINISTIC FINITE AUTOMATA NFA They’re really good guessers! What is deterministic?

8 DFA or NFA? a)DFA b)NFA c)Both DFA and NFA

9 DFA or NFA? a)DFA b)NFA c)Both DFA and NFA

10 Tracing in an NFA What are the two sequences of states on the input “100”? a)(q0,q0,q1,q2[accept]), (q0,q1,q2[accept]) Final: Accept b)(q0,q0,q1,q2[accept]), (q0,q1,q2[reject]) Final: Accept c)(q0,q0,q1,q2[accept]), (q0,q1,q2[reject]) Final: Reject d)(q0,q0,q1,q2[reject]), (q0,q1,q2[reject]) Final: Reject “100” b

11 DFAs vs. NFAs DFAs For each character in the alphabet, exactly one transition leaving every state Computation is “deterministic,” i.e. determined by the input, i.e., the same every time for a given input NFAs There may be 0, 1, or many transitions leaving a single state for the same input character Transition function defined on “epsilon” in addition to alphabet characters There may be several different ways to reach an accept state for a single string—the computation may not determined by the input (“nondeterministic”)

12 Formal Definition of an NFA An NFA M 1 is defined as a 5-tuple as follows: M 1 = (Q, Σ, δ, q0, F), where: – Q is a finite set of states – Σ is a finite set of characters, the alphabet – δ: Q x Σ -> P (Q), the transition function – q0, a member of Q, the start state – F, a subset of Q, the accept state(s) 12 NEED TO USE THIS FOR PROOFS---CANNOT MAKE GENERAL STATEMENTS BY DRAWING SPECIFIC EXAMPLES! WHAT IS the POWER SET?

13 Nondeterminism Because NFAs are non-deterministic, the outcome (accept/reject) of the computation may be different from run to run (i.e., isn’t determined by the input) a)TRUE b)FALSE 13

14 REG. LANGS. CLOSED UNDER UNION (WHY NFAS ARE SO USEFUL IN PROOFS) A different (easier!) way to prove what we just proved

15 Thm. The class of regular languages is closed under the union operation. Proof: Given: Two regular languages L 1, L 2. Want to show: L 1 U L 2 is regular. Because L 1 and L 2 are regular, we know there exist DFAs M 1 = (Q 1,Σ,δ 1,q 01,F 1 ) and M 2 = (Q 2,Σ,δ 2,q 02,F 2 ) that recognize L 1 and L 2. We construct a DFA M = (Q,Σ,δ,q 0,F), s.t.: – Q = Q 1 x Q 2 – δ((x,y),c) = (δ 1 (x,c), δ 2 (y,c)), for c in Σ and (x,y) in Q – q 0 = (q 01, q 02 ) – F = {(x,y) in Q | x in F 1 or y in F 2 } M recognizes L 1 U L 2. Correctness: ___________________________________ A DFA recognizes L 1 U L 2, so L 1 U L 2 is regular, and the class of regular languages is closed under union. Q.E.D. Final form for your homework/test: Could you come up with this, and write it correctly, in a short amount of time on an exam??

16 Thm. The class of regular languages is closed under the union operation. Proof: Given: Two regular languages L 1, L 2. Want to show: L 1 U L 2 is regular. Because L 1 and L 2 are regular, we know there exist DFAs M 1 = (Q 1,Σ,δ 1,q 01,F 1 ) and M 2 = (Q 2,Σ,δ 2,q 02,F 2 ) that recognize L 1 and L 2. We construct an NFA M = (Q,Σ,δ,q 0,F), s.t.: – Q = – δ(x,c) = – q 0 = – F = M recognizes L 1 U L 2. Correctness: ___________________________________ An NFA recognizes L 1 U L 2, so L 1 U L 2 is regular, and the class of regular languages is closed under union. Q.E.D. Final form for your homework/test: Could you come up with this, and write it correctly, in a short amount of time on an exam??

17 Back to our working example

18 Thm. The class of regular languages is closed under the union operation. Proof: Given: Two regular languages L 1, L 2. Want to show: L 1 U L 2 is regular. Because L 1 and L 2 are regular, we know there exist DFAs M 1 = (Q 1,Σ,δ 1,q 01,F 1 ) and M 2 = (Q 2,Σ,δ 2,q 02,F 2 ) that recognize L 1 and L 2. We construct an NFA M = (Q,Σ,δ,q 0,F), s.t.: – Q = – δ(x,c) = – q 0 is a new state not in Q 1 or Q 2 – F = M recognizes L 1 U L 2. Correctness: ___________________________________ An NFA recognizes L 1 U L 2, so L 1 U L 2 is regular, and the class of regular languages is closed under union. Q.E.D. Final form for your homework/test: Discrepancy here NFA vs DFA

19 Thm. The class of regular languages is closed under the union operation. Because L 1 and L 2 are regular, we know there exist DFAs M 1 = (Q 1,Σ,δ 1,q 01,F 1 ) and M 2 = (Q 2,Σ,δ 2,q 02,F 2 ) that recognize L 1 and L 2. We construct an NFA M = (Q,Σ,δ,q 0,F), s.t.: – Q = ? – δ(x,c) = – q 0 is a new state not in Q 1 or Q 2 – F = ? – a) Q = Q 1 X Q 2, F = F 1 X F 2 – b) Q = Q 1 X Q 2, F = {(x,y) in Q | x in F 1 or y in F 2 } – c) Q = Q 1 U Q 2, F = F 1 U F 2 – d) Q = Q 1 U Q 2 U {q 0 }, F = F 1 U F 2 Why q0 in {}?

20 Thm. The class of regular languages is closed under the union operation. Proof: Given: Two regular languages L 1, L 2. Want to show: L 1 U L 2 is regular. Because L 1 and L 2 are regular, we know there exist DFAs M 1 = (Q 1,Σ,δ 1,q 01,F 1 ) and M 2 = (Q 2,Σ,δ 2,q 02,F 2 ) that recognize L 1 and L 2. We construct an NFA M = (Q,Σ,δ,q 0,F), s.t.: – Q = Q 1 U Q 2 – δ(x,c) = ? – q 0 is a new state not in Q 1 or Q 2 – F = F 1 U F 2 M recognizes L 1 U L 2. Correctness: ___________________________________ An NFA recognizes L 1 U L 2, so L 1 U L 2 is regular, and the class of regular languages is closed under union. Q.E.D. Final form for your homework/test: Discrepancy here NFA vs DFA

21 Thm. The class of regular languages is closed under the union operation. – Q = Q 1 U Q 2 – δ(x,c) = δ 1 (x,c) if x in Q 1 δ 2 (x,c) if x in Q 2 {q 01,q 02 } if x = q 0 and c = ε { } if x = q 0 and c != ε – q 0 is a new state not in Q 1 or Q 2 – F = F 1 U F 2 Almost done: we have shown there is an NFA accepting L1 U L2. Does this mean it’s regular? Next class! Zoomed in Discrepancy here NFA vs DFA


Download ppt "CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons."

Similar presentations


Ads by Google