Section 11.4 Regular Language Topics

Slides:



Advertisements
Similar presentations
1 Chapter Parsing Techniques. 2 Section 12.3 Parsing Techniques We know (via a theorem) that the context- free languages are exactly those languages.
Advertisements

CSE 311 Foundations of Computing I
Theory Of Automata By Dr. MM Alam
Lecture 8 From NFA to Regular Language. Induction on k= # of states other than initial and final states K=0 a a* b a c d c*a(d+bc*a)*
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.
CS 310 – Fall 2006 Pacific University CS310 Pumping Lemma Sections:1.4 page 77 September 27, 2006.
1 More Properties of Regular Languages. 2 We have proven Regular languages are closed under: Union Concatenation Star operation Reverse.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
Costas Busch - RPI1 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars.
CS5371 Theory of Computation Lecture 5: Automata Theory III (Non-regular Language, Pumping Lemma, Regular Expression)
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.
1 Regular Grammars Generate Regular Languages. 2 Theorem Regular grammars generate exactly the class of regular languages: If is a regular grammar then.
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.
Courtesy Costas Busch - RPI1 Non-regular languages.
Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars.
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 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.
Finite State Machines Data Structures and Algorithms for Information Processing 1.
Chapter 12: Context-Free Languages and Pushdown Automata
Problem of the DAY Create a regular context-free grammar that generates L= {w  {a,b}* : the number of a’s in w is not divisible by 3} Hint: start by designing.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
1 Let L= { w= u v : u  {a, b}*, v  {c, d}* and |u|= |v|} 1.Design a context-free grammar that generates L. 2.Use your grammar and the construction from.
1 Chapter Regular Language Topics. 2 Section 11.4 Regular Language Topics Regular languages are also characterized by special grammars called regular.
Section 12.4 Context-Free Language Topics
1 Section 12.3 Context-Free Parsing We know (via a theorem) that the context-free languages are exactly those languages that are accepted by PDAs. When.
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.
Class Discussion Can you draw a DFA that accepts the language {a k b k | k = 0,1,2,…} over the alphabet  ={a,b}?
Properties of Regular Languages
Chapter 6 Properties of Regular Languages. 2 Regular Sets and Languages  Claim(1). The family of languages accepted by FSAs consists of precisely the.
Conversions & Pumping Lemma CPSC 388 Fall 2001 Ellen Walker Hiram College.
CS 203: Introduction to Formal Languages and Automata
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University 2006.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
Regular Grammars Reading: 3.3. What we know so far…  FSA = Regular Language  Regular Expression describes a Regular Language  Every Regular Language.
Chapter 8 Properties of Context-free Languages These class notes are based on material from our textbook, An Introduction to Formal Languages and Automata,
1 Find as many examples as you can of w, x, y, z so that w is accepted by this DFA, w = x y z, y ≠ ε, | x y | ≤ 7, and x y n z is in L for all n ≥ 0.
1 Chapter Constructing Efficient Finite Automata.
CS 154 Formal Languages and Computability February 11 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
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.
Regular Languages Chapter 1 Giorgi Japaridze Theory of Computability.
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.
1 Chapter Pushdown Automata. 2 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations.
Compiler Construction Lecture Five: Parsing - Part Two CSC 2103: Compiler Construction Lecture Five: Parsing - Part Two Joyce Nakatumba-Nabende 1.
1 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations pop, push, and nop. PDAs always.
Nonregular Languages Section 2.4 Wed, Oct 5, 2005.
Formal Language & Automata Theory
Standard Representations of Regular Languages
CSE322 PUMPING LEMMA FOR REGULAR SETS AND ITS APPLICATIONS
Context-Free Grammars: an overview
PROPERTIES OF REGULAR LANGUAGES
Complexity and Computability Theory I
NPDAs Accept Context-Free Languages
CSE 3813 Introduction to Formal Languages and Automata
CS314 – Section 5 Recitation 3
PDAs Accept Context-Free Languages
Infiniteness Test The Pumping Lemma Nonregular Languages
CHAPTER 2 Context-Free Languages
Deterministic PDAs - DPDAs
Elementary Questions about Regular Languages
Non-regular languages
Chapter 4 Properties of Regular Languages
Midterm (Models of Computation, Fall, 2000)
CS21 Decidability and Tractability
Applications of Regular Closure
CHAPTER 1 Regular Languages
Presentation transcript:

Section 11.4 Regular Language Topics Regular languages are also characterized by special grammars called regular grammars whose productions take the following form, where w is a string of terminals. A  wB or A  w. Example. A regular grammar for the language of a*b* is S  L | aS | T T  b | bT. Quiz. Write a regular grammar for {ab, acb, accb. …, acnb, …}. Solution: A regular expression for the language is ac*b. A regular grammar is S  aT T  b | cT. Regular grammars as we have defined them are often called right-regular because there are also left-regular grammars that require productions to have the form A  Bw or A  w. Any language with a right-regular grammar also has a left-regular grammar, and conversely. Example. For the regular expression a*bc* we have the following grammars. Right regular: S  aS | bT T  L | cT. Left Regular: S  Sc | Tb T  L | Ta.

