1 Section 11.1 Regular Languages Problem: Suppose the input strings to a program must be strings over the alphabet {a, b} that contain exactly one substring.

Slides:



Advertisements
Similar presentations
Properties of Regular Languages
Advertisements

L ECTURE 3 T HEORY OF AUTOMATA. E QUIVALENT R EGULAR E XPRESSIONS Definition Two regular expressions are said to be equivalent if they generate the same.
1 Pushdown Automata (PDA) Informally: –A PDA is an NFA-ε with a stack. –Transitions are modified to accommodate stack operations. Questions: –What is a.
COMP-421 Compiler Design Presented by Dr Ioanna Dionysiou.
Equivalence, Order, and Inductive Proof
3.2 Pumping Lemma for Regular Languages Given a language L, how do we know whether it is regular or not? If we can construct an FA to accept the language.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Regular Grammars Formal definition of a regular expression.
Vocabulary and Properties. Determine the word or phrase described in each slide.
Strings and Languages Operations
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Regular.
CS5371 Theory of Computation Lecture 6: Automata Theory IV (Regular Expression = NFA = DFA)
79 Regular Expression Regular expressions over an alphabet  are defined recursively as follows. (1) Ø, which denotes the empty set, is a regular expression.
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 Expressions/Languages Regular languages –Inductive definitions –Regular expressions syntax semantics Not covered in lecture.
Nondeterminism (Deterministic) FA required for every state q and every symbol  of the alphabet to have exactly one arrow out of q labeled . What happens.
Lecture 1 String and Language. String string is a finite sequence of symbols. For example, string ( s, t, r, i, n, g) CS4384 ( C, S, 4, 3, 8) (1,
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
Theory of computing, part 1. Von Neumann Turing machine Finite state machines NP complete problems -maximum clique -travelling salesman problem -colour.
Regular Expressions and Finite State Automata  Themes  Finite State Automata (FSA)  Describing patterns with graphs  Programs that keep track of state.
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,
Automata, Computability, & Complexity by Elaine Rich ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Slides provided by author Slides edited for.
1 Chapter 1 Introduction to the Theory of Computation.
Module 2 How to design Computer Language Huma Ayub Software Construction Lecture 8.
L ECTURE 3 Chapter 4 Regular Expressions. I MPORTANT T ERMS Regular Expressions Regular Languages Finite Representations.
1 Module 14 Regular languages –Inductive definitions –Regular expressions syntax semantics.
Lexical Analyzer in Perspective
Objective The student will be able to: recognize and use the commutative and associative properties and the properties of equality.
Recursive Definitions & Regular Expressions (RE)
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.
Specifying Languages Our aim is to be able to specify languages for use in the computer. The sketch of an FSA is easy for us to understand, but difficult.
Brian Mitchell - Drexel University MCS680-FCS 1 Patterns, Automata & Regular Expressions int MSTWeight(int graph[][], int size)
1 Section 4.3 Order Relations A binary relation is an partial order if it transitive and antisymmetric. If R is a partial order over the set S, we also.
CS 203: Introduction to Formal Languages and Automata
Laws of Boolean Algebra Commutative Law Associative Law Distributive Law Identity Law De Morgan's Theorem.
Context-Free Languages
Slide Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Lecture 8 NFA Subset Construction & Epsilon Transitions
1 Section 6.2 Propositional Calculus Propositional calculus is the language of propositions (statements that are true or false). We represent propositions.
Strings and Languages Denning, Section 2.7. Alphabet An alphabet V is a finite nonempty set of symbols. Each symbol is a non- divisible or atomic object.
Mathematical Foundations of Computer Science Chapter 3: Regular Languages and Regular Grammars.
1 Chapter Constructing Efficient Finite Automata.
1 Chapter Regular Languages. 2 Section 11.1 Regular Languages Problem: Suppose the input strings to a program must be strings over the alphabet.
Algebra 1 – 2.5 Matching slides. 1.The order in which you add numbers in a sum doesn’t matter. 2.If you add more than 2 numbers, the order in which you.
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:
 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.
A new Computation System DFAs, NFs, Λ-NFAs all describe a language in an operational manner. They describe a machine that one can execute in order to recognize.
1 Section 11.3 Constructing Efficient Finite Automata First we’ll see how to transform an NFA into a DFA. Then we’ll see how to transform a DFA into a.
1 Section 11.2 Finite Automata Can a machine(i.e., algorithm) recognize a regular language? Yes! Deterministic Finite Automata A deterministic finite automaton.
Lecture 02: Theory of Automata:2014 Asif Nawaz Theory of Automata.
MA/CSSE 474 Theory of Computation Regular Expressions Intro.
Page 1. 1)Let B n = { a k | where k is a multiple of n}. I.e. B 1 = { a k | where k is a multiple of 1} = { a k | k Є {0,1,2,3,…}} = {‘’, a, aa, aaa, aaaa,
Chapter 1 INTRODUCTION TO THE THEORY OF COMPUTATION.
Pumping Lemma.
Lecture # 2.
Regular Languages, Regular Operations, Closure
Identity and Equality Properties
Closure Properties of Regular Languages
Formal Language & Automata Theory
Closure Properties of Regular Languages
REGULAR LANGUAGES AND REGULAR GRAMMARS
Pumping Lemma.
Specification of tokens using regular expressions
Closure Properties of Regular Languages
Closure Properties of Regular Languages
CSE322 Regular Expressions and their Identities
Name:______________________________ Date:________________
LECTURE # 07.
Presentation transcript:

1 Section 11.1 Regular Languages Problem: Suppose the input strings to a program must be strings over the alphabet {a, b} that contain exactly one substring bb. In other words, the strings must be of the form xbby, where x and y are strings over {a, b} that do not contain bb, x does not end in b, and y does not begin with b. In a few minutes, we’ll see how to describe the strings formally. A regular language over alphabet A is a language constructed by the following rules:  and {  } are regular languages. {a} is a regular language for all a  A. If M and N are regular language, then so are M  N, MN, and M*. Example. Let A = {a, b}. Then the following languages are a sampling of the regular languages over A: , {  }, {a}, {b}, {a, b}, {ab}, {a}* = { , a, aa, aaa, …, a n, … }. A regular expression over alphabet A is an expression constructed by the following rules:  and  are regular expressions. a is a regular expression for all a  A. If R and S are regular expressions, then so are (R), R + S, R·S, and R*. The hierarchy in the absence of parentheses is, * (do it first), ·, + (do it last). Juxtaposition will be used in place of ·. Example. Let A = {a, b}. Then the following expressions are a sampling of the regular expressions over A: , , a, b, ab, a + ab, (a + b)*.

2 Regular expressions represent regular languages Regular expressons represent regular languages by the following correspondence, where L(R) denotes the regular language of the regular expression R. L(  ) = , L(  ) = {  }, L(a) = {a} for all a  A, L(R + S) = L(R)  L(S), L(RS) = L(R)L(S), L(R*) = L(R)*. Example. The regular expression ab + a* represents the following regular language: L(ab + a*) = L(ab)  L(a*) = L(a)L(b)  L(a)* = {a}{b}  {a}* = {ab}  { , a, aa, aaa, …, a n, … } ={ab, , a, aa, aaa, …, a n, … }. Example. The regular expression (a + b)* represents the following regular language: L((a + b)*)= (L(a + b))* = {a, b}*, the set of all possible strings over {a, b}. Back to the Problem: Suppose the input strings to a program must be strings over the alphabet {a, b} that contain exactly one substring bb. In other words, the strings must be of the form xbby, where x and y are strings over {a, b} that do not contain bb, x does not end in b, and y does not begin with b. How can we describe the set of inputs formally? Solution: let x = (a + ba)* and y = (a + ab)*.

3 Quiz. Find a regular expresson for {ab n | n  N}  {ba n | n  N}. Answer. ab* + ba*. Quiz. Use a sentence to describe the language of (b + ab)*(  + a). Answer. All strings over {a, b} whose substrings of a’s have length 1. The Algebra of Regular Expressions Equality: Regular expressions R and S are equal, written R = S, when L(R) = L(S). Examples. a + b = b + a, a + a = a, aa* = a*a, ab ≠ ba. Properties of +, ·, and closure + is commutative, associative,  is identity for +, and R + R = R. · is associative,  is identity for ·, and  is zero for ·. · distributes over + (closure properties)  * =  * = . R* = R*R* = (R*)* = R + R*. R* =  + R* =  + RR* = (  + R)* = (  + R)R*. R* = (R + R 2 + … + R k )* =  + R + R 2 + … + R k–1 + R k R* for any k ≥ 1. R*R = RR*. (R + S)* = (R* + S*)* = (R*S*)* = (R*S)*R* = R*(SR*)*. R(SR)* = (RS)*R. (R*S)* =  + (R + S)*S and (RS*)* =  + R(R + S)*. Proof: All properties can be verified by showing that the underlying regular languages are equal as sets. QED.

4 Quiz. Explain each inequality. (1). (a + b)* ≠ a* + b*. (2) (a + b)* ≠ a*b*. Answers. (1) ab  L((a + b)*) – L(a* + b*). (2) ba  L((a + b)*) – L(a*b*). Quiz. Simplify the regular expression aa(b* + a) + a(ab* + aa). Answer. aa(b* + a) + a(ab* + aa) = aa(b* + a) + aa(b* + a)· distributes over + = aa(b* + a) R + R = R. Example/Quiz. Show that (a + aa)(a + b)* = a(a + b)*. Proof: (a + aa)(a + b)*= (a + aa)a*(ba*)* (R + S)* = R*(SR*)* = a(  + a)a*(ba*)*R = R  and · distributes over + = aa*(ba*)* (  + R)R* = R* = a(a + b)*(R + S)* = R*(SR*)* QED. Example/Quiz. Show that a*(b + ab*) = b + aa*b*. Proof: a*(b + ab*) = (  + aa*)(b + ab*)R* =  + RR* = b + ab* + aa*b + aa*ab*· distributes over + = b + (ab* + aa*ab*) + aa*b+ is commutative and associative = b + (  + aa*)ab* + aa*bR = R  and · distributes over + = b + a*ab* + aa*bR* =  + RR* = b + aa*b* + aa*bR*R = RR* = b + aa*(b* + b)· distributes over + = b + aa*b*. R* = R* + R QED.

5 Example. Show that a* + abb*a = a* + ab*a. Proof: Starting on the RHS, we have a* + ab*a= a* + a(  + bb*)a R* =  + RR* = a* + aa + abb*a · distributes over + = (  + aa*) + aa + abb*a R* =  + RR* =  + (aa* + aa) + abb*a + is associative =  + a(a* + a) + abb*a · distributes over + =  + aa* + abb*a R* = R + R* = a* + abb*a R* =  + RR* QED. Example. Show that (a + aa + … + a n )(a + b)* = a(a + b)* for all n ≥ 1. Proof (by induction): If n = 1, the statement becomes a(a + b)* = a(a + b)*, which is true. If n = 2, the statement becomes (a + aa)(a + b)* = a(a + b)*, which is true by a previous example. Let n > 2 and assume the statement is true for 1 ≤ k < n. We need to prove the statement is true for n. The LHS of the statement for n is (a + aa + … + a n )(a + b)* = a(a + b)* + (aa + … + a n )(a + b)* · distributes over + = a(a + b)* + a(a + aa + … + a n–1 )(a + b)* · distributes over + = a(a + b)* + aa(a + b)*induction assumption = (a + aa)(a + b)* · distributes over + = a(a + b)*induction assumption The last line is the RHS of the statement for n. So the statement is true for n. Therefore, the statement is true for all n ≥ 1. QED.

6 Example/Quiz: Use regular algebra to show that R + (R + S)* = (R + S)*. Proof: R + (R + S)*= R + [  + (R + S) + (R + S)(R+ S)*]R* =  + R + R 2 + … + R k–1 + R k R* =  + (R + R) + S + (R + S)(R+ S)*+ is associative =  + R + S + (R + S)(R+ S)*R + R = R =  + (R + S) + (R + S)(R+ S)*+ is associative = (R+ S)*R* =  + R + R 2 + … + R k–1 + R k R* QED. Take-home quiz: Use regular algebra to show that (a + ab)*a = a(a + ba)*.