1 / 18

COSC 3340: Introduction to Theory of Computation

COSC 3340: Introduction to Theory of Computation. University of Houston Dr. Verma Lecture 5. Regular expressions. A third way to view regular languages. A language generator model instead of language acceptor. Definition of Regular expressions :

glynis
Download Presentation

COSC 3340: Introduction 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. COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 5 UofH - COSC 3340 - Dr. Verma

  2. Regular expressions • A third way to view regular languages. • A language generator model instead of language acceptor. • Definition of Regular expressions: • The smallest class of strings over  {(, ), *, , , } that includes: 1.  (basic reg. exp.) 2.  for every  in . (basic reg. exp.) and is closed under , * and  UofH - COSC 3340 - Dr. Verma

  3. Language generated by a regular expression r • Notation: • L(r) denotes language generated by reg. exp. r. • L() =  • L() = {} • L() = L()  L() • L() = L()L() • L(*) = (L())* UofH - COSC 3340 - Dr. Verma

  4. Examples of regular expressions • Note: We drop parentheses when not required. • Example: (a  b) is written a  b • Let  = {a,b} • The following are regular expressions: • , a, b • *, a*, b*, ab, a  b • (a  b)*, a*b*, (ab)* • (a  b)*ab, etc. • Are the following regular expressions? •   a, *a, a*b, a*b UofH - COSC 3340 - Dr. Verma

  5. Some exercises on regular expressions • Example: What is L((a  b)*a(a  b)*)? • Ans: {w in {a, b}* | w contains at least one a} • Write regular expressions for: 1. {w in {a,b}* | |w| is odd }. 2. {w in {a,b}* | w does not have ab as a substring}. 3. {w in {a,b,c}* | no b in w can come before any c in w}. UofH - COSC 3340 - Dr. Verma

  6. Tips for Regular Expressions Regular expressions are harder to design for: • Languages that have complementation in their definition. Example: Exercise 2 on previous slide. • Languages that have intersection in their definition. The reason is that we need to express these operations in terms of ,  and * UofH - COSC 3340 - Dr. Verma

  7. Regular expressions versus FA's • Regular expressions generate exactly the class of regular languages. • Theorem: • (a) For every regular expression there is an equivalent NFA • (b) For every DFA there is an equivalent regular expression. • Proof of (a): • For , the NFA is: • For , the NFA is: • For composite regular expressions: use closure under ,  and * UofH - COSC 3340 - Dr. Verma

  8. b * U a b Parse Tree for (a U b)*  b UofH - COSC 3340 - Dr. Verma

  9. a b aUb Example: NFA for (a U b)*b UofH - COSC 3340 - Dr. Verma

  10. Example (contd.) : NFA for (a U b)*b (aUb)* UofH - COSC 3340 - Dr. Verma

  11. Example (contd.) : NFA for (a U b)*b (a U b)*b UofH - COSC 3340 - Dr. Verma

  12. DFA  regular expression • Easier to do: • DFA GNFAregular expression. • GNFA (Generalized NFA) • labels of transitions can be regular expressions. • Need special GNFA that satisfies: (1) start state has no incoming transition (2) only one final state (3) final state has no outgoing transition. UofH - COSC 3340 - Dr. Verma

  13. DFA  regular expression (contd.) • Idea: • Convert DFA special GNFA. • Eliminate all states, except start and final state, one state at a time. • Output the label on the single transition left at the end. UofH - COSC 3340 - Dr. Verma

  14. Eliminating state q{rip} R4 qi qj R1 R3 qrip (R1 )(R2)* (R3)  (R4) R2 qi qj UofH - COSC 3340 - Dr. Verma

  15. Constructing regular expression. DFA L = {w in {a, b}* | w has odd number of b's } UofH - COSC 3340 - Dr. Verma

  16. Constructing regular expression (contd.) Added: a new start state and a new final state with empty transitions UofH - COSC 3340 - Dr. Verma

  17. Constructing regular expression (contd.) Eliminate states one-by-one qrip Before we take out qrip, we have to see all the paths to the qrip state and all possible transitions. We take out the qrip state and it leaves us with a 3 state Finite Automata UofH - COSC 3340 - Dr. Verma

  18. Constructing regular expression (contd.) qrip We take out the qrip state and we are left with the regular expression UofH - COSC 3340 - Dr. Verma

More Related