Automata Theory. CS F-10 Non-Context-Free Langauges Closure Properties of Context-Free Languages. David Galles

Similar documents
CS5371 Theory of Computation. Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL)

CS5371 Theory of Computation. Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL, DPDA PDA)

Context-Free and Noncontext-Free Languages

Context-Free Languages (Pre Lecture)

Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs

Pushdown Automata. We have seen examples of context-free languages that are not regular, and hence can not be recognized by finite automata.

Pumping Lemma for CFLs

Context-Free Languages

2.1 Solution. E T F a. E E + T T + T F + T a + T a + F a + a

Intro to Theory of Computation

MA/CSSE 474 Theory of Computation

Before We Start. The Pumping Lemma. Languages. Context Free Languages. Plan for today. Now our picture looks like. Any questions?

Computational Models - Lecture 4

Properties of Context-Free Languages

Introduction to Theory of Computing

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

Cliff s notes for equivalence of CFLs and L(PDAs) LisaCFL L = L(M) for some PDA M L=L(M)forsomePDAM L = L(G) for some CFG G

CISC4090: Theory of Computation

CS 341 Homework 16 Languages that Are and Are Not Context-Free

Automata Theory CS F-08 Context-Free Grammars

Computational Models - Lecture 5 1

Non-context-Free Languages. CS215, Lecture 5 c

SCHEME FOR INTERNAL ASSESSMENT TEST 3

Closure Properties of Context-Free Languages. Foundations of Computer Science Theory

CS500 Homework #2 Solutions

Computational Models - Lecture 4 1

CS 455/555: Finite automata

CISC 4090 Theory of Computation

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CSE 355 Test 2, Fall 2016

Theory of Computation (IV) Yijia Chen Fudan University

Problem 2.6(d) [4 pts] Problem 2.12 [3pts] Original CFG:

Automata & languages. A primer on the Theory of Computation. Laurent Vanbever. ETH Zürich (D-ITET) October,

Part 3 out of 5. Automata & languages. A primer on the Theory of Computation. Last week, we learned about closure and equivalence of regular languages

Indexed Languages and why you care. Presented by Pieter Hooimeijer

The View Over The Horizon

Fall 1999 Formal Language Theory Dr. R. Boyer. Theorem. For any context free grammar G; if there is a derivation of w 2 from the

Properties of Context-Free Languages. Closure Properties Decision Properties

Chapter 6. Properties of Regular Languages

NPDA, CFG equivalence

CS20a: summary (Oct 24, 2002)

Ogden s Lemma for CFLs

Properties of Regular Languages. Wen-Guey Tzeng Department of Computer Science National Chiao Tung University

The Pumping Lemma for Context Free Grammars

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Computability Theory

Homework 5 - Solution

Formal Languages, Automata and Models of Computation

Pushdown Automata. Notes on Automata and Theory of Computation. Chia-Ping Chen

Functions on languages:

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lec. 10 : Context-Free Grammars

Harvard CS 121 and CSCI E-207 Lecture 12: General Context-Free Recognition

Einführung in die Computerlinguistik

CS375: Logic and Theory of Computing

Lecture 17: Language Recognition

Computational Models: Class 3

