Grammar. Languages. Content 5/10/16. Automata and Languages. Regular Languages. Regular Languages

Similar documents
Automata and Languages

5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9.

Harvard University Computer Science 121 Midterm October 23, 2012

1.4 Nonregular Languages

Assignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages

Minimal DFA. minimal DFA for L starting from any other

Let's start with an example:

Theory of Computation Regular Languages. (NTU EE) Regular Languages Fall / 38

Talen en Automaten Test 1, Mon 7 th Dec, h45 17h30

Homework 4. 0 ε 0. (00) ε 0 ε 0 (00) (11) CS 341: Foundations of Computer Science II Prof. Marvin Nakayama

Today s Topics Automata and Languages

Automata and Languages

CHAPTER 1 Regular Languages. Contents

Theory of Computation Regular Languages

Regular Language. Nonregular Languages The Pumping Lemma. The pumping lemma. Regular Language. The pumping lemma. Infinitely long words 3/17/15

For convenience, we rewrite m2 s m2 = m m m ; where m is repeted m times. Since xyz = m m m nd jxyj»m, we hve tht the string y is substring of the fir

CS 275 Automata and Formal Language Theory

First Midterm Examination

CS375: Logic and Theory of Computing

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

1.3 Regular Expressions

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Lecture 6 Regular Grammars

Lecture 08: Feb. 08, 2019

1 Nondeterministic Finite Automata

Homework 3 Solutions

First Midterm Examination

Non Deterministic Automata. Linz: Nondeterministic Finite Accepters, page 51

CSCI 340: Computational Models. Transition Graphs. Department of Computer Science

Regular expressions, Finite Automata, transition graphs are all the same!!

Worked out examples Finite Automata

Closure Properties of Regular Languages

Non-Deterministic Finite Automata. Fall 2018 Costas Busch - RPI 1

Formal Languages and Automata

CSCI 340: Computational Models. Kleene s Theorem. Department of Computer Science

Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Kleene-*

Finite Automata-cont d

CS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018

Languages & Automata

Regular Languages and Applications

Homework Solution - Set 5 Due: Friday 10/03/08

Fundamentals of Computer Science

Java II Finite Automata I

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Normal Forms for Context-free Grammars

Nondeterminism and Nodeterministic Automata

CHAPTER 1 Regular Languages. Contents. definitions, examples, designing, regular operations. Non-deterministic Finite Automata (NFA)

Chapter Five: Nondeterministic Finite Automata. Formal Language, chapter 5, slide 1

Chapter 2 Finite Automata

CS 330 Formal Methods and Models

Myhill-Nerode Theorem

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

CS 275 Automata and Formal Language Theory

I. Theory of Automata II. Theory of Formal Languages III. Theory of Turing Machines

Formal languages, automata, and theory of computation

Finite-State Automata: Recap

Lexical Analysis Finite Automate

Convert the NFA into DFA

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

CISC 4090 Theory of Computation

Exercises Chapter 1. Exercise 1.1. Let Σ be an alphabet. Prove wv = w + v for all strings w and v.

Chapter 4 Regular Grammar and Regular Sets. (Solutions / Hints)

1 From NFA to regular expression

Revision Sheet. (a) Give a regular expression for each of the following languages:

Thoery of Automata CS402

Parse trees, ambiguity, and Chomsky normal form

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

Table of contents: Lecture N Summary... 3 What does automata mean?... 3 Introduction to languages... 3 Alphabets... 3 Strings...

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

11.1 Finite Automata. CS125 Lecture 11 Fall Motivation: TMs without a tape: maybe we can at least fully understand such a simple model?

PART 2. REGULAR LANGUAGES, GRAMMARS AND AUTOMATA

Free groups, Lecture 2, part 1

5.1 Definitions and Examples 5.2 Deterministic Pushdown Automata

Context-Free Grammars and Languages

a,b a 1 a 2 a 3 a,b 1 a,b a,b 2 3 a,b a,b a 2 a,b CS Determinisitic Finite Automata 1

Designing finite automata II

Finite Automata. Informatics 2A: Lecture 3. John Longley. 22 September School of Informatics University of Edinburgh

State Minimization for DFAs

Some Theory of Computation Exercises Week 1

Lecture 09: Myhill-Nerode Theorem

ɛ-closure, Kleene s Theorem,

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS

NFAs continued, Closure Properties of Regular Languages

CS103 Handout 32 Fall 2016 November 11, 2016 Problem Set 7

FABER Formal Languages, Automata and Models of Computation

Finite Automata. Informatics 2A: Lecture 3. Mary Cryan. 21 September School of Informatics University of Edinburgh

Anatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute

Deterministic Finite Automata

Name Ima Sample ASU ID

Coalgebra, Lecture 15: Equations for Deterministic Automata

