Recursive Definations Regular Expressions Ch # 4 by Cohen

Slides:



Advertisements
Similar presentations
Theory Of Automata By Dr. MM Alam
Advertisements

Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
1 Regular Expressions/Languages Regular languages –Inductive definitions –Regular expressions syntax semantics Not covered in lecture.
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
L ECTURE 2 Chapter 3 Recursive Definitions. R ECURSIVE D EFINITION It is method of defining sets.
Theory Of Automata By Dr. MM Alam
Chapter 2 Languages.
Theory Of Automata By Dr. MM Alam
Lecture # 1 (Automata Theory)
Theory of Automata.
1 Welcome to ! Theory Of Automata. 2 Text and Reference Material 1.Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons, Inc., 1991,
Module 2 How to design Computer Language Huma Ayub Software Construction Lecture 7 1.
CSC312 Automata Theory Lecture # 2 Languages.
CSC312 Automata Theory Lecture # 2 Languages.
Formal Methods in SE Theory of Automata Qasiar Javaid Assistant Professor Lecture # 06.
Lecture Two: Formal Languages Formal Languages, Lecture 2, slide 1 Amjad Ali.
CMSC 330: Organization of Programming Languages Theory of Regular Expressions.
Two examples English-Words English-Sentences alphabet S ={a,b,c,d,…}
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
1 Language Definitions Lecture # 2. Defining Languages The languages can be defined in different ways, such as Descriptive definition, Recursive definition,
Recap Lecture-2 Kleene Star Closure, Plus operation, recursive definition of languages, INTEGER, EVEN, factorial, PALINDROME, {anbn}, languages of strings.
1 INFO 2950 Prof. Carla Gomes Module Modeling Computation: Language Recognition Rosen, Chapter 12.4.
Automata, Computability, & Complexity by Elaine Rich ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Slides provided by author Slides edited for.
1 Chapter 1 Introduction to the Theory of Computation.
Lecture # 3 Regular Expressions 1. Introduction In computing, a regular expression provides a concise and flexible means to "match" (specify and recognize)
Module 2 How to design Computer Language Huma Ayub Software Construction Lecture 8.
Lecture-2 Recap Lecture-1
L ECTURE 3 Chapter 4 Regular Expressions. I MPORTANT T ERMS Regular Expressions Regular Languages Finite Representations.
Introduction to Theory of Automata By: Wasim Ahmad Khan.
1 Module 14 Regular languages –Inductive definitions –Regular expressions syntax semantics.
Recursive Definitions & Regular Expressions (RE)
Regular Expressions CIS 361. Need finite descriptions of infinite sets of strings. Discover and specify “regularity”. The set of languages over a finite.
MA/CSSE 474 Theory of Computation Regular Expressions Intro.
Regular Expressions and Languages A regular expression is a notation to represent languages, i.e. a set of strings, where the set is either finite or contains.
Regular Expressions Chapter 6 1. Regular Languages Regular Language Regular Expression Finite State Machine L Accepts 2.
Lecture 02: Theory of Automata:08 Theory of Automata.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University 2010.
CSC312 Automata Theory Lecture # 3 Languages-II. Formal Language A formal language is a set of words—that is, strings of symbols drawn from a common alphabet.
Lecture 04: Theory of Automata:08 Transition Graphs.
Lecture # Book Introduction to Theory of Computation by Anil Maheshwari Michiel Smid, 2014 “Introduction to computer theory” by Daniel I.A. Cohen.
Lecture # 4.
Mathematical Foundations of Computer Science Chapter 3: Regular Languages and Regular Grammars.
Lecture 2 Theory of AUTOMATA
Recursive Definitions and Regular Expression RD -- A method of defining sets RE -- A concise way of expressing a pattern in a language.
1 Chapter 3 Regular Languages.  2 3.1: Regular Expressions (1)   Regular Expression (RE):   E is a regular expression over  if E is one of:
Week 13 - Wednesday.  What did we talk about last time?  Exam 3  Before review:  Graphing functions  Rules for manipulating asymptotic bounds  Computing.
Lecture 02: Theory of Automata:2014 Asif Nawaz Theory of Automata.
Set, Alphabets, Strings, and Languages. The regular languages. Clouser properties of regular sets. Finite State Automata. Types of Finite State Automata.
Lecture 03: Theory of Automata:2014 Asif Nawaz Theory of Automata.
CHAPTER TWO LANGUAGES By Dr Zalmiyah Zakaria.
By Dr.Hamed Alrjoub. 1. Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons, Inc., 1991, Second Edition 2. Introduction to Languages.
Lecture 01: Theory of Automata:2013 Asif Nawaz Theory of Automata.
MA/CSSE 474 Theory of Computation Regular Expressions Intro.
Recap Lecture 3 RE, Recursive definition of RE, defining languages by RE, { x}*, { x}+, {a+b}*, Language of strings having exactly one aa, Language of.
Lecture 17: Theory of Automata:2014 Context Free Grammars.
Recap lecture 5 Different notations of transition diagrams, languages of strings of even length, Odd length, starting with b, ending in a (with different.
Theory of Computation Lecture #
Lecture # 2.
Theory of Automata.
Regular Expressions (Examples)
LANGUAGES Prepared by: Paridah Samsuri Dept. of Software Engineering
CSC312 Automata Theory Lecture # 4 Languages-III.
Recap Lecture-2 Kleene Star Closure, Plus operation, recursive definition of languages, INTEGER, EVEN, factorial, PALINDROME, {anbn}, languages of strings.
Recap Lecture-2 Kleene Star Closure, Plus operation, recursive definition of languages, INTEGER, EVEN, factorial, PALINDROME, {anbn}, languages of strings.
CSC312 Automata Theory Lecture # 3 Languages-II.
Welcome to ! Theory Of Automata Irum Feroz
Recap Lecture 3 RE, Recursive definition of RE, defining languages by RE, { x}*, { x}+, {a+b}*, Language of strings having exactly one aa, Language of.
LECTURE # 07.
Presentation transcript:

Recursive Definations Regular Expressions Ch # 4 by Cohen CSC312 Automata Theory Lecture # 4 Recursive Definations Regular Expressions Ch # 4 by Cohen

Recursive Language Definition A recursive definition is characteristically a three-step process: 1. First, we specify some basic objects in the set. The number of basic objects specified must be finite. 2. Second, we give a finite number of rules for constructing more objects in the set from the ones we already know. 3. Third, we declare that no objects except those constructed in this way are allowed in the set.

Example: Example: Consider the set P-EVEN, which is the set of positive even numbers. We can define the set P-EVEN in several different ways: • We can define P-EVEN to be the set of all positive integers that are evenly divisible by 2. • P-EVEN is the set of all 2n, where n = 1, 2, . . .. P-EVEN is defined by these three rules: Rule 1 2 is in P-EVEN. Rule 2 If x is in P-EVEN, then so is x + 2. Rule 3 The only elements in the set P-EVEN are those that can be produced from the two rules above.

Example: Example: Let PALINDROME be the set of all strings over the alphabet = {a, b} that are the same spelled forward as backwards; i.e., PALINDROME = {w : w = reverse(w)} = {, a, b, aa, bb, aaa, aba, bab, bbb, aaaa, abba, . . .}.

Recursive Definition of PALINDROME A recursive definition for PALINDROME is as follows: Rule 1 , a, and b are in PALINDROME. Rule 2 If w 2 PALINDROME, then so are awa and bwb. Rule 3 No other string is in PALINDROME unless it can be produced by rules 1 and 2.

Arithmetic Expressions(AE) We recursively define AE using the following rules: What are the rules?

Recursive Definition of AE Rule 1: Any number (positive, negative, or zero) is in AE. Rule 2: If x is in AE, then so are (i) (x) (ii) -x (provided that x does not already start with a minus sign) Rule 3: If x and y are in AE, then so are (i) x + y (if the first symbol in y is not + or -) (ii) x - y (if the first symbol in y is not + or -) (iii) x * y (iv) x / y (v) x ** y (our notation for exponentiation) Theory Of Automata

For instance, we wish to determine if the following expression is The above definition is the most natural, because it is the method we use to recognize valid arithmetic expressions in real life. For instance, we wish to determine if the following expression is valid: (2 + 4) * (7 * (9 - 3)/4)/4 * (2 + 8) - 1 We do not really scan over the string, looking for forbidden substrings or count the parentheses. We actually imagine the expression in our mind broken down into components: Is (2 + 4) OK? Yes Is (9 - 3) OK? Yes Theory Of Automata

Arithmetic Expression AE Obviously, the following expressions are not valid: (3 + 5) + 6) 2(/8 + 9) (3 + (4-)8) The first contains unbalanced parentheses; the second contains the forbidden substring /; the third contains the forbidden substring -). Are there more rules? The substrings // and */ are also forbidden. Are there still more? The most natural way of defining a valid AE is by using a recursive definition, rather than a long list of forbidden substrings. Theory Of Automata

