1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 (For next time: Read Chapter 1.3 of the book)

Slides:



Advertisements
Similar presentations
Deterministic Finite Automata (DFA)
Advertisements

FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
CS21 Decidability and Tractability
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
NFAs Sipser 1.2 (pages 47–54). CS 311 Fall Recall… Last time we showed that the class of regular languages is closed under: –Complement –Union.
Finite Automata Great Theoretical Ideas In Computer Science Anupam Gupta Danny Sleator CS Fall 2010 Lecture 20Oct 28, 2010Carnegie Mellon University.
1 Introduction to Computability Theory Lecture4: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
NFAs Sipser 1.2 (pages 47–54). CS 311 Mount Holyoke College 2 Recall… Last time we showed that the class of regular languages is closed under: –Complement.
Lecture 3UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 3.
Lecture 3: Closure Properties & Regular Expressions Jim Hook Tim Sheard Portland State University.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Regular.
1 Single Final State for NFAs and DFAs. 2 Observation Any Finite Automaton (NFA or DFA) can be converted to an equivalent NFA with a single final state.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Nondeterminism.
CS5371 Theory of Computation Lecture 6: Automata Theory IV (Regular Expression = NFA = DFA)
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
Lecture 8 Sept 29, 2011 Regular expressions – examples Converting DFA to regular expression. (same works for NFA to r.e. conversion.) Converting R.E. to.
FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such.
1 Regular Languages Finite Automata eg. Supermarket automatic door: exit or entrance.
Costas Busch - LSU1 Non-Deterministic Finite Automata.
Lexical Analysis Part 2 Professor Yihjia Tsai Tamkang University.
Today Chapter 1: RE = Regular Languages, nonregular languages RL pumping lemma Chapter 2: Context-Free Languages (CFLs)
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
1 A Single Final State for Finite Accepters. 2 Observation Any Finite Accepter (NFA or DFA) can be converted to an equivalent NFA with a single final.
Great Theoretical Ideas in Computer Science.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 5 School of Innovation, Design and Engineering Mälardalen University 2012.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong DFA to regular.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Theory of Languages and Automata
Theory of Computation, Feodor F. Dragan, Kent State University 1 Regular expressions: definition An algebraic equivalent to finite automata. We can build.
Prof. Busch - LSU1 NFAs accept the Regular Languages.
CHAPTER 1 Regular Languages
January 9, 2015CS21 Lecture 31 CS21 Decidability and Tractability Lecture 3 January 9, 2015.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
CSCI 2670 Introduction to Theory of Computing September 13.
Finite Automata Great Theoretical Ideas In Computer Science Victor Adamchik Danny Sleator CS Spring 2010 Lecture 20Mar 30, 2010Carnegie Mellon.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Equivalence with FA * Any Regex can be converted to FA and vice versa, because: * Regex and FA are equivalent in their descriptive power ** Regular language.
 2004 SDU Lecture4 Regular Expressions.  2004 SDU 2 Regular expressions A third way to view regular languages. Say that R is a regular expression if.
1 Introduction to the Theory of Computation Regular Expressions.
CSCI 2670 Introduction to Theory of Computing September 11, 2007.
Regular Languages Chapter 1 Giorgi Japaridze Theory of Computability.
Complexity and Computability Theory I Lecture #5 Rina Zviel-Girshin Leah Epstein Winter
Finite Automata A simple model of computation. 2 Finite Automata2 Outline Deterministic finite automata (DFA) –How a DFA works.
1/29/02CSE460 - MSU1 Nondeterminism-NFA Section 4.1 of Martin Textbook CSE460 – Computability & Formal Language Theory Comp. Science & Engineering Michigan.
Theory of Languages and Automata By: Mojtaba Khezrian.
CSE 105 theory of computation
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
Single Final State for NFA
CSC 4170 Theory of Computation Nondeterminism Section 1.2.
Intro to Theory of Computation
CS 154, Lecture 3: DFANFA, Regular Expressions.
COSC 3340: Introduction to Theory of Computation
4. Properties of Regular Languages
Non-Deterministic Finite Automata
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
CS21 Decidability and Tractability
Regular Languages Finite Automata eg. Supermarket automatic door:
CS21 Decidability and Tractability
CSC 4170 Theory of Computation Nondeterminism Section 1.2.
Chapter 1 Regular Language
CSCI 2670 Introduction to Theory of Computing
CHAPTER 1 Regular Languages
Intro to Theory of Computation
Presentation transcript:

