CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.

Slides:



Advertisements
Similar presentations
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
Advertisements

Deterministic Finite Automata (DFA)
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
CSCI 2670 Introduction to Theory of Computing September 13, 2005.
CS21 Decidability and Tractability
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
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.
1 Introduction to Computability Theory Lecture4: Non Regular Languages Prof. Amos Israeli.
1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY (For next time: Read Chapter 1.3 of the book)
CS 310 – Fall 2006 Pacific University CS310 Pumping Lemma Sections:1.4 page 77 September 27, 2006.
CS5371 Theory of Computation Lecture 5: Automata Theory III (Non-regular Language, Pumping Lemma, Regular Expression)
1 Introduction to Computability Theory Lecture4: Non Regular Languages Prof. Amos Israeli.
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.
CS5371 Theory of Computation Lecture 6: Automata Theory IV (Regular Expression = NFA = DFA)
CS 490: Automata and Language Theory Daniel Firpo Spring 2003.
Courtesy Costas Busch - RPI1 Non-regular languages.
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.
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.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 5 School of Innovation, Design and Engineering Mälardalen University 2012.
Theory of Languages and Automata
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Closure.
Cs3102: Theory of Computation Class 6: Pushdown Automata Spring 2010 University of Virginia David Evans TexPoint fonts used in EMF. Read the TexPoint manual.
Prof. Busch - LSU1 NFAs accept the Regular Languages.
CSCI 2670 Introduction to Theory of Computing September 1, 2005.
CHAPTER 1 Regular Languages
CS 3240 – Chapter 4.  Closure Properties  Algorithms for Elementary Questions:  Is a given word, w, in L?  Is L empty, finite or infinite?  Are L.
Formal Definition of Computation Let M = (Q, ∑, δ, q 0, F) be a finite automaton and let w = w 1 w w n be a string where each wi is a member of the.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
CS355 - Theory of Computation Regular Expressions.
Conversions & Pumping Lemma CPSC 388 Fall 2001 Ellen Walker Hiram College.
CSCI 2670 Introduction to Theory of Computing September 13.
CS 203: Introduction to Formal Languages and Automata
Computability Regular expressions. Languages defined by regular expresses = Regular languages (languages recognized by FSM). Applications. Pumping lemma.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 1 Regular Languages Some slides are in courtesy.
Great Theoretical Ideas in Computer Science for Some.
Finite Automata Great Theoretical Ideas In Computer Science Victor Adamchik Danny Sleator CS Spring 2010 Lecture 20Mar 30, 2010Carnegie Mellon.
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.
Regular Languages Chapter 1 Giorgi Japaridze Theory of Computability.
Theory of Computation Automata Theory Dr. Ayman Srour.
CSE 105 theory of computation
CSE 105 theory of computation
Foundations of Computing Science
CIS Automata and Formal Languages – Pei Wang
PROPERTIES OF REGULAR LANGUAGES
Formal Language & Automata Theory
CSE 105 theory of computation
CSE 105 theory of computation
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
CS21 Decidability and Tractability
Chapter 1 Regular Language - 02
CSE 105 theory of computation
Chapter 1 Regular Language
CHAPTER 1 Regular Languages
NFAs accept the Regular Languages
CSCI 2670 Introduction to Theory of Computing
CSE 105 theory of computation
Presentation transcript:

CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics

Automata Theory Regular Expressions

Regular expressions Recall: a language is a set of strings Regular expressions: A notation for building up languages Example: (0 U 1) 0* 0 and 1 are shorthand for {0} and {1} So (0 U 1) = {0} U {1} = {0,1} 0* is {0}*={ ε, 0, 00, 000, 0000, 00000, ,… } Concatenation (o), like multiplication is implicit  (0 U 1) 0* is the language of all strings starting with 0 or 1 followed by any number of 0’s Usually used in text editors or shell script Lexical analyzer in any compiler

More examples Let ∑be an alphabet The regular expression ∑ is a language of one symbol strings ∑* is all strings ∑*1 is all strings ending in 1 0∑*U ∑*1 is all strings starting in 0 or ending in 1

operations Four operations Star (highest precedence) Concatenation Union (least precedence) Parenthesis used to change usual precedence

Formal definition: regular expression Inductive definition R is a regular expression if R is a for some a in ∑ ε Ø (R1 U R2) and R1 and R2 are regular expressions (R1 o R2) and R1 and R2 are regular expressions (R1*) and R1 is a regular expression

Formal definition Let L(R) denote the language defined by regular expression R L(R) is defined as shown in Table RL(R) a{a} ØØ ε {ε}{ε} (R1 U R2)L(R1) U L(R2) (R1 o R2)L(R1) o L(R2) (R1)*L(R1)*

