210 likes | 350 Views
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.
E N D
CSE 105Theory 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.
Guaranteed to be on exams Closure ProofsReviewing our Example
From last time • Are regular languages closed under union? • a) True • b) False
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
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
Final form for your homework/test: Thm. The class of regular languages is closed under the union operation. • Proof: • Given: Two regular languages L1, L2. • Want to show: L1 U L2 is regular. • Because L1 and L2 are regular, we know there exist DFAs M1 = (Q1,Σ,δ1,q01,F1) and M2 = (Q2,Σ,δ2,q02,F2) that recognize L1 and L2. We construct a DFA M = (Q,Σ,δ,q0,F), s.t.: • Q = Q1x Q2 • δ((x,y),c) = (δ1(x,c),δ2 (y,c)), for c in Σ and (x,y) in Q • q0 = (q01, q02) • F = {(x,y) in Q | x in F1or y in F2} • M recognizes L1 U L2. • Correctness: ___________________________________ • A DFA recognizes L1 U L2, so L1 U L2 is regular, and the class of regular languages is closed under union. Q.E.D. Could you come up with this, and write it correctly, in a short amount of time on an exam??
They’re really good guessers! Nondeterministic Finite AutomataNFA What is deterministic?
DFA or NFA? DFA NFA Both DFA and NFA
DFA or NFA? DFA NFA Both DFA and NFA
Tracing in an NFA “100” • What are the two sequences of states on the input “100”? • (q0,q0,q1,q2[accept]), (q0,q1,q2[accept]) Final: Accept • (q0,q0,q1,q2[accept]), (q0,q1,q2[reject]) Final: Accept • (q0,q0,q1,q2[accept]), (q0,q1,q2[reject]) Final: Reject • (q0,q0,q1,q2[reject]), (q0,q1,q2[reject]) Final: Reject b
DFAs vs. NFAs DFAs 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”) • 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
Formal Definition of an NFA • An NFA M1 is defined as a 5-tuple as follows: • M1 = (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) WHAT IS the POWER SET? NEED TO USE THIS FOR PROOFS---CANNOT MAKE GENERAL STATEMENTS BY DRAWING SPECIFIC EXAMPLES!
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) • TRUE • FALSE
A different (easier!) way to prove what we just proved Reg. Langs. Closed Under Union(Why NFAs are So Useful in proofs)
Final form for your homework/test: Thm. The class of regular languages is closed under the union operation. • Proof: • Given: Two regular languages L1, L2. • Want to show: L1 U L2 is regular. • Because L1 and L2 are regular, we know there exist DFAs M1 = (Q1,Σ,δ1,q01,F1) and M2 = (Q2,Σ,δ2,q02,F2) that recognize L1 and L2. We construct a DFA M = (Q,Σ,δ,q0,F), s.t.: • Q = Q1x Q2 • δ((x,y),c) = (δ1(x,c),δ2 (y,c)), for c in Σ and (x,y) in Q • q0 = (q01, q02) • F = {(x,y) in Q | x in F1or y in F2} • M recognizes L1 U L2. • Correctness: ___________________________________ • A DFA recognizes L1 U L2, so L1 U L2 is regular, and the class of regular languages is closed under union. Q.E.D. Could you come up with this, and write it correctly, in a short amount of time on an exam??
Final form for your homework/test: Thm. The class of regular languages is closed under the union operation. • Proof: • Given: Two regular languages L1, L2. • Want to show: L1 U L2 is regular. • Because L1 and L2 are regular, we know there exist DFAs M1 = (Q1,Σ,δ1,q01,F1) and M2 = (Q2,Σ,δ2,q02,F2) that recognize L1 and L2. We construct an NFAM = (Q,Σ,δ,q0,F), s.t.: • Q = • δ(x,c) = • q0 = • F = • M recognizes L1 U L2. • Correctness: ___________________________________ • An NFA recognizes L1 U L2, so L1 U L2 is regular, and the class of regular languages is closed under union. Q.E.D. Could you come up with this, and write it correctly, in a short amount of time on an exam??
Final form for your homework/test: Thm. The class of regular languages is closed under the union operation. • Proof: • Given: Two regular languages L1, L2. • Want to show: L1 U L2 is regular. • Because L1 and L2 are regular, we know there exist DFAs M1 = (Q1,Σ,δ1,q01,F1) and M2 = (Q2,Σ,δ2,q02,F2) that recognize L1 and L2. We construct an NFAM = (Q,Σ,δ,q0,F), s.t.: • Q = • δ(x,c) = • q0 is a new state not in Q1 or Q2 • F = • M recognizes L1 U L2. • Correctness: ___________________________________ • An NFA recognizes L1 U L2, so L1 U L2 is regular, and the class of regular languages is closed under union. Q.E.D. Discrepancy here NFA vs DFA
Thm. The class of regular languages is closed under the union operation. • Because L1 and L2 are regular, we know there exist DFAs M1 = (Q1,Σ,δ1,q01,F1) and M2 = (Q2,Σ,δ2,q02,F2) that recognize L1 and L2. We construct an NFAM = (Q,Σ,δ,q0,F), s.t.: • Q = ? • δ(x,c) = • q0 is a new state not in Q1 or Q2 • F = ? • a) Q = Q1 X Q2, F = F1 X F2 • b) Q = Q1 X Q2, F = {(x,y) in Q | x in F1 or y in F2} • c) Q = Q1 U Q2, F = F1 U F2 • d) Q = Q1 U Q2 U {q0}, F = F1 U F2 Why q0 in {}?
Final form for your homework/test: Thm. The class of regular languages is closed under the union operation. • Proof: • Given: Two regular languages L1, L2. • Want to show: L1 U L2 is regular. • Because L1 and L2 are regular, we know there exist DFAs M1 = (Q1,Σ,δ1,q01,F1) and M2 = (Q2,Σ,δ2,q02,F2) that recognize L1 and L2. We construct an NFAM = (Q,Σ,δ,q0,F), s.t.: • Q = Q1 U Q2 • δ(x,c) = ? • q0 is a new state not in Q1 or Q2 • F = F1 U F2 • M recognizes L1 U L2. • Correctness: ___________________________________ • An NFA recognizes L1 U L2, so L1 U L2 is regular, and the class of regular languages is closed under union. Q.E.D. Discrepancy here NFA vs DFA
Zoomed in Thm. The class of regular languages is closed under the union operation. • Q = Q1 U Q2 • δ(x,c) = • δ1(x,c) if x in Q1 • δ2(x,c) if x in Q2 • {q01,q02} if x = q0 and c = ε • { } if x = q0 and c != ε • q0 is a new state not in Q1 or Q2 • F = F1 U F2 Almost done: we have shown there is an NFA accepting L1 U L2. Does this mean it’s regular? Next class! Discrepancy here NFA vs DFA