CSCI 2670 Introduction to Theory of Computing September 1, 2005.

21
CSCI 2670 Introduction to Theory of Computing September 1, 2005

Transcript of CSCI 2670 Introduction to Theory of Computing September 1, 2005.

Page 1: CSCI 2670 Introduction to Theory of Computing September 1, 2005.

CSCI 2670Introduction to Theory of

Computing

September 1, 2005

Page 2: CSCI 2670 Introduction to Theory of Computing September 1, 2005.

Agenda

• Last class– Equivalence of DFA’s and NFA’s

• Today– Some work on designing NFA’s– Closure of regular languages under

regular operators– Another method for describing regular

languages

Page 3: CSCI 2670 Introduction to Theory of Computing September 1, 2005.

Group project

• For each NFA– Informally describe the behavior of

the NFA– Construct a DFA accepting the same

language

Page 4: CSCI 2670 Introduction to Theory of Computing September 1, 2005.

Group 1

ε

ε

1

0

1

0

1

1

0

0

All strings containing an even number of 0’s or an even number of 1’s

Page 5: CSCI 2670 Introduction to Theory of Computing September 1, 2005.

Group 2

0,ε

0 1 1 0

0,ε 0,ε 0,ε

All prefixes of the string 0110

Proper prefixes may be followed by a 0

Page 6: CSCI 2670 Introduction to Theory of Computing September 1, 2005.

Group 3

ε

ε

1

1

1

1

0

0

0

0

1

0

All strings with a zero count divisible by 2 or 3

Page 7: CSCI 2670 Introduction to Theory of Computing September 1, 2005.

Group 4

1 0,1 0,1

0,1

All strings that have a 1 in one of the last three positions

ε

ε

Page 8: CSCI 2670 Introduction to Theory of Computing September 1, 2005.

Group 5

0

1

0

1

All strings with alternating 0’s and 1’s that start with a 0

Page 9: CSCI 2670 Introduction to Theory of Computing September 1, 2005.

Group 6

1

1

1

0

0

0

ε

All strings containing either zero 1’s or three or more 1’s

Page 10: CSCI 2670 Introduction to Theory of Computing September 1, 2005.

Closure of NFA’s under regular operations

• Recall the following are the regular operators– Union– Concatenation– Kleene star

Page 11: CSCI 2670 Introduction to Theory of Computing September 1, 2005.

Union is a regular operation

Theorem: The class of regular languages is closed under the union operation

Proof approach: Assume A1 and A2 are both regular languages with A1=L(M1) and A2=L(M2) and create an NFA M such that L(M) = A1A2

Method: Proof by construction

Page 12: CSCI 2670 Introduction to Theory of Computing September 1, 2005.

M

Construct M from M1 and M2

M1

M2

ε

ε

Page 13: CSCI 2670 Introduction to Theory of Computing September 1, 2005.

Concatenation is a regular operation

Theorem: The class of regular languages is closed under the concatenation operation

Proof approach: Assume A1 and A2 are both regular languages with A1=L(M1) and A2=L(M2) and create an NFA M such that L(M) = A1A2

Method: Proof by construction

Page 14: CSCI 2670 Introduction to Theory of Computing September 1, 2005.

M

Construct M from M1 and M2

M1

M2

ε ε

Page 15: CSCI 2670 Introduction to Theory of Computing September 1, 2005.

Kleene star is a regular operation

Theorem: The class of regular languages is closed under the Kleene operation

Proof approach: Assume A1 is a regular language with A1=L(M1) and create an NFA M such that L(M) = A1

*

Method: Proof by construction

Page 16: CSCI 2670 Introduction to Theory of Computing September 1, 2005.

M

Construct M from M1

M1

ε

εε

Page 17: CSCI 2670 Introduction to Theory of Computing September 1, 2005.

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*

Page 18: CSCI 2670 Introduction to Theory of Computing September 1, 2005.

Where have you seen RE’s?

• Grep• Awk• Perl• Search expressions within emacs

or vi

Page 19: CSCI 2670 Introduction to Theory of Computing September 1, 2005.

RE inductive definition

R is a regular expression if R is1. a for some a 2. ε3. 4. R1 R2 where R1 and R2 are both

regular expressions5. R1 R2 where R1 and R2 are both

regular expressions6. (R1

*) where R1 is a regular expression

Page 20: CSCI 2670 Introduction to Theory of Computing September 1, 2005.

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,ε}

Page 21: CSCI 2670 Introduction to Theory of Computing September 1, 2005.