Transcript Document

CSCI 2670 Introduction to Theory of Computing

September 7, 2004

Agenda • Last week – Section 1.2

– NFA’s • Today – Start Section 1.3

• Regular expressions • This week – Sections 1.3 and 1.4

• May not complete Section 1.4

Announcement • Homework due next Tuesday (9/14) – 1.5e, 1.12a, 1.16a (show the GNFA steps), 1.17b, 1.39

• Quiz tomorrow – Section 1.2 & Formal definition of RE

Regular expressions (RE’s) • So far we have had to describe languages either with finite automata or with words – Potentially clumsy or imprecise • Today we learn precise expression to describe regular languages – Example : All strings with at least one 1 becomes  *  {1}  * , or more simply  * 1  *

Where have you seen RE’s?

• Grep • Awk • Perl • Search expressions within emacs or vi

RE inductive definition R is a regular expression if R is 1.

a for some a   2.

ε 3.

4.

5.

 R 1  R 2 where R 1 and R 2 regular expressions R 1  R 2 where R 1 and R 2 regular expressions are both are both 6.

(R 1 * ) R 1 is a regular expression

Examples • 0 * 10 * 10 * – {w | w contains exactly two 1’s} • •  11  – {w | w contains two consecutive 1’s}  1(0  ε)1  – {w | w contains two 1’s separated by at most one 0} • (0  ε)(1  ε) – {0,1,01,ε}

RE’s and regular languages Theorem: A language is regular if and only if some regular expression describes it.

– i.e., every regular expression has a corresponding DFA and vice versa

RE’s and regular languages Lemma: If a language is described by a regular expression, then it is regular.

– find an NFA corresponding to any regular expression – use inductive definition of RE’s

1. R=a for some a  q 1 a q 2 N = {{q 1 ,q 2 },  ,  ,q 1 ,{q 2 }} where  (q 1 ,a)=q 2 and  (r,x)=  whenever r=q 2 or x=b

2. R= ε q 1 N = {{q 1 },  ,  ,q 1 ,{q 1 }} where  (q 1 ,x)=  all x for

3. R=  q 1 N = {{q 1 },  ,  ,q 1 ,  } where  (q 1 ,x)=  all x for

Remaining constructions • R = R 1  R 2 • R = R 1  R 2 • R = R 1 * • These were all shown to be regular operators – We know we can construct NFA’s for R provided they exist for R 1 and R 2

• R =  1 – R = (0  1)1 R 1 = 0 0 R 2 = 1 1 Example R 3 = 0  1 ε ε R = (0  1)1 0 1 ε ε ε ε 1 0 1

Example2 • R = 1(0  ε)  * R 1 = 1 R 2 = 0  ε ε ε 1 0 ε 1 R 3 =  * ε R = 1(0  ε )  * 0 ε ε ε 0,1 ε ε ε 0,1 ε

Equivalence of RE’s and DFA’s • We have seen that every RE has a corresponding NFA – Therefore, every RE has a corresponding DFA • We need to show that every DFA can be described by a regular expression • Begin by converting all DFA’s into GNFA’s – Generalized Non-deterministic Finite Automata

GNFA’s • A GNFA is an NFA with the following properties: 1.

The start state has transition arrows going to every other state, but no arrows coming in from any other state 2.

3.

There is exactly one accept state and there is an arrow from every other state to this state, but no arrows to any other state from the accept state The start state is not the accept state

GNFA’s (continued) 4.

5.

Except for the start and accept states, one arrow goes from every state to every other state and also from each state to itself Instead of being labeled with symbols from the alphabet, transitions are labeled with regular expressions