1 / 21

CSE 105 Theory of Computation

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.

maren
Télécharger la présentation

CSE 105 Theory of Computation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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.

  2. Guaranteed to be on exams Closure ProofsReviewing our Example

  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. 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??

  7. They’re really good guessers! Nondeterministic Finite AutomataNFA What is deterministic?

  8. DFA or NFA? DFA NFA Both DFA and NFA

  9. DFA or NFA? DFA NFA Both DFA and NFA

  10. 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

  11. 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

  12. 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!

  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) • TRUE • FALSE

  14. A different (easier!) way to prove what we just proved Reg. Langs. Closed Under Union(Why NFAs are So Useful in proofs)

  15. 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??

  16. 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??

  17. Back to our working example

  18. 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

  19. 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 {}?

  20. 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

  21. 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

More Related