1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY (For next time: Read Chapter 1.3 of the book)

q1q1 q2q2 q3q3 q4q4 ε

3 Q is the set of states Σ is the alphabet  : Q  Σ ε → 2 Q is the transition function Q 0  Q is the set of start states F  Q is the set of accept states A non-deterministic finite automaton (NFA) is a 5-tuple N = (Q, Σ, , Q 0, F) 2 Q is the set of subsets of Q and Σ ε = Σ  {ε}

q1q1 q2q2 q3q3 q4q4 N = (Q, Σ, , Q 0, F) Q = {q 1, q 2, q 3, q 4 } Σ = {0,1} Q 0 = {q 1, q 2 } F = {q 4 }  Q ε 0 1ε q1q1 q2q2 q3q3 q4q4

q1q1 q2q2 q3q3 q4q4 N = (Q, Σ, , Q 0, F) Q = {q 1, q 2, q 3, q 4 } Σ = {0,1} Q 0 = {q 1, q 2 } F = {q 4 }  Q 0 1ε q1q1 {q 3 }  q2q2  {q 4 }  q3q3  {q2}{q2} q4q4  ε

q1q1 q2q2 q3q3 q4q4 N = (Q, Σ, , Q 0, F) Q = {q 1, q 2, q 3, q 4 } Σ = {0,1} Q 0 = {q 1, q 2 } F = {q 4 }  Q ε, 0 0 1ε q1q1 {q 3 }  q2q2  {q 4 }  q3q3 {q 2,q 4 }  {q2}{q2} q4q4  00  L(N)? 01  L(N)?

7 Let w  Σ* and suppose w can be written as w 1... w n where w i  Σ ε (ε is viewed as representing the empty string ) Then N accepts w if there are r 0, r 1,..., r n  Q such that 1.r 0  Q 0 2.r i+1   (r i, w i+1 ) for i = 0,..., n-1, and 3.r n  F A language L is recognized by an NFA N if L = L (N). L(N) = the language of machine N = set of all strings machine N accepts

q1q1 q2q2 q3q3 q4q4 N = (Q, Σ, , Q 0, F) Q = {q 1, q 2, q 3, q 4 } Σ = {0,1} Q 0 = {q 1, q 2 } F = {q 4 }  Q ε, 0 0 1ε q1q1 {q 3 }  q2q2  {q 4 }  q3q3 {q 2,q 4 }  {q2}{q2} q4q4  00  L(N)? 01  L(N)?

9 Q = 2 Q  : Q  Σ → Q  (R,  ) =  ε(  (r,  ) ) rRrR q 0 = ε(Q 0 ) F = { R  Q | f  R for some f  F } FROM NFA TO DFA Input: N = (Q, Σ, , Q 0, F) Output: M = (Q, Σ, , q 0, F) * For R  Q, the ε-closure of R, ε(R) = {q that can be reached from some r  R by traveling along zero or more ε arrows}, *

10 a a, b a b ε Given: NFA N = ( {1,2,3}, {a.b}, , {1}, {1} ) Construct: equivalent DFA M ε({1}) = {1,3} N

11 a a, b a b ε Given: NFA N = ( {1,2,3}, {a,b}, , {1}, {1} ) Construct: equivalent DFA M ε({1}) = {1,3} N N = ( Q, Σ, , Q 0, F ) = (Q, Σ, , q 0, F)  ab  {1}  {2} {2,3} {3} {1,3}  {1,2} {2,3} {1,3} {2} {2,3} {1,2,3} {3} {1,2,3} {2,3} q 0 =

12 a a, b a b ε Given: NFA N = ( {1,2,3}, {a,b}, , {1}, {1} ) Construct: equivalent DFA M ε({1}) = {1,3} N N = ( Q, Σ, , Q 0, F ) = (Q, Σ, , q 0, F)  ab  {1}  {2} {2,3} {3} {1,3}  {1,2} {2,3} {1,3} {2} {2,3} {1,2,3} {3} {1,2,3} {2,3} q 0 =

