Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to the Theory of Computation John Paxton Montana State University Summer 2003.

Similar presentations


Presentation on theme: "Introduction to the Theory of Computation John Paxton Montana State University Summer 2003."— Presentation transcript:

1 Introduction to the Theory of Computation John Paxton Montana State University Summer 2003

2 Humor A man walks up to the Marine guard at the White House front gate and asked to see President Clinton. The guard says "Sorry sir but Clinton is no longer president." The man comes back the next day and again approaches the same guard and asks to see President Clinton. Again the guard says "Sir, Clinton is no longer president." The man leaves but comes back the third day and again asked to see President Clinton. The guard says "Sir...you have been here three days in a row asking to see President Clinton...and I have told you each time that Clinton is no longer president...what gives?" The man says "I know... I just like hearing it."

3 1.3 Regular Expression Pattern Recogniton –Unix (GREP) –Perl –Text Editors

4 Formal Definition R is a regular expression if R is 1.a for some a in the alphabet   3.{} 4.(R 1 U R 2 ) where R 1 and R 2 are both regular expressions 5.(R 1 R 2 ) 6.(R 1 *)

5 Exercise: Describe the Language 0*10*  *1  * (  )* 01 U 10 (0 U  )1* 0  *0 U 1  *1 U 0 U 1 1*{} {}*

6 Exercise: Give the Regular Expression {w | w begins with a 1 and ends with a 0} {w | w contains at least 3 0s} {w | w starts with a 0 and has odd length or starts with a 1 and has even length} {w | the length of w is at most 5} {w | w contains at least two 0s and at most one 1} All strings except the empty string

7 Theorem A language is regular if and only if some regular expression describes it. Part I. If a language is described by a regular expression, then it is regular. Part II. If a language is regular, then it is described by a regular expression.

8 Part 1: Show constructions 1.R = a 2.R =  3.R = {} 4.R = R 1 U R 2 5.R = R 1 R 2 6.R = R 1 * a #1

9 Exercises Build an NFA from the regular expression (ab U a)*. Build an NFA from the regular expression (0 U 1)*000(0 U 1)*.

10 Part II A generalized nondeterministic finite automaton (GNFA): –The start state has transition arrows going to every other state but no arrows coming in from any other state. –There is only a single accept state, and it has arrows coming in from every other state but no arrows going to any other state. Furthermore, the accept state is not the same as the start state

11 GNFA –Except for the start state and accept state, one arrow goes from every state to every other state and also from each state to itself. q start q accept q1q1 a a U b a* 

12 GNFA Definition A generalized nondeterministic finite automaton, (Q, , , q start, q accept ) is a 5- tuple where –Q is the finite set of states –  is the input alphabet –  : (Q – {q accept }) x (Q – {q start })  R is the transition function –q start is the start state –q accept is the accept state

13 GNFA Acceptance A GNFA accepts a string w in  * if w = w 1 w 2 …w k where each w i is in  * and a sequence of states q 0,q 1,…q k exists such that –q 0 = q start –q k = q accept –for each i, w i  L(R i ) where R i =  (q i-1,q i )

14 Part II: Proof Process Start with a k state DFA Construct a k+2 state GNFA Map to a k+1 state GNFA ….. Map to a 2 state GNFA Read off the regular expression!

15 Conversion Example 2 state DFA a a, b b 1 2

16 Conversion Example 4 state GNFA a a U b b 1 2 {} 

17 Conversion Example 3 state GNFA a U b  a*b 2  a*{} U {} 

18 Conversion Example 3 state GNFA (simplified) a U b a*b 2 {} 

19 Conversion Example 2 state GNFA {} U a*b(a U b)*  Regular Expression: a*b(a U b)*

20 Exercise Convert to a regular expression 1 2 3 ab 


Download ppt "Introduction to the Theory of Computation John Paxton Montana State University Summer 2003."

Similar presentations


Ads by Google