+ All Categories
Home > Technology > MELJUN CORTES Automata Theory (Automata11)

MELJUN CORTES Automata Theory (Automata11)

Date post: 26-Jun-2015
Category:
Upload: meljun-cortes
View: 143 times
Download: 2 times
Share this document with a friend
Description:
MELJUN CORTES Automata Theory (Automata11)
Popular Tags:
15
CSC 3130: Automata theory and formal languages Limitations of context-free languages Fall 2008 MELJUN P. CORTES, MBA,MPA,BSCS,ACS MELJUN P. CORTES, MBA,MPA,BSCS,ACS MELJUN CORTES MELJUN CORTES
Transcript
Page 1: MELJUN CORTES Automata Theory (Automata11)

CSC 3130: Automata theory and formal languages

Limitations of context-free languages

Fall 2008MELJUN P. CORTES, MBA,MPA,BSCS,ACSMELJUN P. CORTES, MBA,MPA,BSCS,ACS

MELJUN CORTESMELJUN CORTES

Page 2: MELJUN CORTES Automata Theory (Automata11)

Non context-free languages

• Recall the pumping lemma for regular languagesallows 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}*}

Page 3: MELJUN CORTES Automata Theory (Automata11)

Some intuition

• Let’s try to show this is context-free

L4 = {anbncn: n ≥ 0}

context-free grammar pushdown automaton

S → aBc B → ??

read a / push 1

read c / pop 1???

Page 4: MELJUN CORTES Automata Theory (Automata11)

More intuition

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

• We do some derivationsof “long” strings

S BCB CS | bC SB | a

. . .

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

Page 5: MELJUN CORTES Automata Theory (Automata11)

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

Page 6: MELJUN CORTES Automata Theory (Automata11)

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 SS

B CBa

b a b

bC

S

ababab ababbabb✗

Page 7: MELJUN CORTES Automata Theory (Automata11)

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

Page 8: MELJUN CORTES Automata Theory (Automata11)

General picture

u u

v v

vw

x

yy

u

v

v

v

w

x

y

uvwxy uv3wx3y

A

A

A

A

A

A

A

A

A

x

x

x

x

wxvvwxxy

Page 9: MELJUN CORTES Automata Theory (Automata11)

Example

• 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

L4 = {anbncn: n ≥ 0}

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

Page 10: MELJUN CORTES Automata Theory (Automata11)

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.

wu yxv

Page 11: MELJUN CORTES Automata Theory (Automata11)

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: MELJUN CORTES Automata Theory (Automata11)

Proving language is not context-free• Just like for regular languages, need 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

Page 13: MELJUN CORTES Automata Theory (Automata11)

Example

adversary

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

you

choose z Lchoose iyou win if uviwxiy L

1

2

adversary

nwrite z = uvwxy

you

z = anbncn

i = ?1

2

L4 = {anbncn: n ≥ 0}

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

Page 14: MELJUN CORTES Automata Theory (Automata11)

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

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: MELJUN CORTES Automata Theory (Automata11)

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}*}


Recommended