Limitations of context-free languages

Slides:



Advertisements
Similar presentations
The Pumping Lemma for CFL’s
Advertisements

CSCI 3130: Formal languages and automata theory Tutorial 5
Erik Jonsson School of Engineering and Computer Science FEARLESS Engineering CS 4384 – 001 Automata Theory Thursday: Context-Free.
Applied Computer Science II Chapter 2 : Context-free languages Prof. Dr. Luc De Raedt Institut für Informatik Albert-Ludwigs Universität Freiburg Germany.
127 The Chomsky Hierarchy(review) Recursively Enumerable Sets Turing Machines Post System Markov Algorithms,  -recursive Functions Regular Expression.
Transparency No. P2C5-1 Formal Language and Automata Theory Part II Chapter 5 The Pumping Lemma and Closure properties for Context-free Languages.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2009 with acknowledgement.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Nondeterminism.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Limitations.
Transparency No. P2C5-1 Formal Language and Automata Theory Part II Chapter 5 The Pumping Lemma and Closure properties for Context-free Languages.
Today Chapter 2: (Pushdown automata) Non-CF languages CFL pumping lemma Closure properties of CFL.
The Pumping Lemma for Context Free Grammars. Chomsky Normal Form Chomsky Normal Form (CNF) is a simple and useful form of a CFG Every rule of a CNF grammar.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Closure.
1 L= { w c w R : w  {a, b}* } is accepted by the PDA below. Use a construction like the one for intersection for regular languages to design a PDA that.
Pumping Lemma for CFLs. Theorem 7.17: Let G be a CFG in CNF and w a string in L(G). Suppose we have a parse tree for w. If the length of the longest path.
Critique this PDA for L= { u u R v v R : u ∈ {0,1}* and v ∈ {0,1}+ } u0εu0 u1εu1 uεεvε v00vε v11vε vεεfε sεεtε t0εt0 t1εt1 t00tε t11tε tεεuε After you.
Chapter 8 Properties of Context-free Languages These class notes are based on material from our textbook, An Introduction to Formal Languages and Automata,
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Limitations.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
LR(k) grammars The Chinese University of Hong Kong Fall 2009
CSE 105 theory of computation
7. Properties of Context-Free Languages
Lecture 22 Pumping Lemma for Context Free Languages
CSE 105 theory of computation
Lecture 17 Oct 25, 2011 Section 2.1 (push-down automata)
Context Free Languages
Jaya Krishna, M.Tech, Assistant Professor
More on Context Free Grammars
Pushdown automata and CFG ↔ PDA conversions
LR(1) grammars The Chinese University of Hong Kong Fall 2010
Non-Context-Free Languages
More on DFA minimization and DFA equivalence
Chapter Fourteen: The Context-Free Frontier
Definition: Let G = (V, T, P, S) be a CFL
7. Properties of Context-Free Languages
Context-Free Grammars
Context-Free Languages
فصل دوم Context-Free Languages
COSC 3340: Introduction to Theory of Computation
The Pumping Lemma for CFL’s
Pumping Lemma for Context-free Languages
Properties of Context-Free Languages
Department of Computer Science & Engineering
The Pumping Lemma for CFL’s
CS21 Decidability and Tractability
Chapter 2 Context-Free Language - 01
CSE 105 theory of computation
COSC 3340: Introduction to Theory of Computation
CS21 Decidability and Tractability
Chapter 2 Context-Free Language - 02
Key Answers for Homework #7
CS21 Decidability and Tractability
LR(1) grammars The Chinese University of Hong Kong Fall 2011
Limitations of pushdown automata
CSE 105 theory of computation
Non-regular languages
Non-regular languages
Pushdown automata The Chinese University of Hong Kong Fall 2011
The Pumping Lemma for CFL’s
LR(k) grammars The Chinese University of Hong Kong Fall 2008
Applications of Regular Closure
CSE 105 theory of computation
The Pumping Lemma for CFL’s
Nondeterminism The Chinese University of Hong Kong Fall 2010
Intro to Theory of Computation
CSE 105 theory of computation
CSE 105 theory of computation
Presentation transcript:

