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

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

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

NPDA, CFG equivalence

Ogden s Lemma for CFLs

Properties of Context-Free Languages. Closure Properties Decision Properties

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

Theory Bridge Exam Example Questions

Properties of Context-Free Languages

The Pumping Lemma for Context Free Grammars

Context Free Language Properties

Properties of Context-free Languages. Reading: Chapter 7

MA/CSSE 474 Theory of Computation

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

Section 1 (closed-book) Total points 30

CS375: Logic and Theory of Computing

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

Context-Free Languages (Pre Lecture)

MA/CSSE 474 Theory of Computation

Notes for Comp 497 (454) Week 10

CSE 355 Test 2, Fall 2016

Properties of Context Free Languages

V Honors Theory of Computation

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

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

CS481F01 Prelim 2 Solutions

CPS 220 Theory of Computation

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

Context-Free and Noncontext-Free Languages

CS20a: summary (Oct 24, 2002)

Theory of Computation 8 Deterministic Membership Testing

Computational Models - Lecture 4

This lecture covers Chapter 7 of HMU: Properties of CFLs

Properties of context-free Languages

Functions on languages:

Decidability (What, stuff is unsolvable?)

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

HW6 Solutions. Micha l Dereziński. March 20, 2015

SYLLABUS. Introduction to Finite Automata, Central Concepts of Automata Theory. CHAPTER - 3 : REGULAR EXPRESSIONS AND LANGUAGES

Theory of Computation

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

Context-Free Grammars and Languages. Reading: Chapter 5

CS500 Homework #2 Solutions

Theory of Computation 7 Normalforms and Algorithms

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

CISC4090: Theory of Computation

Plan for 2 nd half. Just when you thought it was safe. Just when you thought it was safe. Theory Hall of Fame. Chomsky Normal Form

TAFL 1 (ECS-403) Unit- III. 3.1 Definition of CFG (Context Free Grammar) and problems. 3.2 Derivation. 3.3 Ambiguity in Grammar

Lecture 17: Language Recognition

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Chap. 7 Properties of Context-free Languages

Context Free Languages and Grammars

Final exam study sheet for CS3719 Turing machines and decidability.

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

CPSC 421: Tutorial #1

Formal Languages, Automata and Models of Computation

Theory of Computation (Classroom Practice Booklet Solutions)

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

CSE 105 THEORY OF COMPUTATION

CS5371 Theory of Computation. Lecture 7: Automata Theory V (CFG, CFL, CNF)

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

CSE 105 THEORY OF COMPUTATION

DM17. Beregnelighed. Jacob Aae Mikkelsen

I have read and understand all of the instructions below, and I will obey the University Code on Academic Integrity.

Solution. S ABc Ab c Bc Ac b A ABa Ba Aa a B Bbc bc.

CS311 Computational Structures More about PDAs & Context-Free Languages. Lecture 9. Andrew P. Black Andrew Tolmach

MTH401A Theory of Computation. Lecture 17

Languages, regular languages, finite automata

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

The Chomsky Hierarchy(review)

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

1 More finite deterministic automata

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,

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

UNIT-VIII COMPUTABILITY THEORY

Einführung in die Computerlinguistik

Foundations of Informatics: a Bridging Course

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

Computational Models: Class 5

Theory of Computation Turing Machine and Pushdown Automata

Computability and Complexity

The View Over The Horizon

1 Alphabets and Languages

Part 4 out of 5 DFA NFA REX. Automata & languages. A primer on the Theory of Computation. Last week, we showed the equivalence of DFA, NFA and REX

Theory of Computation (IV) Yijia Chen Fudan University

CSE 105 THEORY OF COMPUTATION

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

CS 301. Lecture 18 Decidable languages. Stephen Checkoway. April 2, 2018

Computational Models - Lecture 5 1

10. The GNFA method is used to show that

Pushdown Automata: Introduction (2)

Definition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x where

Theory of Computation

5 Context-Free Languages

More Properties of Regular Languages

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

Miscellaneous. Closure Properties Decision Properties

DD2371 Automata Theory

Reducability. Sipser, pages

Context-Free Languages

Transcription:

Before We Start The Pumping Lemma Any questions? The Lemma & Decision/ Languages Future Exam Question What is a language? What is a class of languages? Context Free Languages Context Free Languages(CFL) is the next class of languages outside of Regular Languages: Means for defining: Context Free Grammar Machine for accepting: Pushdown Automata Plan for today The Return of the Pumping Lemma and for CFLs Now our picture looks like Context Free Languages Deterministic Context Free Languages Regular Languages Finite Languages Is there anything out here?

