MELJUN CORTES Automata Theory (Automata11)

  • 115 views
Uploaded on

MELJUN CORTES Automata Theory (Automata11)

MELJUN CORTES Automata Theory (Automata11)

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
115
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
2
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. MELJUN P. CORTES, MBA,MPA,BSCS,ACS Fall 2008 CSC 3130: Automata theory and formal languages Limitations of context-free languages MELJUN CORTES
  • 2. Non context-free languages • Recall the pumping lemma for regular languages allows us to show some languages are not regular 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}*} Are these languages context-free?
  • 3. Some intuition L4 = {anbncn: n ≥ 0} • Let’s try to show this is context-free S → aBc B → ?? context-free grammar read a / push 1 ??? read c / pop 1 pushdown automaton
  • 4. More intuition • Suppose we could construct some CFG for L4, e.g. S → BC B → CS | b C → SB | a ... • We do some derivations of “long” strings S ⇒ BC ⇒ CSC ⇒ aSC ⇒ aBCC ⇒ abCC ⇒ abaC ⇒ abaSB ⇒ abaBCB ⇒ ababCB ⇒ ababaB ⇒ ababab
  • 5. More intuition • If derivation is long enough, some variable must appear twice on same path in parse tree S ⇒ BC ⇒ CSC ⇒ aSC ⇒ aBCC ⇒ abCC ⇒ abaC ⇒ abaSB ⇒ abaBCB ⇒ ababCB ⇒ ababaB ⇒ ababab S B C C S S B B C B C a b a b a b
  • 6. More intuition • Then we can “cut and paste” part of parse tree S S ababab ✗ C C B B C S S C a B ababbabb SS B b b C B CB a b S B B C B C B C a b a b a b b b a
  • 7. More intuition • We can repeat this many times ababab ✗ ababbabb ✗ ababbbabbb ababnabnbb • Every sufficiently large derivation will have a part that can be repeated indefinitely – This is caused by cycles in the grammar
  • 8. General picture u u A u A y y v A w A x x v x A v v A uvwxy x A v v A y xvvwxxy w x A x w uv3wx3y
  • 9. Example L4 = {anbncn: n ≥ 0} • If L4 has a context-free grammar G, then If uvwxy can be derived in G, so can uviwxiy for every i • What happens for anbncn? a a a ... a a b b b ... b b c c c ... c c u v w x • No matter how it is split, uv2wx2y ∉ L4! y
  • 10. 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. 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 • Just like for regular languages, need strategy that, regardless of adversary, always wins you this game adversary 1 choose n 2 write z = uvwxy (|vwx| ≤ n,|vx| ≥ 1) you choose z ∈ L choose i you win if uviwxiy ∉ L
  • 13. Example adversary 1 choose n 2 write z = uvwxy you choose z ∈ L choose i you win if uviwxiy ∉ L (|vwx| ≤ n,|vx| ≥ 1) L4 = {anbncn: n ≥ 0} adversary 1 2 you n write z = uvwxy z = anbncn i=? a a a ... a a b b b ... b b c c c ... c c u v w x y
  • 14. Example • Case 1: v or x contains two kinds of symbols a a a ... a a b b b ... b b c c c ... c c v x Then uv2wx2y not in L because pattern is wrong • Case 2: v and x both contain one kind of symbol a a a ... a a b b b ... b b c c c ... c c v x Then uv2wx2y does not have same number of as, bs, cs
  • 15. 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}*}