meljun cortes automata theory 11
TRANSCRIPT
8/13/2019 MELJUN CORTES Automata Theory 11
http://slidepdf.com/reader/full/meljun-cortes-automata-theory-11 1/15
CSC 3130: Automata theory and formal languages
Limitations of context-free languages
Fall 2008ELJUN P. CORTES MBA MPA BSCS ACS
MELJUN CORTES
8/13/2019 MELJUN CORTES Automata Theory 11
http://slidepdf.com/reader/full/meljun-cortes-automata-theory-11 2/15
Non context-free languages
• Recall the pumping lemma for regular languagesallows us to show some languages are not
regular
Are these languages context-free?
L 1 = {an bn : n ≥ 0}
L 2 = {x : x has same number of as and bs}L 3 = {1n : n is prime}
L 4 = {an bn cn : n ≥ 0}
L 5 = {x #x R : x ∈ {0, 1}*}
L 6 = {x #x : x ∈ {0, 1}*}
8/13/2019 MELJUN CORTES Automata Theory 11
http://slidepdf.com/reader/full/meljun-cortes-automata-theory-11 3/15
Some intuition
• Let’s try to show this is context-free
L 4 = {an bn cn : n ≥ 0}
context-free grammar pushdown automaton
S → aBc
B → ??
read a / push 1
read c / pop 1
???
8/13/2019 MELJUN CORTES Automata Theory 11
http://slidepdf.com/reader/full/meljun-cortes-automata-theory-11 4/15
More intuition
• Suppose we could construct some CFG for L4,e.g.
• We do some derivations
of “long” strings
S BC
B CS | b
C SB | a
. . .
S BC CSC
aSC aBCC
abCC
abaC
abaSB
abaBCB ababCB
ababaB ababab
8/13/2019 MELJUN CORTES Automata Theory 11
http://slidepdf.com/reader/full/meljun-cortes-automata-theory-11 5/15
More intuition
• If derivation is long enough, some variable mustappear twice on same path in parse tree
S BC
CSC aSC
aBCC
abCC
abaC
abaSB
abaBCB
ababCB
ababaB
ababab
S
B C
BC S S
B C B C
a b a b a b
8/13/2019 MELJUN CORTES Automata Theory 11
http://slidepdf.com/reader/full/meljun-cortes-automata-theory-11 6/15
More intuition
• Then we can “cut and paste” part of parse tree S
B C
BC S S
B C B C
a b a b a b
BS
B C
a
b
b
B C
BC S S
B C Ba
b a b
bC
S
ababab ababbabb✗
8/13/2019 MELJUN CORTES Automata Theory 11
http://slidepdf.com/reader/full/meljun-cortes-automata-theory-11 7/15
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
ababn abn bb
8/13/2019 MELJUN CORTES Automata Theory 11
http://slidepdf.com/reader/full/meljun-cortes-automata-theory-11 8/15
General picture
u u
v v
v
w
x
y y
u
v
v
v
w
x
y
uvwxy uv 3wx 3 y
A
A
A
A
A
A
A
A
A
x
x
x
x
wxvvwxxy
8/13/2019 MELJUN CORTES Automata Theory 11
http://slidepdf.com/reader/full/meljun-cortes-automata-theory-11 9/15
Example
• If L4 has a context-free grammar G, then
• What happens for an bn cn ?
• No matter how it is split, uv 2wx 2 y L 4!
If uvwxy can be derived in G, so can uv i wx i y for every i
L 4 = {an
bn
cn
: n ≥ 0}
wu yxva a a ... a a b b b ... b b c c c ... c c
8/13/2019 MELJUN CORTES Automata Theory 11
http://slidepdf.com/reader/full/meljun-cortes-automata-theory-11 10/15
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 uv i wx i y is in L .
wu yxv
8/13/2019 MELJUN CORTES Automata Theory 11
http://slidepdf.com/reader/full/meljun-cortes-automata-theory-11 11/15
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 yisnot in L for some i ≥ 0.
wu yxv
8/13/2019 MELJUN CORTES Automata Theory 11
http://slidepdf.com/reader/full/meljun-cortes-automata-theory-11 12/15
Proving language is not context-free
• Just like for regular languages, need strategy that,
regardless of adversary, always wins you this
gameadversary
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
8/13/2019 MELJUN CORTES Automata Theory 11
http://slidepdf.com/reader/full/meljun-cortes-automata-theory-11 13/15
Example
adversary
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
adversary
n
write z = uvwxy
you
z = an bn cn
i = ? 1
2
L 4 = {an bn cn : n ≥ 0}
wu yxva a a ... a a b b b ... b b c c c ... c c
8/13/2019 MELJUN CORTES Automata Theory 11
http://slidepdf.com/reader/full/meljun-cortes-automata-theory-11 14/15
Example
• Case 1: v or x contains two kinds of symbols
Then uv 2wx 2 y not in L because pattern is wrong
• Case 2: v and x both contain one kind of symbol
Then uv 2wx 2 y does not have same number of as,
bs, cs
xva a a ... a a b b b ... b b c c c ... c c
xv
a a a ... a a b b b ... b b c c c ... c c
8/13/2019 MELJUN CORTES Automata Theory 11
http://slidepdf.com/reader/full/meljun-cortes-automata-theory-11 15/15
More examples
• Which of these is context-free?
L 1 = {an bn : n ≥ 0}
L 2 = {x : x has same number of as and bs}
L 3 = {1n
: n is prime} L 4 = {an bn cn : n ≥ 0}
L 5 = {x #x R : x {0, 1}*}
L 6 = {x #x : x {0, 1}*}