Context-Free and Noncontext-Free Languages

Similar documents
SCHEME FOR INTERNAL ASSESSMENT TEST 3

MA/CSSE 474 Theory of Computation

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

Context-Free Languages (Pre Lecture)

MA/CSSE 474 Theory of Computation

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

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

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

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

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

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

CSE 355 Test 2, Fall 2016

DM17. Beregnelighed. Jacob Aae Mikkelsen

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

Computational Models - Lecture 4

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

Context-Free Languages

Pumping Lemma for CFLs

Context Free Languages: Decidability of a CFL

Properties of Context-Free Languages. Closure Properties Decision Properties

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

NPDA, CFG equivalence

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

The View Over The Horizon

CISC4090: Theory of Computation

Computational Models - Lecture 5 1

Final exam study sheet for CS3719 Turing machines and decidability.

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

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

Functions on languages:

Introduction to Theory of Computing

The Pumping Lemma for Context Free Grammars

Theory of Computation (IV) Yijia Chen Fudan University

CS20a: summary (Oct 24, 2002)

PUSHDOWN AUTOMATA (PDA)

Foundations of Informatics: a Bridging Course

Theory of Computation

CISC 4090 Theory of Computation

CPS 220 Theory of Computation

Section 1 (closed-book) Total points 30

CS500 Homework #2 Solutions

Ogden s Lemma for CFLs

Computational Models - Lecture 4 1

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

Context Free Language Properties

Lecture 17: Language Recognition

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

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

Chap. 7 Properties of Context-free Languages

CS481F01 Prelim 2 Solutions

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

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

Einführung in die Computerlinguistik

Properties of Context Free Languages

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

This lecture covers Chapter 7 of HMU: Properties of CFLs

Computability and Complexity

Solution Scoring: SD Reg exp.: a(a

Indexed Languages and why you care. Presented by Pieter Hooimeijer

Notes for Comp 497 (454) Week 10

Homework 5 - Solution

Properties of Context-Free 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

Context-Free Grammars (and Languages) Lecture 7

Einführung in die Computerlinguistik

Computational Models Lecture 5

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

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

Computational Models - Lecture 5 1

Computational Models: Class 5

CISC 4090 Theory of Computation

Properties of Context-free Languages. Reading: Chapter 7

Closure Properties of Regular Languages

5 Context-Free Languages

3.10. TREE DOMAINS AND GORN TREES Tree Domains and Gorn Trees

CS 455/555: Finite automata

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

Context Free Languages (CFL) Language Recognizer A device that accepts valid strings. The FA are formalized types of language recognizer.

Context Free Languages and Grammars

Computability Theory

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

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

Properties of context-free Languages

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

CSE 105 THEORY OF COMPUTATION

V Honors Theory of Computation

Pushdown Automata. Chapter 12

Great Theoretical Ideas in Computer Science. Lecture 4: Deterministic Finite Automaton (DFA), Part 2

Intro to Theory of Computation

} Some languages are Turing-decidable A Turing Machine will halt on all inputs (either accepting or rejecting). No infinite loops.

Computational Models - Lecture 3

Theory Bridge Exam Example Questions

THEORY OF COMPUTATION

Chapter 16: Non-Context-Free Languages

MA/CSSE 474 Theory of Computation

The Pumping Lemma and Closure Properties

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

Finite Automata and Regular languages

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

Transcription:

Examples: Context-Free and Noncontext-Free Languages a*b* is regular. A n B n = {a n b n : n 0} is context-free but not regular. A n B n C n = {a n b n c n : n 0} is not context-free

The Regular and the CF Languages Theorem: The regular languages are a proper subset of the context-free languages. Proof: In two parts: Every regular language is CF. There exists at least one language that is CF but not regular.

The Regular and the CF Languages Lemma: Every regular language is CF. Proof: Every FSM is (trivially) a PDA: Given an FSM M = (K,,, s, A) and elements of of the form: ( p, c, q ) old state, input, new state Construct a PDA M' = (K,, { },, s, A). Each (p, c, q) becomes: (( p, c, ), (q, )) old state, input, don't new state don't look at push on stack stack In other words, we just don t use the stack.

The Regular and the CF Languages Lemma: There exists at least one language that is CF but not regular Proof: {a n b n, n 0} is context-free but not regular. So the regular languages are a proper subset of the context-free languages.

Showing that L is Context-Free Techniques for showing that a language L is context-free: 1. Exhibit a context-free grammar for L. 2. Exhibit a PDA for L. 3. Use the closure properties of context-free languages. Unfortunately, these are weaker than they are for regular languages.