Notice in the previous example that right-regular grammars derive strings by examining the leftmost letter first, while left-regular grammars examine the rightmost letter first. Example/Quiz. Find a right-regular grammar and a left-regular grammar for the language of the regular expression a(b + c)*de*. Right regular: S  aT T  bT | cT | dU U  L | eU. Left Regular: S  Se | Td T  a | Tb | Tc. Transforming an NFA to a Regular Grammar State names become the nonterminals. So rename them to be uppercase letters. 2. The start state becomes the start symbol of the grammar. 3. For each state transition from I to J labeled with x construct a production I  xJ. 4. For each final state F construct a production F  L. Example/Quiz. Transform the following NFA into a regular grammar. Solution: S  aI | F I  aI | bF F  L This grammar can be simplified to S  aI | L I  aI | b Start S F I L b a

Example/Quiz. Transform the regular expression a. (ba) Example/Quiz. Transform the regular expression a*(ba)* into a regular grammar. Solution: Draw an NFA and then use the algorithm. Start S I a b F J An NFA: The resulting grammar: S  aS | bI | L I  aF F  bJ | L J  aF. Quiz. Simplify the grammar. Answer: S  aS | baF | L F  baF | L Start S F J a b E a, b Quiz. What happens when a DFA has an error state, like the following DFA? Answer: The resulting grammar: S  aF | bE F  aE | bJ | L J  aF | bE E  aE | bE. But E does not derive a terminal string. So the grammar simplifies to S  aF F  bJ | L J  aF. Quiz: Simplify the grammar further. Answer: S  aF F  baF | L.

Transforming a Regular Grammar to an NFA 1. Replace any production with multiple terminals by productions with single terminals. 2. The start state is the grammar start symbol. 3. Transform I  aJ into a transition from I to J labeled with a. 4. Transform I  J into a transition from I to J labeled with L. 5. Transform each I  a into a transition from I to new single final state F labeled with a. 6. The final states are F together with each state I with a production I  L. Example/Quiz. Transform the following regular grammar into a NFA. S  abS | T | L T  cT | d Solution. Transform S  abS into S  aI and I  bS, so the grammar becomes S  aI | T | L I  bS T  cT | d Now the NFA can be drawn: Start S T L b a c F I d Quiz. What is the regular expression for the language of the grammar? Answer: (ab)*(L + c*d)

Properties of Regular Languages When we know some properties of regular languages they can help us argue, BWOC, that certain languages are not regular. The Pumping Lemma If L is an infinite regular language, then it is recognized by a DFA with, say, m states. If s in L and | s | ≥ m, then an acceptance path for s must pass through some state twice. The following graph depicts the situation. Start y x z The dotted arrows represent the path to acceptance for s and the letters x, y, and z represent the concatenation of the letters along the edges of the path. So s = xyz and y ≠ L. Assume that the middle state is the first repeated state on the path. So | xy | ≤ m. Since the loop can be traversed any number of times, we have the pumping property: xykz  L for all k  N Example. The language L = {anbn | n  N} is not regular. Proof: Assume, BWOC, that L is regular. Since L is infinite, the pumping lemma applies. Choose s = ambm. Then s = xyz, where y ≠ L, | xy | ≤ m, and xykz  L for all k  N. Since | xy | ≤ m and s = ambm = xyz, it follows that xy is a string of a’s. Since y ≠ L, it must be that y = ai for some i > 0. We’ll try for a contradiction with k = 2. The pumping property implies xy2z  L. But xy2z = am + ibm, which is not in L because i > 0. This contradiction implies that L is not regular. QED.

Quiz. In the previous proof we exhibited a contradiction when k = 2 Quiz. In the previous proof we exhibited a contradiction when k = 2. Find similar contradictions for k = 0 and k = 3. Answer: (k = 0) The pumping property implies xy0z  L. In other words, xz  L. But xz = am – ibm, which is not in L because i > 0. This contradiction implies that L is not regular. QED. (k = 3) The pumping property implies xy3z  L. But xy3z = am + 2ibm, which is not in L because i > 0. This contradiction implies that L is not regular. QED. Example/Quiz. Prove the language L = {aabnac2n | n  N} is not regular. Proof: Assume, BWOC, that L is regular. Since L is infinite, the pumping lemma applies. Choose s = aabmac2m. Then s = xyz, where y ≠ L, | xy | ≤ m and xykz  L for all k  N. Since | xy | ≤ m, there are three cases for y: Case 1: y = aabi for some 0 ≤ i ≤ m – 2. (Remember, | xy | ≤ m, so x = L in this case.) Case 2: y = abi for some 0 ≤ i ≤ m – 2. (In this case, we have x = a.) Case 3: y = bi for some 0 < i ≤ m – 2 – j. (In this case, x = aabj for some 0 ≤ j ≤ m – 3) We can obtain a contradiction in each case by considering k = 0, which implies xz  L. Case 1: xz = bm – iac2m which is not in L because strings of L must begin with aa. Case 2: xz = abm – iac2m which is not in L because strngs of L must begin with aa. Case 3: xz = aabm – iac2m which is not in L because strings in L must have twice as many c’s as b’s which can’t be the case since i > 0. So each of the three cases yields a contradiction. Therefore L is not regular. QED.