csci 3130: automata theory and formal languages

20
CSCI 3130: Automata theory and formal languages Andrej Bogdanov http://www.cse.cuhk.edu.hk/ ~andrejb/csc3130 The Chinese University of Hong Kong Limitations of pushdown automata Fall 2010

Upload: maxwell-jordan

Post on 31-Dec-2015

67 views

Category:

Documents


0 download

DESCRIPTION

Fall 2010. The Chinese University of Hong Kong. CSCI 3130: Automata theory and formal languages. Limitations of pushdown automata. Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130. Non context-free languages. ✔. L 1 = { a n b n : n ≥ 0} - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CSCI 3130: Automata theory and formal languages

CSCI 3130: Automata theory and formal languages

Andrej Bogdanov

http://www.cse.cuhk.edu.hk/~andrejb/csc3130

The Chinese University of Hong Kong

Limitations of pushdown automata

Fall 2010

Page 2: CSCI 3130: Automata theory and formal languages

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?

✔✔

?

Page 3: CSCI 3130: Automata theory and formal languages

An attempt

• Let’s try to design a CFG or PDA

L3 = {anbncn: n ≥ 0}

S → aBc | B → ??

read a / push x

read c / pop x???

Page 4: CSCI 3130: Automata theory and formal languages

What would happen if...

• Suppose we could construct some CFG for L3, e.g.

• Let’s do some long derivations

S BCB CS | bC SB | a

. . .

S BC CSC aSC aBCC abCC abaC abaSB abaBCB ababCB ababaB ababab

Page 5: CSCI 3130: Automata theory and formal languages

Repetition in long derivations

• If derivation is long enough, some variable mustappear twice on same path in parse tree

S

B C

BC S S

B C B C

a b a b a b

S BC CSC aSC aBCC abCC abaC abaSB abaBCB ababCB ababaB ababab

Page 6: CSCI 3130: Automata theory and formal languages

Pumping example

• 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 SS

B CBa

b a b

bC

S

ababab ababbabb✗

Page 7: CSCI 3130: Automata theory and formal languages

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

Page 8: CSCI 3130: Automata theory and formal languages

Pumping in general

uvwxy uv3wx3y

u

v

v

v

w

x

yA

A

A

A

x

x

uv2wx2y

u

v

v

w

x

yA

A

A x

u

v

w

x

yA

A

u

wyA

uwy

Page 9: CSCI 3130: Automata theory and formal languages

Example

• 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, ...

L3 = {anbncn: n ≥ 0}

wu yxva a a ... a a b b b ... b b c c c ... c c

Page 10: CSCI 3130: Automata theory and formal languages

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.

wu yxv

Page 11: CSCI 3130: Automata theory and formal languages

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 forevery way of writing z = uvwxy where |vwx| ≤ n and |vx| ≥ 1, the string uviwxiy isnot in L for some i ≥ 0.

wu yxv

Page 12: CSCI 3130: Automata theory and formal languages

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 nwrite z = uvwxy (|vwx| ≤ n,|vx| ≥ 1)

you

choose z Lchoose iyou win if uviwxiy L

1

2

wu yxv≤ n

At least oneis not empty

Page 13: CSCI 3130: Automata theory and formal languages

Example

adversary

choose nwrite z = uvwxy (|vwx| ≤ n,|vx| ≥ 1)

you

choose z Lchoose iyou win if uviwxiy L

1

2

1

2

L3 = {anbncn: n ≥ 0}

wu yxva a a ... a a b b b ... b b c c c ... c c

choose nwrite z = uvwxy

z = anbncni = ?

Page 14: CSCI 3130: Automata theory and formal languages

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

xva a a ... a a b b b ... b b c c c ... c c

xva a a ... a a b b b ... b b c c c ... c c

Page 15: CSCI 3130: Automata theory and formal languages

More examples

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?

✔✔

Page 16: CSCI 3130: Automata theory and formal languages

Example

1

2

L5 = {ss: s ∈ {a, b}*}

wu yxva a a a a a a a a b a a a a a a a a a b

choose nwrite z = uvwxy

z = anbanbi = ?

wxvu ya a a a a a a a a b a a a a a a a a a bWhat if:

Page 17: CSCI 3130: Automata theory and formal languages

Example

1

2

L5 = {ss: s ∈ {a, b}*}

wu yxva a a a a a b b b b b b a a a a a a b b b b b b

choose nwrite z = uvwxy

z = anbnanbn

i = ?

Recall that |vwx| ≤ n

Page 18: CSCI 3130: Automata theory and formal languages

Example

Case 1: w xv

a a a a a a b b b b b b a a a a a a b b b b b b

Three cases

Case 2: w xv

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: w xv

a a a a a a b b b b b b a a a a a a b b b b b b

vwx is in the first half of anbnanbn

vwx is in the middle part of anbnanbn

vwx is in the second half of anbnanbn

Page 19: CSCI 3130: Automata theory and formal languages

Example

Case 1: w xv

a a a a a a b b b b b b a a a a a a b b b b b b

Apply pumping with i = 0

Case 2: w xv

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: w xv

a a a a a a b b b b b b a a a a a a b b b b b b

uwy looks like aibjanbn, where i < n or j < n

uwy looks like anbiajbn, where i < n or j < n

uwy looks like anbnaibj, where i < n or j < n

Page 20: CSCI 3130: Automata theory and formal languages

Example

Case 1:

Apply pumping with i = 0

Case 2:

Case 3:

uv0wx0y looks like aibjanbn, where i < n or j < n

uv0wx0y looks like anbiajbn, where i < n or j < n

uv0wx0y looks like anbnaibj, where i < n or j < n

Not of the form ss

Not of the form ss

Not of the form ss

This covers all the cases, so L5 is not context-free

L5 = {ss: s ∈ {a, b}*}