Limitations of context-free languages The Chinese University of Hong Kong Fall 2008 CSC 3130: Automata theory and formal languages Limitations of context-free languages Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130

Non context-free languages Recall the pumping lemma for regular languages allows us to show some languages are not regular Are these languages context-free? L1 = {anbn: n ≥ 0} L2 = {x: x has same number of as and bs} L3 = {1n: n is prime} L4 = {anbncn: n ≥ 0} L5 = {x#xR: x ∈ {0, 1}*} L6 = {x#x: x ∈ {0, 1}*}

Some intuition L4 = {anbncn: n ≥ 0} Let’s try to show this is context-free read a / push 1 S → aBc ??? B → ?? read c / pop 1 context-free grammar pushdown automaton

More intuition Suppose we could construct some CFG for L4, e.g. We do some derivations of “long” strings S  BC  CSC  aSC  aBCC  abCC  abaC  abaSB  abaBCB  ababCB  ababaB  ababab S  BC B  CS | b C  SB | a . . .

More intuition If derivation is long enough, some variable must appear twice on same path in parse tree S S  BC  CSC  aSC  aBCC  abCC  abaC  abaSB  abaBCB  ababCB  ababaB  ababab B C C S S B B C B C a b a b a b

More intuition Then we can “cut and paste” part of parse tree ababbabb ababab ✗ B C C S S B B S C a b B C B C a b a b a b

More intuition We can repeat this many times Every sufficiently large derivation will have a part that can be repeated indefinitely This is caused by cycles in the grammar ababab ababbabb ababbbabbb ✗ ✗ ababnabnbb

General picture u u y y v v x x w v x uvwxy xvvwxxy uv3wx3y w A A A A

Example L4 = {anbncn: n ≥ 0} If L4 has a context-free grammar G, then What happens for anbncn? No matter how it is split, uv2wx2y ∉ L4! If uvwxy can be derived in G, so can uviwxiy for every i a a a ... a a b b b ... b b c c c ... c c u v w x y

Pumping lemma for context-free languages Theorem: For every context-free language L There exists a number n such that for every string z in L, we can write z = uvwxy where  |vwx| ≤ n  |vx| ≥ 1  For every i ≥ 0, the string uviwxiy is in L. u v w x y

Pumping lemma for context-free languages So to prove L is not context-free, it is enough that For every n there exists z in L, such that for every way of writing z = uvwxy where  |vwx| ≤ n and  |vx| ≥ 1, the string uviwxiy is not in L for some i ≥ 0. u v w x y

Proving language is not context-free Just like for regular languages, need strategy that, regardless of adversary, always wins you this game adversary choose n write z = uvwxy (|vwx| ≤ n,|vx| ≥ 1) you choose z  L choose i you win if uviwxiy  L 1 2

Example L4 = {anbncn: n ≥ 0} a a a ... a a b b b ... b b c c c ... c c adversary choose n write z = uvwxy (|vwx| ≤ n,|vx| ≥ 1) you choose z  L choose i you win if uviwxiy  L 1 2 L4 = {anbncn: n ≥ 0} adversary n write z = uvwxy you z = anbncn i = ? 1 2 w u y x v a a a ... a a b b b ... b b c c c ... c c

Example Case 1: v or x contains two kinds of symbols Then uv2wx2y not in L because pattern is wrong Case 2: v and x both contain one kind of symbol Then uv2wx2y does not have same number of as, bs, cs a a a ... a a b b b ... b b c c c ... c c v x a a a ... a a b b b ... b b c c c ... c c v x

More examples Which of these is context-free? L1 = {anbn: n ≥ 0} L2 = {x: x has same number of as and bs} L3 = {1n: n is prime} L4 = {anbncn: n ≥ 0} L5 = {x#xR: x ∈ {0, 1}*} L6 = {x#x: x ∈ {0, 1}*}