Solution Scoring: SD Reg exp.: a(a

The Pumping Lemma and Closure Properties

Theory of Computation

ECS 120: Theory of Computation UC Davis Phillip Rogaway February 16, Midterm Exam

Final exam study sheet for CS3719 Turing machines and decidability.

CPS 220 Theory of Computation

Chapter 16: Non-Context-Free Languages

CISC 4090 Theory of Computation

V Honors Theory of Computation

Question Bank UNIT I

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lec. 9 : Myhill-Nerode Theorem and applications

60-354, Theory of Computation Fall Asish Mukhopadhyay School of Computer Science University of Windsor

Comment: The induction is always on some parameter, and the basis case is always an integer or set of integers.

UNIT II REGULAR LANGUAGES

CSE 105 THEORY OF COMPUTATION

Notes for Comp 497 (Comp 454) Week 10 4/5/05

Computational Models - Lecture 3 1

CpSc 421 Final Exam December 15, 2006

Context Free Language Properties

Computational Models - Lecture 5 1

DM17. Beregnelighed. Jacob Aae Mikkelsen

Context Free Languages. Automata Theory and Formal Grammars: Lecture 6. Languages That Are Not Regular. Non-Regular Languages

Computational Models - Lecture 3

CSE 105 Homework 5 Due: Monday November 13, Instructions. should be on each page of the submission.

Context Free Languages: Decidability of a CFL

PUSHDOWN AUTOMATA (PDA)

Automata Theory. Lecture on Discussion Course of CS120. Runzhe SJTU ACM CLASS

ÖVNINGSUPPGIFTER I SAMMANHANGSFRIA SPRÅK. 17 april Classrum Edition

Context Free Languages and Grammars

6.1 The Pumping Lemma for CFLs 6.2 Intersections and Complements of CFLs

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lec. 5 : DFA minimization

Foundations of Informatics: a Bridging Course

Solution to CS375 Homework Assignment 11 (40 points) Due date: 4/26/2017

What we have done so far

1. Draw a parse tree for the following derivation: S C A C C A b b b b A b b b b B b b b b a A a a b b b b a b a a b b 2. Show on your parse tree u,

Sheet 1-8 Dr. Mostafa Aref Format By : Mostafa Sayed

Lecture III CONTEXT FREE LANGUAGES

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

PS2 - Comments. University of Virginia - cs3102: Theory of Computation Spring 2010

Harvard CS 121 and CSCI E-207 Lecture 10: Ambiguity, Pushdown Automata

Pushdown automata. Twan van Laarhoven. Institute for Computing and Information Sciences Intelligent Systems Radboud University Nijmegen

The Unsolvability of the Halting Problem. Chapter 19

Note: In any grammar here, the meaning and usage of P (productions) is equivalent to R (rules).

Transcription:

Automata Theory CS411-2015F-10 Non-Context-Free Langauges Closure Properties of Context-Free Languages David Galles Department of Computer Science University of San Francisco

10-0: Fun with CFGs Create a CFG for the language: L = {0 n 1 n 2 n : n > 0} {012, 001122, 000111222, 000011112222,... }

10-1: Fun with CFGs L = {0 n 1 n 2 n : n > 0} is not context-free! Why? Need to keep track of how many 0 s there are, and match 1 s and match 2 s Only one stack

10-2: Non-Context-Free Languages We will use a similar idea to the pumping lemma for regular languages to prove a language is not context-free Regular Languages: if a string is long enough, there must be some state q that is repeated in the computation Context-Free Languages: if a string is long enough, there must be some non-terminal A that is used twice in a derivation

10-3: Repeating Non-Terminals If w is long enough, parse tree for w will have some non-terminal that repeats along a path from the root to some leaf Let φ(g) be the fan out of the grammar the longest string that appears on the right-hand side of some rule Let height of a parse tree be the longest path from root to some leaf Longest possible string produced by a grammar G with height h is:

10-4: Repeating Non-Terminals If w is long enough, parse tree for w will have some non-terminal that repeats along a path from the root to some leaf Let φ(g) be the fan out of the grammar the longest string that appears on the right-hand side of some rule Let height of a parse tree be the longest path from root to some leaf Longest possible string produced by a grammar G with height h is: φ(g) h Smallest possible height for a parse tree produced by grammar G for a string of length n is:

10-5: Repeating Non-Terminals If w is long enough, parse tree for w will have some non-terminal that repeats along a path from the root to some leaf Let φ(g) be the fan out of the grammar the longest string that appears on the right-hand side of some rule Let height of a parse tree be the longest path from root to some leaf Longest possible string produced by a grammar G with height h is: φ(g) h Smallest possible height for a parse tree produced by grammar G for a string of length n is: log φ(g) n

10-6: Repeating Non-Terminals Let φ(g) be the fan out of the grammar the longest string that appears on the right-hand side of some rule Let height of a parse tree be the longest path from root to some leaf Longest possible string produced by a grammar G with height h is: φ(g) h Smallest possible height for a parse tree produced by grammar G for a string of length n is: log φ(g) n Given any grammar G and integer k, there exists an n such that any string of lengthnmust have a height k

10-7: Repeating Non-Terminals Given any grammar G and integer k, there exists an n such that any string of length n must have a parse tree of height k If a parse tree has a height k, and the number of non-terminals in the string is < k then by the pigeonhole principle...

10-8: Repeating Non-Terminals Given any grammar G and integer k, there exists an n such that any string of length n must have a parse tree of height k If a parse tree has a height k, and the number of non-terminals in the string is < k then by the pigeonhole principle, some non-terminal must repeat along a path from the root to some leaf.

10-9: Repeating Non-Terminals S A A

10-10: Repeating Non-Terminals S A A

10-11: Repeating Non-Terminals S A A A

10-12: Repeating Non-Terminals S A A A A

10-13: Repeating Non-Terminals S A A

10-14: Repeating Non-Terminals S A

10-15: Repeating Non-Terminals S A u v A y z x

10-16: CF Pumping Lemma Given any Context-Free language L, there exists an integer n, such that for all w L with w n can be broken into w = uvxyz such that vy > 0 uv i xy i z L for all i 0

10-17: CF Pumping Lemma L = {0 n 1 n 2 n : n > 0} is not Context Free Let n be the constant of the Context-Free Pumping lemma Consider w = 0 n 1 n 2 n If we break w = uvxyz, there are 4 cases: v contains both 0 s and 1 s, or both 1 s and 2 s, or y contains both 0 s and 1 s, or both 1 s and 2 s Neither v nor y contain any 0 s Neither v nor y contain any 1 s Neither v nor y contain any 2 s

10-18: CF Pumping Lemma v contains both 0 s and 1 s, or both 1 s and 2 s, or y contains both 0 s and 1 s, or both 1 s and 2 s uv 2 xy 2 z is not in 0 1 2, and is not in L Neither v nor y contain any 0 s uv 2 xy 2 z contains either more 1 s than 0 s, or more 2 s than 0 s, and is not in L Neither v nor y contain any 1 s uv 2 xy 2 z contains either more 0 s than 1 s, or more 2 s than 1 s, and is not in L Neither v nor y contain any 2 s uv 2 xy 2 z contains either more 1 s than 2 s, or more 0 s than 2 s, and is not in L

10-19: CF Pumping Lemma L = {a n : n is prime } is not Context Free

10-20: CF Pumping Lemma L = {a n : n is prime } is not Context Free Let n be the constant of the Context-Free Pumping lemma Consider w = a p, where p is the smallest prime number > n. If we break w = uvxyz: Let vy = k, uxz = r = n k uv i xy i z = a r+ik, r+ik must be prime for all i set i = r+k +1: r+ik = r+kr +k 2 +k = (r +k)(k +1) uv i xy i z is not in L for i = r+k +1; L is not Context-Free

10-21: CF Closure Properties Are the Context-Free Languages closed under union?

10-22: CF Closure Properties Are the Context-Free Languages closed under union? YES! Proved in Lecture 8 (when showing L REG L CFG ) Are the Context-Free Languages closed under intersection?

10-23: CF Closure Properties Are the Context-Free Languages closed under union? YES! Proved in Lecture 8 (when showing L REG L CFG ) Are the Context-Free Languages closed under intersection? Hint can we intersect two Context-Free langauges to get 0 n 1 n 2 n?

10-24: CF Closure Properties Are the Context-Free Languages closed under intersection? L 1 = 0 n 1 n 2 L 2 = 0 1 n 2 n S 1 A 1 B 1 S 2 A 2 B 2 A 1 0A 1 1 01 A 2 0A ǫ B 1 2B 1 ǫ B 2 1B 2 2 12 L 1 L 2 = 0 n 1 n 2 n L 1 is Context-Free, L 2 is Context-Free, L 1 L 2 is not Context-Free

10-25: CF Closure Properties The Context-Free Languages are not closed under intersection What if we tried to use the machine construction proof that showed that L DFA is closed under intersection why wouldn t that work?

10-26: CF Closure Properties Are the Context-Free Languages closed under intersection with a regular language? That is, if L 1 is Context-Free, and L 2 is regular, must L 1 L 2 be Context-Free?

10-27: CF Closure Properties Are the Context-Free Languages closed under intersection with a regular language? That is, if L 1 is Context-Free, and L 2 is regular, must L 1 L 2 be Context-Free? Run PDA L 1 and DFA L 2 in parallel (just like the intersection of two regular languages)

10-28: CF Closure Properties M 1 = (K 1,Σ,Γ 1, 1,s 1,F 1 ) M 2 = (K 2,Σ,δ 2,s 2,F 2 ) K = K 1 K 2 Γ 1 = Γ s = (s 1,s 2 ) F = F 1 F 2 : For each transition in of form ((q 1,a,β),(p 1,γ)), for each state q 2 K 2, add (((q 1,q 2 ),a,β),((p 1,δ(q 2 )),γ)) to For each transition in of form ((q 1,ǫ,β),(p 1,γ)), for each state q 2 K 2, add (((q 1,q 2 ),a,β),((p 1,q 2 ),γ)) to

10-29: CF Closure Properties Is L = {(0+1+2) : # of 0 s = # of 1 s = # of 2 s } Context Free?

10-30: CF Closure Properties Is L = {(0+1+2) : # of 0 s = # of 1 s = # of 2 s } Context Free? L 00 11 22 = {0 n 1 n 2 n : n > 0} which is not Context Free Context-Free language intersected with a regular language must be context free L is not Context-Free

10-31: CF Closure Properties Is L = {www : w (a+b) } Context Free?

10-32: CF Closure Properties Is L = {www : w (a+b) } Context Free? Intersect L with a ba ba b to get L 1 L 1 = a n ba n ba n b If L 1 is not context-free, L is not context-free either

10-33: CF Closure Properties Is L = {a n ba n ba n b : n 0} Context Free?

10-34: CF Closure Properties Is L = {a n ba n ba n b : n 0} Context Free? Let n be the constant of the context-free pumping lemma Consider w = a n ba n ba n b If we break w into uvxyz, there are several possibilities:

10-35: CF Closure Properties If we break w into uvxyz, there are several possibilities: Either v or y contains at least one b. Then w = uv 2 xy 2 z will contain more than 3 b s, and not be in L Neither v nor y contains any characters from the first set of a s. In this case, w = uv 2 xy 2 z will be of the form a n ba m ba o b, were either m or o is greater than n, and hence w is not in L

10-36: CF Closure Properties If we break w into uvxyz, there are several possibilities: Neither v nor y contains any characters from the second set of a s. In this case, w = uv 2 xy 2 z will be of the form a m ba n ba o b, were either m or o is greater than n, and hence w is not in L Neither v nor y contains any characters from the third set of a s. In this case, w = uv 2 xy 2 z will be of the form a m ba o ba n b, were either m or o is greater than n, and hence w is not in L