CSC 473 Automata, Grammars & Languages 11/9/10

Tutorial Automata and formal Languages

Lecture 9: LTL and Büchi Automata

Deterministic Finite-State Automata

CS 330 Formal Methods and Models Dana Richards, George Mason University, Spring 2016 Quiz Solutions

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER LANGUAGES AND COMPUTATION ANSWERS

CS 275 Automata and Formal Language Theory

Non-deterministic Finite Automata

p-adic Egyptian Fractions

Transcription:

5//6 Grmmr Automt nd Lnguges Regulr Grmmr Context-free Grmmr Context-sensitive Grmmr Prof. Mohmed Hmd Softwre Engineering L. The University of Aizu Jpn Regulr Lnguges Context Free Lnguges Context Sensitive Lnguges Lnguges 2 Regulr Lnguges Content Equivlence etween Regulr Grmmrs nd Regulr Lnguges Pumping Lemm (PL) Exmples Regulr Lnguges L is Regulr Lnguge if nd only if there exist finite utomton M = (Q, Σ, δ, q, F ) such tht: L = L(M) = { w Σ* : δ (q,w) F} 3 4

5//6 Equivlence etween Regulr Grmmrs nd Regulr Lnguges Theorem If L is regulr lnguge then there is right-liner grmmr G =(V,T,S,P ) such tht L=L(G). Proof. L is regulr implies (y def.) there exist finite utomton M = (Q, Σ, δ, q, F ) such tht L(M)=L. Now we construct the equivlent grmmr G s follows: Vriles re the sttes: V = Q Strt symol is strt stte: S = q Sme lphet of terminls T=Σ A trnsition δ(q,)=q 2 ecomes the rule q àq 2 Accept sttes q F define the λ-productions q à λ Accepted pths give rise to terminting derivtions nd vice vers. L(G)=L(M). 5 Equivlence etween Regulr Grmmrs nd Regulr Lnguges Exmple The DFA ove cn e simulted y the grmmr x à x y y à x z z à x z λ 6 Equivlence etween Regulr Grmmrs nd Regulr Lnguges Equivlence etween Regulr Grmmrs nd Regulr Lnguges Exmple x à x y y à x z z à x z λ Exmple x à x y y à x z z à x z λ x x y 7 8 2

5//6 Equivlence etween Regulr Grmmrs nd Regulr Lnguges Equivlence etween Regulr Grmmrs nd Regulr Lnguges Exmple x à x y y à x z z à x z λ Exmple x à x y y à x z z à x z λ x y x x y x x 9 Equivlence etween Regulr Grmmrs nd Regulr Lnguges Exmple x à x y y à x z z à x z λ x y x x y Equivlence etween Regulr Grmmrs nd Regulr Lnguges Exmple x à x y y à x z z à x z λ x y x x y z 2 3

5//6 Equivlence etween Regulr Grmmrs nd Regulr Lnguges Exmple x à x y y à x z z à x z λ x y x x y z Equivlence etween Regulr Grmmrs nd Regulr Lnguges Theorem 2 If G =(V,T,S,P) is right-liner grmmr then L(G) is regulr lnguge. Proof. : Define FA M = (Q, Σ, δ, q, F ) s follows Strt stte q correspond to strt symol S A non-finl stte q i corresponds to vrile symol V i Sme lphet of terminls Σ = Τ For every rule V i à m V j, define trnsition δ(q i, m )=q j For every rule V i à m, define trnsition δ(q i, m )=q f finl stte ACCEPT! 3 Terminting derivtions give rise to ccepted pths nd vice vers. So L(M)=L(G). Hence (y def.) L(G) is regulr lnguge. 4 Equivlence etween Regulr Grmmrs nd Regulr Lnguges Theorem 2 Construct n FA tht is equivlent to the right-liner grmmr: Answer: S à A A à S Aà S A q f Equivlence etween Regulr Grmmrs nd Regulr Lnguges Comments THEOREM nd THEOREM 2 show tht right-liner grmmrs nd regulr lnguges re equivlent. Similrly we cn show tht left-liner grmmrs nd regulr lnguges re equivlent. 5 Hence we conclude tht Regulr Grmmrs nd Regulr Lnguges re equivlent. 6 4

5//6 Regulr Lnguges Regulr Lnguges Cn every CFG e converted into right liner grmmr? How we cn identify non-regulr lnguges? A: NO! This would men tht ll context free lnguges re regulr. For exmple: S à λ S cnnot e converted ecuse { n n } is not regulr. 7 A: By using technique clled Pumping Lemm 8 Pumping Lemm (PL) Pumping Lemm (PL) Motivtion Motivtion Consider the lnguge L = * = {,,,, } The string is sid to e pumple in L ecuse cn tke the underlined portion, nd pump it up (i.e. repet) s much s desired while lwys getting elements in L. Consider the lnguge L = * = {,,,, } Which of the following re pumple?. 2. 3. A:. Pumple:,,,, etc. 2. Pumple: 9 3. not pumple ecuse most of * not in L 2 5