Just when you thought it was safe Return of the Pumping Lemma But before we start that! When we last left our CFGs Chomsky Normal Form Chomsky Normal Form A context free grammar is in Chomsky Normal Form (CNF) if every production is of the form: A BC A a Where A,B, and C are variables and a is a terminal. The Pumping Lemma for RL The Pumping Lemma for RL Statement of the pumping lemma for RL Let L be a regular language. Then there exists a constant n (which varies for different languages), such that for every string x L with x n, x can be expressed as x = uvw such that: 1. v > 0 2. uv n 3. For all k 0, the string uv k w is also in L. p 0 u = a 1 a 2 a i p i v = a i+1 a i+2 a j w = a j+1 a j+2 a m With CFLs strings are distinguished by their derivation (or parse trees) based on the productions of a CFG. The idea behind the Pumping Lemma for CFLs: If a string is long enough, then at least one variable in it s derivation will have to be repeated. We can repeatedly reapply productions for the repeated variable ( pump you up ) and the resultant string will also be in the language

S * vaz * vwayz * vwxyz So A * x but also A * way We can then write instead: S * vaz * vwayz * vw 2 Ay 2 z * vw 3 Ay 3 z And so on How long is long enough? Recall Chomsky Normal Form A context free grammar is in Chomsky Normal Form (CNF) if every production is of the form: A BC A a Where A,B, and C are variables and a is a terminal. The parse tree for a grammar in CNF will be a binary tree A binary tree having more than 2 k-1 leaf nodes must have a height (longest path) > k. If we let k be the number of number of variables in our grammar, then For any string x, where x > 2 k At least one variable in the longest path will be repeated.

Let L be a CFL. Then there is an integer n so that for all strings u, where u n, u can be expressed as u = vwxyz where wy > 0 wxy n For any m 0, vw m xy m z L n = 2 p+1 where p = number of variables The real strength of the pumping lemma is proving that languages are not context free Proof by contradiction Assume that the language to be tested is a CFL Use the pumping lemma to come to a contradiction Original assumption about the language being a CFL is false You cannot prove a language to be a CFL using the Pumping Lemma!!!! The Pumping Lemma game To show that a language L is not a CFL Assume L is context free Choose an appropriate string x in L Express x = uvwxy following rules of pumping lemma Show that uv k wx k z is not in L, for some k The above contradicts the Pumping Lemma Our assumption that L is context free is wrong L must not be context free Example: L = { a i b i c i i 1 } Strings of the form abc where number of a s, b s and c s are equal Let s play! Assume that L is context free. Then by the pumping lemma all strings u with u n can be expressed as u = vwxyz and wy > 0 wxy n For any m 0, vw m xy m z L Example L = {a i b i c i i 1 } Choose an appropriate u = a n b n c n = vwxyz Since wxy n then wxy must consists of All a s or all b s or all c s Some a s and some b s Some b s and some c s In all three cases vw 2 xy 2 z will not have an equal number of a s b s and c s. Pumping Lemma says vw 2 xy 2 z L Can t contradict the pumping lemma! Our original assumption must be wrong. L is not context-free.