Remarkable fact Theorem: A language is regular if and only if some regular expression describes it. This theorem states two things If a language is described by a regular expression, then it is regular (  ) If a language is regular, then it can be described by a regular expression (  )

Proof (  ) If a language is described by a regular expression, then it is regular (  ) Given a regular expression describing some language A, we show how to convert R into a NFA recognizing A By previous result: If an NFA recognizes A, then A is regular

NFA accepting regular expression R = a Є ∑ q1 q2 a

NFA accepting regular expression R = ε

NFA accepting regular expression R = Ø

NFA accepting regular expression R = (R1 U R2)

NFA accepting regular expression R = (R1 U R2) ε ε

NFA accepting regular expression R = (R1 o R2)

NFA accepting regular expression R = (R1 o R2) ε ε

NFA accepting regular expression R = (R1)*

NFA accepting regular expression R = (R1)* ε ε ε

Example R = a q1 q2 a

Example R = b q1 q2 b

Example R = ab b a ε

Example R = ab U a b a ε a ε ε

Example R = (ab U a)* b a ε a ε ε ε ε ε

Nonregular languages We have made a lot of progress understanding what finite automata can do But, what can’t they do?

Limitations of finite automata B={0 n 1 n | 0 ≤ n } Examples: 01, 0011, ,…. Machines must “remember” how many 0s have been seen so far as it reads the input! Impossible with finite automata Because the number of 0s isn’t limited, the machine will have to keep track of an unlimited number of possibilities (states!)

Limitations of finite automata C={w | w has an equal number of 0s and 1s} Examples: 01, , ,…. Machines must “remember” how many 0s and 1s have been seen so far as it reads the input! Impossible with finite automata Because the number of 0s and 1s isn’t limited, the machine will have to keep track of an unlimited number of possibilities (states!)

Limitations of finite automata D={w | w has an equal number of occurrences of 01 and 10 as substrings} Examples: 00, , ,…. Machines must “remember” how many 01s and 10s have been seen so far as it reads the input! Impossible with finite automata Because the number of 01s and 10s isn’t limited, the machine will have to keep track of an unlimited number of possibilities (states!)

Limitations of finite automata D={w | w has an equal number of occurrences of 01 and 10 as substrings} Examples: 00, , ,…. Machines must “remember” how many 01s and 10s have been seen so far as it reads the input! Impossible with finite automata Because the number of 01s and 10s isn’t limited, the machine will have to keep track of an unlimited number of possibilities (states!)

Limitation of finite automata Our intuition may fail us (remember language D) So, how to prove that a certain language is not regular? Pumping Lemma

Pumping lemma We will show that all regular languages have a special property If a string is longer than a certain critical length l, then it can be “pumped” to a larger length by repeating an internal substring This is a powerful technique for showing that a language is not regular!

Pumping lemma Theorem: If A is a regular language, then there is a number p (the pumping length) where, if s is any string of length at least p, then s may be divided into three pieces, s= xyz, such that  For each 0 ≤ i, xy i z Є A 2. |y| > 0 3. |xy| ≤ p

Pumping lemma Theorem: If A is a regular language, then there is a number p (the pumping length) where, if s is any string of length at least p, then s may be divided into three pieces, s= xyz, such that  For each 0 ≤ i, xy i z Є A : note that y 0 is ε 2. |y| > 0: without this the theorem is trivially true! 3. |xy| ≤ p : x and y together should not have a length bigger than p

How to use the pumping lemma To show that language A is not regular Approach: Proof by contradiction Assume A is regular in order to obtain a contradiction Use the pumping lemma to guarantee the existence of pumping length p Find a string s of length p or more that cannot be pumped Demonstrate that s cannot be pumped by considering all possible ways of dividing s into x, y, and z, and for each division find an i where xy i z does not belong to A

Application Prove that B={0 n 1 n | 0 ≤ n } is not regular Assume B is regular Because of pumping lemma, we have the pumping length p Now consider string s to be 0 p 1 p Theorem says s=xyz, where xy i z belongs to B y is all 0s in s, then we have too many 0’s in xy i z y is all 1s in s, then we have too many 1’s in xy i z y is mixed of 0s followed by 1s in s, then xy i z will have 0s and 1s out of order

Another Application Prove that C={w| w has an equal number of os and 1s} is not regular Assume C is regular Because of pumping lemma, we have the pumping length p Now consider string s to be 0 p 1 p Theorem says s=xyz, where xy i z belongs to C y is all 0s in s, then we have too many 0’s in xy i z y is all 1s in s, then we have too many 1’s in xy i z y is mixed of 0s and 1s in s, then by condition 3, we have |xy| is less than or equal to p, so y will have only 0s

Conclusions Regular expression closure properties union concatenation star Non-regular languages pumping lemma Next: Context-free grammars