1 / 27

FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY

15-453. FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY. REGULAR EXPRESSIONS. THURSDAY Jan 21. WHAT DOES D LOOK LIKE?. D = { w | w has equal number of occurrences of 01 and 10}. = { w | w = 1, w = 0, w = ε or w starts with a 0 and ends with a 0 or

eris
Download Presentation

FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY

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. 15-453 FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY

  2. REGULAR EXPRESSIONS THURSDAY Jan 21

  3. WHAT DOES D LOOK LIKE? D = { w | w has equal number of occurrences of 01 and 10} = { w | w = 1, w = 0, w = ε or w starts with a 0 and ends with a 0 or w starts with a 1 and ends with a 1 } 1  0  ε 0(01)*0  1(01)*1

  4. REGULAR EXPRESSIONS  is a regexp representing {} ε is a regexp representing {ε}  is a regexp representing  If R1 and R2 are regular expressions representing L1 and L2 then: (R1R2) represents L1  L2 (R1  R2) represents L1 L2 (R1)* represents L1*

  5. PRECEDENCE Tightest Star (“*”) Concatenation (“.”, “”) Loosest Union (“”, “+”, “|”)

  6. EXAMPLE ( ( R1* ) R2 )  R3 R1*R2 R3 =

  7. { w | w has exactly a single 1 } 0*10*

  8. What language does * represent? {ε}

  9. { w | w has length ≥ 3 and its 3rd symbol is 0 } 000(01)*  010(01)*  100(01)*  110(01)* (01)(01)0(01)*

  10. { w | every odd position of w is a 1 } 1((01)1)*(01ε)  ε Also (1(0  1))*(1  ε)

  11. EQUIVALENCE L can be represented by a regexp  L is regular Induction on the length of R: Given regular expression R, we show there exists NFA N such that R represents L(N)

  12. Given regular expression R, we show there exists NFA N such that R represents L(N) Induction on the length of R:  L can be represented by a regexp  L is regular Base Cases (R has length 1): R =  R = ε R = 

  13. Inductive Step: Assume R has length k > 1, and that every regular expression of length <k represents a regular language Three possibilities for R: (Union Theorem!) R = R1 R2 (Concatenation) R = R1 R2 (Star) R = (R1)* Therefore: L can be represented by a regexp  L is regular

  14. Have Shown L can be represented by a regexp  L is a regular language

  15. Give an NFA that accepts the language represented by (1(0  1))* ε 1 1,0 ε

  16. L can be represented by a regexp  L is a regular language  Proof idea: Transform an NFA for L into a regular expression by removing states and re-labeling arrows with regular expressions

  17. ε ε ε ε ε 0 0 01*0 1 NFA Add unique and distinct start and accept states While machine has more than 2 states: Pick an internal state, rip it out and re-label the arrowswith regexps, to account for the missing state

  18. ε ε ε ε ε R(q1,q2)R(q2,q2)*R(q2,q3)  R(q1,q3) R(q1,q2) R(q2,q3) R(q2,q2) G NFA While machine has more than 2 states: In general: R(q1,q3) q2 q3 q1

  19. a a,b (a*b)(ab)* ε b ε a*b q1 q2 q3 q0 R(q0,q3) = (a*b)(ab)* represents L(N)

  20. Formally: Add qstart and qaccept to create G Run CONVERT(G): (Outputs a regexp) If #states = 2 return the expression on the arrow going from qstart to qaccept If #states > 2

  21. Formally: Add qstart and qaccept to create G Run CONVERT(G): (Outputs a regexp) If #states > 2 select qripQ different from qstart and qaccept }Defines: G (GNFA) define Q = Q – {qrip} define Ras: R(qi,qj) = R(qi,qrip)R(qrip,qrip)*R(qrip,qj)  R(qi,qj) (R = the regexps for edges in G) return CONVERT(G)

  22. Claim: CONVERT(G) is equivalent to G Proof by induction on k (number of states in G) Base Case: k = 2  Inductive Step: Assume claim is true for k-1 state GNFAs We first note that G and G are equivalent But, by the induction hypothesis, G is equivalent to CONVERT(G) Thus: CONVERT(G) equivalent to CONVERT(G) QED

  23. b bb a q1 q2 a ε b ε b a ε q3

  24. b bb a q1 q2 a  ba a ε b ε b a ε

  25. b bb  (a  ba)b*a bb a q1 q2 a  ba ε ε b  (a  ba)b* b (bb  (a  ba)b*a)* (b  (a  ba)b*)

  26. NFA DFA DEFINITION Regular Language Regular Expression

  27. FLAC Read Chapter 2.1 of the book for next time www.cs.cmu.edu/~15453

More Related