1 / 23

Intro to Theory of Computation

L ECTURE 4 Last time: Equivalence of NFAs and DFAs Closure properties of regular languages Today : Finish closure properties Equivalence of NFAs, DFAs and regular expressions. Intro to Theory of Computation. CS 332. Sofya Raskhodnikova. Operations on languages.

agarland
Download Presentation

Intro to 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. LECTURE 4 • Last time: • Equivalence of NFAs and DFAs • Closure properties of regular languages • Today: • Finish closure properties Equivalence of NFAs, DFAs and regular expressions Intro to Theory of Computation CS 332 Sofya Raskhodnikova SofyaRaskhodnikova; based on slides by Nick Hopper

  2. Operations on languages Complement: A = { w | w  A } Union: A  B = { w | w  A or w  B } Intersection: A  B = { w | w  A and w  B } Reverse: AR = { w1 …wk | wk …w1 A } Concatenation: A  B = { vw | v  A and w  B } Star: A* = { w1 …wk | k ≥ 0 and each wi A } Sofya Raskhodnikova; based on slides by Nick Hopper

  3. Closure properties of the class of regular languages THEOREM. The class of regular languages is closedunder all 6 operations. If A and B are regular, applying any of these operation yields a regular language. Sofya Raskhodnikova; based on slides by Nick Hopper

  4. Star operation Star: A* = { w1 …wk | k ≥ 0 and each wi A } Theorem. If A is regular, A* is also regular. ε ε L(M)=A ε Sofya Raskhodnikova; based on slides by Nick Hopper

  5. The class of regular languages is closed under Regular operations Union: A  B = { w | w  A or w  B } Union: A  B = { w | w  A or w  B } Concatenation: A  B = { vw | v  A and w  B } Star: A* = { w1 …wk | k ≥ 0 and each wi A } Other operations Complement: A = { w | w  A } Intersection: A  B = { w | w  A and w  B } Reverse: AR = { w1 …wk | wk …w1 A } Sofya Raskhodnikova; based on slides by Nick Hopper

  6. Regular expressions • In a regular expression, we can use • Constants: ε , , a setΣ, members of Σ. • Regular operations:*,  , • Examples: • 0*1* • (01)* • 0*1*(ε 0) • L(R) = the language regular expression R describes = { w | w has a run of 0s followed by a run of 1s} • = the set of all strings over the alphabet Σ={0,1} Sofya Raskhodnikova; based on slides by Nick Hopper

  7. Precedence *  EXAMPLE Sofya Raskhodnikova; based on slides by Nick Hopper

  8. Regular expressions: examples 1) 2) 3) { w | w has exactly one character 1, any # of 0s} 0*10* { w | w has length ≥ 3 and its 3rd symbol is 0 } (01)(01) 0 (01)* { w | every odd position of w is a 1 } (1(01))* (ε 1) Sofya Raskhodnikova; based on slides by Nick Hopper

  9. Regular expressions to NFAs Theorem.Every regular expression has an equivalent NFA. Proof: Induction on the length of regular expression R. Base case: length 1 Inductive step: follows from closure of the class of regular languages under the regular operations. R = ε R =  R =  Sofya Raskhodnikova; based on slides by Nick Hopper

  10. Exercise What should the induction hypothesis be? • Suppose some regular expression of length can be converted an NFA, for some . • Suppose each regular expression of length can be converted an NFA, for some . • Suppose each regular expression of length at most k can be converted an NFA, for some . • None of the above.

  11. Regular expression to NFA Transform (1(0 1))* to an NFA ε 1 1,0 ε Sofya Raskhodnikova; based on slides by Nick Hopper

  12. 01*0 0 0 1 NFAs to regular expressions Theorem.Every NFA has an equivalent regular expression. Proof idea: Transform NFA to a regular expression by removing states and relabeling the arrows with regular expressions. Sofya Raskhodnikova; based on slides by Nick Hopper

  13. Exercise qs q qa What is the regular expression that generates all strings that take this machine from to ? • None of the above.

  14. Generalized NFAs Sofya Raskhodnikova; based on slides by Nick Hopper Each transition is labeled with a regular expression Unique and distinct start and accept states No transitions to the start state No transitions from the accept state

  15. Generalized NFAs ab a*b a qs q qa A GNFA accepts w if q0,q1,…,qk, w1,…,wk: wiis generated by R(qi-1,qi) w = w1w2…wk q0=qs, qk=qa R(qs,q) = a*b R(qa,q) = Ø R(q,qs) = Ø

  16. NFA to GNFA ε ε ε NFA ε Add a new start state with no incoming arrows. Make a unique accept state with no outgoing arrows. Sofya Raskhodnikova; based on slides by Nick Hopper

  17. GNF to regular expression ε ε ε NFA While machine has more than 2 states: Pick an internal state, rip it out and relabel the arrows with regular expressions to account for the missing state. Sofya Raskhodnikova; based on slides by Nick Hopper

  18. a a,b (a*b)(ab)* ε b ε a*b q1 q2 q3 q0 R(q0,q3) = (a*b)(ab)*

  19. b bb a q1 q2 a ε b ε b a ε q3 Sofya Raskhodnikova; based on slides by Nick Hopper

  20. b bb a q1 q2 a  ba a ε b ε b a ε Sofya Raskhodnikova; based on slides by Nick Hopper

  21. b = R(q1,q1) bb  (a  ba)b*a bb a q1 q2 a  ba ε ε b  (a  ba)b* b Sofya Raskhodnikova; based on slides by Nick Hopper

  22. = R(q1,q1) bb  (a  ba)b*a q1 ε b  (a  ba)b* = R(q1,qa) qs qa (bb  (a  ba)b*a)*(b  (a  ba)b*) Sofya Raskhodnikova; based on slides by Nick Hopper

  23. Conversion procedures NFA DFA definition Regular Language Regular Expression Sofya Raskhodnikova; based on slides by Nick Hopper

More Related