Showing that L is Not Context-Free Pumping Theorem for Context-free Languages If L is a context-free language, then k 1 ( strings w L, where w k ( u, v, x, y, z ( w = uvxyz, vy, vxy k and q 0 (uv q xy q z is in L)))).

Pumping Theorem for Context-free Languages Proof: L is generated by some CFG G = (V,, R, S) with n nonterminal symbols and branching factor b. Let k be b n + 1. The longest string that can be generated by G with no repeated nonterminals in the resulting parse tree has length b n. Assuming that b 2, it must be the case that b n + 1 > b n. So let w be any string in L(G) where w k. Let T be any smallest parse tree for w. T must have height at least n + 1. Choose some path in T of length at least n + 1. Let X be the bottom-most repeated nonterminal along that path. Then w can be rewritten as uvxyz. The tree rooted at [1] has height at most n + 1. Thus its yield, vxy, has length less than or equal to b n + 1, which is k. vy since if vy were then there would be a smaller parse tree for w and we chose T so that that wasn t so. uxz must be in L because rule 2 could have been used immediately at [1]. For any q 1, uv q xy q z must be in L because rule 1 could have been used q times before finally using rule 2.

An Example of Pumping: AnBnCn

An Example of Pumping: { a n2 : n 0}

Example: WcW = {wcw : w {a, b}*}

Example: WcW = {wcw : w {a, b}*} Corollary: Java is not context-free

Closure Theorems for Context-Free Languages The context-free languages are closed under: Union Concatenation Kleene star Reverse Letter substitution

Closure Under Union Let G 1 = (V 1, 1, R 1, S 1 ), and G 2 = (V 2, 2, R 2, S 2 ). Assume that G 1 and G 2 have disjoint sets of nonterminals, not including S. Let L = L(G 1 ) L(G 2 ). We can show that L is CF by exhibiting a CFG for it: G = (V 1 V 2 {S}, 1 2, R 1 R 2 {S S 1, S S 2 }, S)

Closure Under Concatenation Let G 1 = (V 1, 1, R 1, S 1 ), and G 2 = (V 2, 2, R 2, S 2 ). Assume that G 1 and G 2 have disjoint sets of nonterminals, not including S. Let L = L(G 1 )L(G 2 ). We can show that L is CF by exhibiting a CFG for it: G = (V 1 V 2 {S}, 1 2, R 1 R 2 {S S 1 S 2 }, S)

Closure Under Kleene Star Let G = (V,, R, S 1 ). Assume that G does not have the nonterminal S. Let L = L(G)*. We can show that L is CF by exhibiting a CFG for it: G = (V 1 {S}, 1, R 1 {S, S S S 1 }, S)

Closure Under Reverse L R = {w * : w = x R for some x L}. Let G = (V,, R, S) be in Chomsky normal form. Every rule in G is of the form X BC or X a, where X, B, and C are elements of V - and a. X a: L(X) = {a}. {a} R = {a}. X BC: L(X) = L(B)L(C). (L(B)L(C)) R = L(C) R L(B) R. Construct, from G, a new grammar G, such that L(G ) = L R : G = (V G, G, R, S G ), where R is constructed as follows: For every rule in G of the form X BC, add to R the rule X CB. For every rule in G of the form X a, add to R the rule X a.

Closure Under Intersection The context-free languages are not closed under intersection: The proof is by counterexample. Let: L 1 = {a n b n c m : n, m 0} L 2 = {a m b n c n : n, m 0} /* equal a s and b s. /* equal b s and c s. Both L 1 and L 2 are context-free, since there exist straightforward context-free grammars for them. But now consider: L = L 1 L 2 = {a n b n c n : n 0}

Closure Under Complement The context-free languages are not closed under complement: The proof : We know that L 1 L 2 = ( L 1 L 2 ) The context-free languages are closed under union, so if they were closed under complement, they would be closed under intersection (which they are not).

The Intersection of a Context-Free Language and a Regular Language is Context-Free L = L(M 1 ), a PDA = (K 1,, 1, 1, s 1, A 1 ). R = L(M 2 ), a deterministic FSM = (K 2,,, s 2, A 2 ). We construct a new PDA, M 3, that accepts L R by simulating the parallel execution of M 1 and M 2. M = (K 1 K 2,, 1,, (s 1, s 2 ), A 1 A 2 ). Insert into : For each rule (( q 1, a, ), ( p 1, )) in 1, and each rule ( q 2, a, p 2 ) in, ((( q 1, q 2 ), a, ), (( p 1, p 2 ), )). For each rule ((q 1,, ), (p 1, ) in 1, and each state q 2 in K 2, (((q 1, q 2 ),, ), ((p 1, q 2 ), )).