By the same argument (same choice of u), we can show that: L = { x { a,b,c} * n a (x) = n b (x) = n c (x) } Is not context free Another Example: L = { a i b j c k i < j and i < k } Number of a s is less than the number of b s and the number of c s Let s play! Assume that L is context free. Then by the pumping lemma all strings u with u n can be expressed as u = vwxyz and wy > 0 wxy n For any m 0, vw m xy m z L Example L = {a i b j c k i < j and i < k } Choose an appropriate u = a n b n+1 c n+1 =vwxyz Since wxy n then wxy must consists of Case 1: All a s or all b s or all c s Case 2: Some a s and some b s Case 3: Some b s and some c s Let s consider each case individually: Case 1: All a s or all b s or all c s If wxy consists of all a s then there will be k such that when we pump w and y k times, the number of a s will be greater than n+1 If wxy consists of all b s then vw 0 xy 0 z will contain the same number or less b s than a s If wxy consists of all c s then vw 0 xy 0 z will contain the same number or less c s than a s Let s consider each case individually: Case 2: Some a s and some b s If wxy consists of only a s and b s then there will be k such that when we pump w and y k times, the number of a s will be greater than n+1 (# of c s) Relationship between a s and b s might be maintained, but not the relationship between a s and c s Let s consider each case individually: Case 2: Some b s and some c s If wxy consists of only b s and c s then vw 0 xy 0 z will contain the same number or less c s or b s than a s

In all cases We found a pumped (or unpumped) string that the pumping lemma said should be in the langauge but did not maintain the relationship of a s to b s and c s as specified in the language. Can t contradict the pumping lemma! Our original assumption must be wrong. L is not context-free. By the same argument (same choice of u), we can show that: L = { x { a,b,c} * n a (x) < n b (x) and n a (x) < n c (x) } Is not context free Questions? We already seen that CFLs are closed under: Union Concatenation Kleene Star Regular Languages are also closed under Intersection Complementation Difference What about Context Free Languages? Sorry, Charlie CFLs are not closed under intersection Meaning: If L 1 and L 2 are CFLs then L 1 L 2 is not necessarily a CFL. CFLs are not closed under intersection Example: L 1 = {a i b j c k i < j } L 2 = {a i b j c k i < k } Are both CFLs

CFLs are not closed under intersection L L 2 = {a i b j c k 1 = {a i b j c k i < j } i < k } CFLs are not closed under intersection L 1 L 2 = {a i b j c k i < j and i < k } S ABC A aab ε B bb b C cc ε S AC A aac B B bb ε C cc c Which we just showed to be non-context free. Sorry, Charlie CFLs are not closed under complement Why? L 1 L 2 = (L 1 L 2 ) Sorry, Charlie CFLs are not closed under difference Why? L = Σ * -L We know Σ * is regular, and as such is also a CFL. If CFLs were closed under difference, then Σ * -L = L would always be a CFL But we showed that CFLs are not closed under complement What went wrong? Can t we apply the same construction as we did for the complement of RLs? Reverse the accepting / non-accepting states PDAs can crash. I.e Fail by having no place to go. PDAs can crash in accepting or non-accepting state Making non-accepting states accepting will not handle crashes. What went wrong? Can t we apply the same construction as we did for the intersection of RLs? The states of M are an ordered pair (p, q) where p Q 1 and q Q 2 Informally, the states of M will represent the current states of M 1 and M 2 at each simultaneous move of the machines.

What went wrong? Can t we apply the same construction as we did for the intersection of RLs? The problem is the stack. Although we could try the same thing for PDAs and have a combined machine keep track of where both PDAs are at any one time. We can t keep track of what s on both stacks at any given tine. However, if one of the CFLs does not use the stack (I.e. it is an FA), then we can build a PDA that accepts L 1 L 2. In other words: If L 1 is a context free language and L 2 is a regular language, then L 1 L 2 is context free. Basic idea: Like with the FA construction, let the states of the new machine keep track of the states of the PDA accepting L 1 (M 1 ) and the FA accepting L 2 (M 2 ). Our single stack of the new machine will operate the same as the stack of the PDA accepting L 1 Accepting states will be all states that contain both an accepting state from M 1 and M 2. Basic idea Summary CFLs are closed under Union, Concatenation, Kleene Star CFLs are NOT closed under Intersection, Difference, Complement But The intersection of a CFL with a RL is a CFL Questions we can ask about context free languages and how we answer such questions.

Given regular languages, specified in any one of the four means, can we develop algorithms that answer the following questions: 1. Is a given string in the language? 2. Is the language empty? 3. Is the language finite? Membership Unlike FAs, we can t just run the string through the machine and see where it goes since PDAs are non-deterministic. Must consider all possible paths Membership Instead, start with your grammar in CNF. The proof of the pumping lemma states that the longest derivation path of a string of size n will be 2n 1. Systematically generate all derivations with one step, then two steps,, then 2n 1 steps where the length of the string tested = n. If one of the derivations derive x, return true, else return false. Emptiness By the proof of the pumping lemma, if a grammar in CNF has p states, the longest string, not subject to the pumping lemma will have length n = 2 p+1. Systematically generate all strings with lengths less than n. Test each one using membership algorithm If all fail and ε L, then L is empty Else L is not empty. Finiteness Just as with RLs, a language is infinite if there is a string x with length between n and 2n With RLs n = number of states in an FA With CFLs n = 2 p+1 where p is the number of variables in the CFG Questions? Systematically generate all strings with lengths between n and 2n Run through membership algorithm If one passes, L is infinite, if all fail, L is finite

Summary Pumping Lemma for CFLs Now our picture looks like Context Free Languages Deterministic Context Free Languages Regular Languages Finite Languages Is there anything out here? YES Next Time Next classes of languages However, We start with the machine rather than the language Move beyond simple language acceptance into the realm of computation. Enter The Turing Machine!!!