Regular Expressions (REs) Any language-defining symbols generated according to some rule are called regular expressions OR a regular expression is a pattern describing a certain amount of text OR A regular expression represents a "pattern“; strings that match the pattern are in the language, strings that do not match the pattern are not in the language. Regular expressions describe regular languages.

Regular Expressions Example: describes the language Not a regular expression:

REs Here instead of applying Kleene Star Operation (KSO) over some set S, we shall straight away apply KSO on some alphabet say “a” and write it as “a*” which means a* = , a, aa, aaa, ……. And Kleene plus closure is a+ = a, aa, aaa, ……. Where a+ = aa* a* =  + a+

Operators allowed in REs Every RE can contains concatenation “dot” operator, + i.e. logical operator “or”, Kleene Star Closure, Kleene Plus Closure and parenthesis only. Precedence of Operators: The Kleene Star (or Kleene Plus) operator has highest precedence. Next come the precedence of concatenation or “dot” operator. The union or + operator has the lowest priority.

Primitive REs Primitive regular expressions: Thus, if |Σ| = n, then there are n+2 primitive regular expressions defined over Σ . Given regular expressions and Are regular expressions

Languages of Regular Expressions : language of regular expression Example: The languages defined by the primitive regular expressions are: (i) The primitive regular expression  denotes the language {}. There are no strings in this language. (ii) The primitive regular expression  denotes the language {}. The only string in this language is the empty string or the string with no letters. (iii) For each x  Σ , the primitive regular expression x denotes the language {x} i.e. the only string in the language is the string "x".