13 REGULAR LANGUAGES CLOSED UNDER STAR Let L be a regular language and M be a DFA for L We construct an NFA N that recognizes L* 0 0, ε ε ε

14 Formally: Input: M = (Q, Σ, , q 1, F) Output: N = (Q, Σ, , {q 0 }, F) Q = Q  {q 0 } F = F  {q 0 }  (q,a) = {  (q,a)} {q1}{q1} {q1}{q1}  if q  Q and a ≠ ε if q  F and a = ε if q = q 0 and a = ε if q = q 0 and a ≠ ε  else DFA NFA

15 Show: L (N) = L* 1.L (N)  L* 2. L (N)  L*

16 1. L (N)  L* Assume w = w 1 …w k is in L*, where w 1,…,w k  L We show N accepts w by induction on k Base Cases: k = 0 k = 1 Inductive Step: Assume N accepts all strings v = v 1 …v k  L*, v i  L and let u = u 1 …u k u k+1  L*, v j  L Since N accepts u 1 …u k (by induction) and M accepts u k+1, N must accept u (w = ε) (w  L)

17 Assume w is accepted by N, we show w  L* If w = ε, then w  L* If w ≠ ε accept ε ε  L* 2. L (N)  L* By induction

18 REGULAR LANGUAGES ARE CLOSED UNDER REGULAR OPERATIONS Union: A  B = { w | w  A or w  B } Intersection: A  B = { w | w  A and w  B } Negation:  A = { w  Σ* | w  A } Reverse: A R = { w 1 …w k | w k …w 1  A } Concatenation: A  B = { vw | v  A and w  B } Star: A* = { w 1 …w k | k ≥ 0 and each w i  A }

19 The PUMPING LEMMA and REGULAR EXPRESSIONS

20 SOME LANGUAGES ARE NOT REGULAR B = {0 n 1 n | n ≥ 0} is NOT regular!

21 WHICH OF THESE ARE REGULAR C = { w | w has equal number of 1s and 0s} D = { w | w has equal number of occurrences of 01 and 10} NOT REGULAR REGULAR!!!

22 THE PUMPING LEMMA Let L be a regular language with |L| =  Then there exists a positive integer P such that 1. |y| > 0 2. |xy| ≤ P 3. xy i z  L for any i ≥ 0 if w  L and |w| ≥ P then w = xyz, where:

23 Let P be the number of states in M Assume w  L is such that |w| ≥ P q0q0 qiqi qjqj q |w| … There must be j > i such that q i = q j Let M be a DFA that recognizes L 1. |y| > 0 2. |xy| ≤ P 3. xy i z  L for any i ≥ 0 We show w = xyz x

24 USING THE PUMPING LEMMA Use the pumping lemma to prove that B = {0 n 1 n | n ≥ 0} is not regular Hint: Assume B is regular Let B = L(M), for DFA M, and let P be larger than the number of states in M Try pumping s = 0 P 1 P

25 USING THE PUMPING LEMMA Use the pumping lemma to prove that B = {0 n 1 n | n ≥ 0} is not regular Hint: Assume B is regular, and try pumping s = 0 P 1 P If B is regular, s can be split into s = xyz, where for any i ≥ 0, xy i z is also in B If y is all 0s: xyyz has more 0s than 1s If y is all 1s: xyyz has more 1s than 0s If y has both 1s and 0s: xyyz will have some 1s before some 0s

26 Use the pumping lemma to prove that C = { w | w has an equal number of 0s and 1s} is not regular Hint: Try pumping s = 0 P 1 P If C is regular, s can be split into s = xyz, where for any i ≥ 0, xy i z is also in C and |xy| ≤ P

27 WHAT DOES D LOOK LIKE? (0(0  1)*0)  (1(0  1)*1)  1  0  ε D = { w | w has equal number of occurrences of 01 and 10} = { w | w = 1, w = 0, w = ε or w starts with a 0 and ends with a 0 or w starts with a 1 and ends with a 1 }

28 REGULAR EXPRESSIONS  is a regular expression representing {  } ε is a regular expression representing {ε}  is a regular expression representing  If R 1 and R 2 are regular expressions representing L 1 and L 2 then: (R 1 R 2 ) represents L 1  L 2 (R 1  R 2 ) represents L 1  L 2 (R 1 )* represents L 1 *

