Download presentation
Presentation is loading. Please wait.
1
Limitations of pushdown automata
The Chinese University of Hong Kong Fall 2010 CSCI 3130: Automata theory and formal languages Limitations of pushdown automata Andrej Bogdanov
2
Non context-free languages
L1 = {anbn: n ≥ 0} L2 = {s: s has same number of as and bs} L3 = {anbncn: n ≥ 0} L4 = {ssR: s ∈ {a, b}*} L5 = {ss: s ∈ {a, b}*} ✔ ✔ ? These are not regular Are they context-free?
3
An attempt L3 = {anbncn: n ≥ 0} Let’s try to design a CFG or PDA
read a / push x S → aBc | e ??? B → ?? read c / pop x
4
What would happen if... Suppose we could construct some CFG for L3, e.g. Let’s do some long derivations S BC CSC aSC aBCC abCC abaC abaSB abaBCB ababCB ababaB ababab S BC B CS | b C SB | a . . .
5
Repetition in long derivations
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
6
Pumping example Then we can “cut and paste” part of parse tree S
B C S a b S ababab ✗ ababbabb B C C S S B B S C a b B C B C a b a b a b
7
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 ✗ ✗ ababnabnbb
8
Pumping in general uvwxy uv2wx2y uv3wx3y uwy u v w x y A u v w x y A u
9
Example L3 = {anbncn: n ≥ 0} If L3 has a context-free grammar G, then
What happens for anbncn? No matter how it is split, uv2wx2y ∉ L4! If uvwxy is in G, so are uv2wx2y, uv3wx3y, uwy, ... a a a ... a a b b b ... b b c c c ... c c w u y x v
10
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 uviwxiy is in L. u v w x y
11
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
12
Proving language is not context-free
Like for regular languages, you need a 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 At least one is not empty u v w x y ≤ n
13
Example L3 = {anbncn: n ≥ 0} adversary
choose n write z = uvwxy (|vwx| ≤ n,|vx| ≥ 1) you choose z L choose i you win if uviwxiy L 1 2 L3 = {anbncn: n ≥ 0} choose n z = anbncn 1 2 write z = uvwxy i = ? w u y x v a a a ... a a b b b ... b b c c c ... c c
14
Example Case 1: v or x contains two kinds of symbols Then uv2wx2y not in L3 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 x v a a a ... a a b b b ... b b c c c ... c c x v a a a ... a a b b b ... b b c c c ... c c
15
More examples ✔ ✔ ✔ Which is context-free? L1 = {anbn: n ≥ 0}
L2 = {s: s has same number of as and bs} L3 = {anbncn: n ≥ 0} L4 = {ssR: s ∈ {a, b}*} L5 = {ss: s ∈ {a, b}*} ✔ ✔ ✘ ✔ Which is context-free?
16
Example L5 = {ss: s ∈ {a, b}*} a a a a a a a a a b a a a a a a a a a b
choose n z = anbanb 1 2 write z = uvwxy i = ? w u y x v a a a a a a a a a b a a a a a a a a a b w x v u y a a a a a a a a a b a a a a a a a a a b What if:
17
Example L5 = {ss: s ∈ {a, b}*}
choose n z = anbnanbn 1 2 write z = uvwxy i = ? w u y x v a a a a a a b b b b b b a a a a a a b b b b b b Recall that |vwx| ≤ n
18
Example Three cases a a a a a a b b b b b b a a a a a a b b b b b b
v w x vwx is in the first half of anbnanbn a a a a a a b b b b b b a a a a a a b b b b b b Case 2: v w x vwx is in the middle part of anbnanbn a a a a a a b b b b b b a a a a a a b b b b b b Case 3: v w x vwx is in the second half of anbnanbn
19
Example Apply pumping with i = 0
a a a a a a b b b b b b a a a a a a b b b b b b Case 1: v w x uwy looks like aibjanbn, where i < n or j < n a a a a a a b b b b b b a a a a a a b b b b b b Case 2: v w x uwy looks like anbiajbn, where i < n or j < n a a a a a a b b b b b b a a a a a a b b b b b b Case 3: v w x uwy looks like anbnaibj, where i < n or j < n
20
Example Apply pumping with i = 0 L5 = {ss: s ∈ {a, b}*}
Case 1: uv0wx0y looks like aibjanbn, where i < n or j < n Not of the form ss Case 2: uv0wx0y looks like anbiajbn, where i < n or j < n Not of the form ss Case 3: uv0wx0y looks like anbnaibj, where i < n or j < n Not of the form ss This covers all the cases, so L5 is not context-free
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.