COSC 3340 Introduction to Theory of Computation University
- Slides: 18
COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 5 1 Lecture 5 Uof. H - COSC 3340 - Dr. Verma
Regular expressions l l 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 2 Lecture 5 Uof. H - COSC 3340 - Dr. Verma
Language generated by a regular expression r l Notation: – l l l 3 L(r) denotes language generated by reg. exp. r. L( ) = { } L( ) = L( ) L( *) = (L( ))* Lecture 5 Uof. H - COSC 3340 - Dr. Verma
Examples of regular expressions l Note: We drop parentheses when not required. – l l Let = {a, b} The following are regular expressions: – – l , a, b *, a*, b*, ab, a b (a b)*, a*b*, (ab)* (a b)*ab, etc. Are the following regular expressions? – 4 Example: (a b) is written a b a, *a, a*b Lecture 5 Uof. H - COSC 3340 - Dr. Verma
Some exercises on regular expressions l Example: What is L((a b)*a(a b)*)? – l 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}. 5 Lecture 5 Uof. H - COSC 3340 - Dr. Verma
Tips for Regular Expressions Regular expressions are harder to design for: l Languages that have complementation in their definition. Example: Exercise 2 on previous slide. l Languages that have intersection in their definition. The reason is that we need to express these operations in terms of , and * 6 Lecture 5 Uof. H - COSC 3340 - Dr. Verma
Regular expressions versus FA's l l Regular expressions generate exactly the class of regular languages. Theorem: – – l 7 (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 composite regular expressions: use closure under , and * Lecture 5 Uof. H - COSC 3340 - Dr. Verma
Parse Tree for (a U b)* b * b U a 8 b Lecture 5 Uof. H - COSC 3340 - Dr. Verma
Example: NFA for (a U b)*b a b a. Ub 9 Lecture 5 Uof. H - COSC 3340 - Dr. Verma
Example (contd. ) : NFA for (a U b)*b (a. Ub)* 10 Lecture 5 Uof. H - COSC 3340 - Dr. Verma
Example (contd. ) : NFA for (a U b)*b 11 Lecture 5 Uof. H - COSC 3340 - Dr. Verma
DFA regular expression l Easier to do: – l GNFA (Generalized NFA) – l DFA GNFA regular expression. 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. 12 Lecture 5 Uof. H - COSC 3340 - Dr. Verma
DFA regular expression (contd. ) l Idea: – – – 13 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. Lecture 5 Uof. H - COSC 3340 - Dr. Verma
Eliminating state q{rip} R 4 qi qj R 1 R 3 qrip (R 1 )(R 2)* (R 3) (R 4) R 2 14 qi Lecture 5 qj Uof. H - COSC 3340 - Dr. Verma
Constructing regular expression. DFA L = {w in {a, b}* | w has odd number of b's } 15 Lecture 5 Uof. H - COSC 3340 - Dr. Verma
Constructing regular expression (contd. ) Added: a new start state and a new final state with empty transitions 16 Lecture 5 Uof. H - COSC 3340 - Dr. Verma
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 17 Lecture 5 Uof. H - COSC 3340 - Dr. Verma
Constructing regular expression (contd. ) qrip We take out the qrip state and we are left with the regular expression 18 Lecture 5 Uof. H - COSC 3340 - Dr. Verma
- Cosc 3340
- Cosc 3340
- Cosc 3340
- Cosc 3340
- Sipser, m: introduction to the theory of computation
- Kine 3340
- O que hd
- Ece 3340
- Kine 3340
- Common lisp a gentle introduction to symbolic computation
- Theory of computation
- What is transition graph
- Theory of computation
- Theory of computation
- Ambiguity
- Finite automata calculator
- Time hierarchy theorem proof
- Anbncn pda
- Theory of computation quiz