29 PRECEDENCE Tightest Star (“*”) Concatenation (“.”, “”) LoosestUnion (“  ”, “+”, “|”)

30 R2R2 R1*R1*( EXAMPLE R 1 *R 2  R 3 = ())  R3R3

31 { w | w has exactly a single 1 } 0*10*

32 What language does  * represent? {ε}{ε}

33 { w | w has length ≥ 3 and its 3rd symbol is 0 } 000(0  1)*  010(0  1)*  100(0  1)*  110(0  1)* = (0  1)(0  1)0(0  1)*

34 { w | every odd position of w is a 1 } 1((0  1)1)*(0  1  ε)  ε Also (1(0  1))*(1  ε)

35 EQUIVALENCE L can be represented by a regexp  L is a regular language

36 L can be represented by a regexp  L is a regular language Given regular expression R, we show there exists NFA N such that R represents L(N) Induction on the length of R:

37 Given regular expression R, we show there exists NFA N such that R represents L(N) Induction on the length of R: Base Cases (R has length 1): R =  (matches a single symbol)  R = ε (matches the empty string) R =  (matches nothing)

38 Inductive Step: Assume R has length k > 1 and that any regular expression of length < k represents a language that can be recognized by an NFA Three possibilities for R: R = R 1  R 2 R = R 1 R 2 R = (R 1 )* (Union Theorem!)

39 L can be represented by a regexp  L is a regular language Have Shown

40 Transform (1(0  1))* to an NFA 1ε1,0 ε

41 L can be represented by a regexp  L is a regular language 

42 L can be represented by a regexp  L is a regular language  Proof idea: Transform an NFA for L into a regular expression by removing states and re- labeling the arrows with regular expressions

43 NFA ε ε ε ε ε Add unique and distinct start and accept states While machine has more than 2 states: Pick an internal state, rip it out and re-label the arrows with regexps, to account for the missing state 0 1 0

44 NFA ε ε ε ε ε While machine has more than 2 states: Pick an internal state, rip it out and re-label the arrows with regexps, to account for the missing state 01*0

45 q1q1 b a ε q2q2 a,b ε q0q0 q3q3 R(q 0,q 3 ) = (a*b)(a  b)*

46 q2q2 a,b ε a*b q0q0 q3q3 R(q 0,q 3 ) = (a*b)(a  b)*

47 (a*b)(a  b)* q0q0 q3q3 R(q 0,q 3 ) = (a*b)(a  b)*

48 q3q3 q2q2 b a b q1q1 b a a ε ε ε bb

49 q2q2 b a b q1q1 a a ε ε ε bb a  ba b

50 bb  (a  ba)b*a a  ba q2q2 b q1q1 a ε ε bb b b  (a  ba)b* = R(q 1,q 1 ) (bb  (a  ba)b*a)* (b  (a  ba)b*)

51 Convert the NFA to a regular expression q3q3 q2q2 b b q1q1 a a, b ε ε ε b (a  b)b*b bb*b (a  b)b*b(bb*b)* (a  b)b*b(bb*b)*a

52 ((a  b)b*b(bb*b)*a)*  ((a  b)b*b(bb*b)*a)*(a  b)b*b(bb*b)*

53 Formally: Run CONVERT(G): (return regexp) If #states = 2 return the expression on the arrow going from q start to q accept Add q start and q accept to create G If #states > 2

54 Formally:Add q start and q accept to create G If #states > 2 select q rip  Q different from q start and q accept define Q = Q – {q rip } define R as: R(q i,q j ) = R(q i,q rip )R(q rip,q rip )*R(q rip,q j )  R(q i,q j ) return CONVERT(G) Run CONVERT(G): (return regexp) } Defines: G (GNFA)

55 CONVERT(G) is “equivalent” to G Proof by induction on k (number of states in G) Base Case: k = 2 Inductive Step: Assume claim is true for k-1 states We first note that G and G are “equivalent” But, by the induction hypothesis, G is “equivalent” to CONVERT(G) And CONVERT(G) is equivalent to CONVERT(G ) QED

56 ε

57 DFA NFA Regular Language Regular Expression DEF

58 Read Chapter 1.3 of the book for next time