5//6 Pumping Lemm (PL) Pumping Lemm (PL) Motivtion Motivtion Define L 2 y the following utomton: Is pumple? A: Pumple:,. Underlined sustrings correspond to cycles in the FA! Let L3 = {,,, λ} Which strings re pumple? A: None! When pumping ny string non-trivilly, lwys result in infinitely mny possile strings. So no pumping cn go on inside finite set. Cycles in the FA cn e repeted ritrrily often, hence pumple. 2 Pumping Lemm give criterion for when strings cn e pumped. 22 Pumping Lemm (PL) Pumping Lemm (PL) Motivtion q q q2 q3, We hve: Becuse: L(M ) q q q q q q3 Motivtion Note, q q q q q q3 So, L(M ) L(M ) Also, q q q q q q3 So, We note tht: i j i, j Ν : ( ) ( ) L( M ) 23 24 6

5//6 Theorem Pumping Lemm (PL) Given n (infinite) regulr lnguge L, there is numer p (clled the pumping numer) such tht ny string in L of length p is pumple within its first p letters. In other words, for ll u L with u p we cn write: u = xyz (x is prefix, z is suffix) y (mid-portion y is non-empty) xy p (pumping occurs in first p letters) xy i z L for ll i (cn pump y-portion) To prove the Pumping Lemm we need to know the Pigeonhole Principle 25 Pigeonhole principle The pigeonhole principle is very simple, yet powerful method for identifying nonregulr lnguges. It sttes tht: given n ojects nd m oxes, if n>m then t lest one ox must hve more thn one oject. n ojects: n > m m oxes: Pumping Lemm (PL) This Box hs more thn one oject 26 Pumping Lemm (PL) Pigeonhole principle fundmentl oservtion Given sufficiently long string, the sttes of DFA must repet in n ccepting computtion. These cycles cn then e used to predict (generte) infinitely mny other strings in (of) the lnguge. Proof Now consider n ccepted string u. By ssumption L is regulr so let M e the FA ccepting it. Let p = Q = no. of sttes in M. Suppose u p. Pumping Lemm (PL) The pth leled y u visits p+ sttes in its first p letters. Thus (y pigeonhole principle) u must visit some stte twice. Pigeon-Hole Principle 27 The su-pth of u connecting the first nd second visit of the vertex is loop, nd gives the climed string y tht cn e pumped within the first p letters. 28 7

5//6 Notes: Pumping Lemm (PL) It is necessry condition. Every regulr lnguge stisfies it. If lnguge violtes it, it is not regulr. RL => PL not PL => not RL It is not sufficient condition. Not every non-regulr lnguge violtes it. not RL =>? PL or not PL (no conclusion) Notes: Pumping Lemm (PL) For ll sufficiently long strings (u) There exists non-null prefix (xy) nd sustring (y) For ll repetitions of the sustring (y), we get strings in the lnguge. u L : u k x,y,z : ( xyz = u) ( xy p) ( y ) i ( i : i xy z L) 29 3 Pumping Lemm (PL) Proving non-regulrity If there exists n ritrrily long string u L, nd for ech decomposition u = xyz, there exists n i such tht xy i z L, then L is non-regulr. Negtion of the necessry condition: u L : u p x,y,z : ( xyz = u) ( xy p) ( y ) i ( i : i xy z L) Proving non-regulrity Pumping Lemm (PL) In generl, to prove tht L isn t regulr:. Assume L were regulr 2. Therefore it hs pumping no. p 3. Find string pttern involving the length p in some clever wy, nd which cnnot e pumped. This is the hrd prt. 4. (2)àß(3) <contrdiction> Therefore our ssumption () ws wrong nd conclude tht L is not regulr lnguge 3 32 8

5//6 Exmple Pumping Lemm (PL) Show tht L={ n n n =,,2, } is not regulr.. Assume L were regulr 2. Therefore it hs pumping no. p, sy p=2 3. But consider the string u= 2 2. we hve u =4 > p=2, let x=, y=, nd z= è u=xyz, y, nd xy p(=2). PLè xy i z L for ll i Tking i=è xz L è L 4. <contrdiction> Therefore our ssumption () ws wrong nd conclude tht L is not regulr lnguge 33 Exercise Show tht the following lnguges re not regulr: L p = p { p is prime numer} L = c c { c is composite numer} L = { ω {, }* # ' s inω = # 's inω} L pl ={x * x =x R } Pumping Lemm (PL) 34 9