If r and  are REs then r +  = r and r =  Note: The language  is the language with no words and for REs, the  is the regular expression for the null language. If r and  are REs then r +  = r and r = 

Languages of Regular Expressions Example: Consider the alphabet Σ={a} The language of all words containing even number of a’s can be defined by the following RE (aa)* Example: Language of all words containing only odd no. of a’s can be defined by the following RE 1. (aaa)* 2. a(aa)*+ 3. a+(aa)* 4. a+a* 5. a+(aa)*a correct but inefficient due to repetition 6. (aa)*a or a(aa)* correct

Languages of Regular Expressions Example: The language of all words having all possible combinations of a’s followed by one b can be described by the following RE. 1. a+b 2. a*+b 3. a*b 4. (+a+)b 5. a+b+b Example: The language of all words in which all a’s (if any) comes before all the b’s (if any) can be defined the following RE (ab)* 2. a*b* 3. a+b+a+b++ 4. b+a+b*+ both are inefficient

Example:The language of all words of a’s & b’s that have atleast two letters, that begin & end with a’s & that have nothing but b’s inside (if any thing at all) can be defined by following RE. Σ = {a, b} (aba)* 2. ab*a+ 3. ab+a 4. a+b*a+ all above are incorrect 5. ab*a

Example: Consider the alphabet Σ={a,b,c} Example: Consider the alphabet Σ={a,b,c}. The language of all words that begins with either a or c, followed be any no. of b’s can be defined by following RE. (a+c)b* = ab* + cb* Example: The language of all words that ends with letter b can be defined by the following RE (a+b)*b

Example: The language of all words that have at least 1 a in them somewhere can be defined be by RE (a+b)*a(a+b)* Example:The language of all words that have at least 2 a’s in them somewhere. (a+b)*a(a+b)*a(a+b)* OR b*ab*a(a+b)* OR b*a(a+b)*ab* OR (a+b)*ab*ab*

Example: The language of all words that have exactly 2 a’s in them somewhere can be defined by RE b*ab*ab* Example: The language of all words that have at most one a in them somewhere can be defined by RE b*(a+)b* OR b*ab* + b*

Example: The language of all words having at least one a and one b, may be expressed by the following RE (a+b)*a(a+b)*b(a+b)* + (a+b)*b(a+b)*a(a+b)* Example: The language of all words starting with a and ending in b or starting with b and ending in a, may be expressed by the following RE a(a+b)*b + b(a+b)*a

Example: The language of all strings that at some point contain a double letter, may be expressed by the following RE (a + b)*(aa + bb)(a + b)* Example: The language of all strings that do not contain a double letter, may be expressed by the following RE ( + b) (ab)*( + a)

Definition For regular expressions and

Example Regular expression:

Example Regular expression

Example = { all strings with at least two consecutive 0 } = { all strings without two consecutive 0 }