CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Limitations.

Slides:



Advertisements
Similar presentations
The Pumping Lemma for CFL’s
Advertisements

CSCI 3130: Formal languages and automata theory Tutorial 5
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
Examples for Context-free Language and Pumping Lemma CSC3130 Tutorial 5 Xiao Linfu Department of Computer Science & Engineering.
CFG => PDA Sipser 2 (pages ). CS 311 Fall Formally… A pushdown automaton is a sextuple M = (Q, Σ, Γ, δ, q 0, F), where – Q is a finite set.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Context-free.
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 11, 2006.
127 The Chomsky Hierarchy(review) Recursively Enumerable Sets Turing Machines Post System Markov Algorithms,  -recursive Functions Regular Expression.
1 CSC 3130: Automata theory and formal languages Tutorial 4 KN Hung Office: SHB 1026 Department of Computer Science & Engineering.
The Pumping Lemma for CFL’s
Transparency No. P2C5-1 Formal Language and Automata Theory Part II Chapter 5 The Pumping Lemma and Closure properties for Context-free Languages.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Limitations.
CS5371 Theory of Computation Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL)
Transparency No. P2C5-1 Formal Language and Automata Theory Part II Chapter 5 The Pumping Lemma and Closure properties for Context-free Languages.
1 Background Information for the Pumping Lemma for Context-Free Languages Definition: Let G = (V, T, P, S) be a CFL. If every production in P is of the.
Today Chapter 2: (Pushdown automata) Non-CF languages CFL pumping lemma Closure properties of CFL.
1 The Pumping Lemma for Context-Free Languages. 2 Take an infinite context-free language Example: Generates an infinite number of different strings.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
Chapter 12: Context-Free Languages and Pushdown Automata
CSE 3813 Introduction to Formal Languages and Automata Chapter 8 Properties of Context-free Languages These class notes are based on material from our.
CSCI 2670 Introduction to Theory of Computing September 20, 2005.
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.
CSCI 2670 Introduction to Theory of Computing September 21, 2004.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Context-free.
Design contex-free grammars that generate: L 1 = { u v : u ∈ {a,b}*, v ∈ {a, c}*, and |u| ≤ |v| ≤ 3 |u| }. L 2 = { a p b q c p a r b 2r : p, q, r ≥ 0 }
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Ambiguity.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Closure.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Context-free.
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.
Section 12.4 Context-Free Language Topics
Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans.
Non-CF Languages The language L = { a n b n c n | n  0 } does not appear to be context-free. Informal: A PDA can compare #a’s with #b’s. But by the time.
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.
CSCI 3130: Formal languages and automata theory Tutorial 3 Chin.
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,
Transparency No. P2C5-1 Formal Language and Automata Theory Part II Chapter 5 The Pumping Lemma and Closure properties for Context-free Languages.
1 Alphabets: An Alphabet is a finite set of symbols. We will usually use  to denote the alphabet of input symbols or “terminal characters.” String: A.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Normal forms.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
Transparency No. 1 Formal Language and Automata Theory Homework 5.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
CS 154 Formal Languages and Computability March 15 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
Complexity and Computability Theory I Lecture #12 Instructor: Rina Zviel-Girshin Lea Epstein.
CSCI 2670 Introduction to Theory of Computing September 16, 2004.
LR(k) grammars The Chinese University of Hong Kong Fall 2009
7. Properties of Context-Free Languages
Pushdown automata and CFG ↔ PDA conversions
LR(1) grammars The Chinese University of Hong Kong Fall 2010
Chapter Fourteen: The Context-Free Frontier
Definition: Let G = (V, T, P, S) be a CFL
7. Properties of Context-Free Languages
فصل دوم Context-Free Languages
The Pumping Lemma for CFL’s
Properties of Context-Free Languages
Department of Computer Science & Engineering
The Pumping Lemma for CFL’s
Midterm #2 — Review problems
LR(1) grammars The Chinese University of Hong Kong Fall 2011
Limitations of pushdown automata
Non-regular languages
Non-regular languages
Pushdown automata The Chinese University of Hong Kong Fall 2011
The Pumping Lemma for CFL’s
Normal forms and parsing
The Pumping Lemma for CFL’s
Limitations of context-free languages
Presentation transcript:

CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Limitations of pushdown automata Fall 2011

Non context-free languages L 1 = { a n b n : n ≥ 0} L 2 = {s: s has same number of a s and b s} L 3 = { a n b n c n : n ≥ 0} L 4 = {ss R : s  { a, b }*} L 5 = {ss: s  { a, b }*} These are not regular Are they context-free? ✔ ✔ ?

An attempt Let’s try to design a CFG or PDA L 3 = { a n b n c n : n ≥ 0} S → a B c |  B → ?? read a / push x read b / pop x ???

What would happen if... Suppose we could construct some CFG for L 3, e.g. Let’s do some long derivations S  BC B  CS | b C  SB | a... S  BC  CSC  a SC  a BCC  ab CC  aba C  aba SB  aba BCB  abab CB  ababa B  ababab

Repetition in long derivations If derivation is long enough, some variable must appear twice on same path in parse tree S BC BCSS BCBC a b a b a b S  BC  CSC  a SC  a BCC  ab CC  aba C  aba SB  aba BCB  abab CB  ababa B  ababab

Pumping example Then we can “cut and paste” part of parse tree S BC BCSS BCBC ababab BS BC a b b B C BC S S B C B a b a b b C S ababab ababbabb ✗

Pumping example We can repeat this many times Every sufficiently large derivation will have a middle part that can be repeated indefinitely ababab ✗ ababbabb ✗ ababbbabbb abab n ab n bb

Pumping in general uvwxyuv 3 wx 3 y u v v v w x y A A A A x x uv 2 wx 2 y u v v w x y A A A x u v w x y A A u w y A uwy

Example If L 3 has a context-free grammar G, then What happens for a n b n c n ? No matter how it is split, uv 2 wx 2 y ∉ L 3 ! If uvwxy is in G, so are uv 2 wx 2 y, uv 3 wx 3 y, uwy,... L 3 = { a n b n c n : n ≥ 0} w u y x v a a a... a a b b b... b b c c c... c c

Pumping lemma for context-free languages Pumping lemma: 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 uv i wx i y is in L. w u y x v

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 uv i wx i y is not in L for some i ≥ 0. w u y x v

Proving language is not context-free Like for regular languages, you need a strategy that always wins you this game Donald choose n write z = uvwxy ( |vwx| ≤ n, |vx| ≥ 1) you choose z  L choose i you win if uv i wx i y  L 1 2 w u y x v ≤ n At least one is not empty

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

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

More examples L 1 = { a n b n : n ≥ 0} L 2 = {s: s has same number of a s and b s} L 3 = { a n b n c n : n ≥ 0} L 4 = {ss R : s ∈ { a, b }*} L 5 = {ss: s ∈ { a, b }*} Which is context-free? ✘ ✔ ✔ ✔

Example 1 2 L 5 = {ss: s ∈ { a, b }*} w u y x v a a a a a a a a a b choose n write z = uvwxy z = a n ba n b i = ? w x v u y a a a a a a a a a b What if:

Example 1 2 L 5 = {ss: s  { a, b }*} w u y x v a a a a a a b b b b b b choose n write z = uvwxy z = a n b n a n b n i = ? Recall that |vwx| ≤ n

Example Case 1: w x v a a a a a a b b b b b b Three cases Case 2: w x v a a a a a a b b b b b b Case 3: w x v a a a a a a b b b b b b vwx is in the first half of a n b n a n b n vwx is in the middle part of a n b n a n b n vwx is in the second half of a n b n a n b n

Example Case 1: w x v a a a a a a b b b b b b Apply pumping with i = 0 Case 2: w x v a a a a a a b b b b b b Case 3: w x v a a a a a a b b b b b b uwy looks like a j b k a n b n, where j < n or k < n uwy looks like a n b j a k b n, where j < n or k < n uwy looks like a n b n a j b k, where j < n or k < n

Example Case 1: Apply pumping with i = 0 Case 2: Case 3: uv 0 wx 0 y looks like a j b k a n b n, where j < n or k < n uv 0 wx 0 y looks like a n b j a k b n, where j < n or k < n uv 0 wx 0 y looks like a n b n a j b k, where j < n or k < n Not of the form ss This covers all the cases, so L 5 is not context-free L 5 = {ss: s ∈ { a, b }*}