1 / 20

CSC 3130: Automata theory and formal languages

Fall 2009. The Chinese University of Hong Kong. CSC 3130: Automata theory and formal languages. Limitations of context-free languages. Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130. Non context-free languages.

jules
Download Presentation

CSC 3130: Automata theory and formal languages

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Fall 2009 The Chinese University of Hong Kong CSC 3130: Automata theory and formal languages Limitations of context-free languages Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130

  2. Non context-free languages • Recall the pumping lemma for regular languagesallows us to show some languages are not regularAre 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 = {zzR: z∈ {0, 1}*} L6 = {zz: z∈ {0, 1}*}

  3. Some intuition • Let’s try to show this is context-free L4 = {anbncn: n ≥ 0} read a / push 1 S → aBc ??? B → ?? read c / pop 1 context-free grammar pushdown automaton

  4. More intuition • Suppose we could construct some CFG for L4, e.g. • We do some derivationsof “long” strings • S  BC  CSC  aSC  aBCC  abCC  abaC  abaSB •  abaBCB  ababCB  ababaB •  ababab S  BC B  CS | b C  SB | a . . .

  5. More intuition • If derivation is long enough, some variable mustappear 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. More intuition • Then we can “cut and paste” part of parse tree S S ababbabb ababab ✗ C B B C C S B S a b C C B B C S S B b b a S B B C B C b B C a b a b a b a b

  7. 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 ababbabb ababbbabbb ababab ✗ ✗ ababnabnbb

  8. General picture u y A u A u A v y y x A v v v x A x A x A w v v x A x A w uvwxy uvvwxxy uv3wx3y w

  9. Example L4 = {anbncn: n ≥ 0} • 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 a a a ... a a b b b ... b b c c c ... c c x v w y u

  10. Pumping lemma for context-free languages • Theorem: For every context-free language L There exists a number nsuch 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. x v w y u

  11. Pumping lemma for context-free languages • So to prove L is not context-free, it is enough that For every nthere 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. x v w y u

  12. 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

  13. Example adversary choose nwrite z = uvwxy(|vwx| ≤ n,|vx| ≥ 1) you choose zLchoose iyou win if uviwxiyL 1 2 L4 = {anbncn: n ≥ 0} choose n z= anbncn 1 write z = uvwxy i = ? 2 a a a ... a a b b b ... b b c c c ... c c x v w y u

  14. Example • Case 1:v or x contains two kinds of symbolsThen uv2wx2y not in L because pattern is wrong • Case 2: v and x both contain one kind of symbolThen uv2wx2y does not have same number of as, bs, cs a a a ... a a b b b ... b b c c c ... c c v x a a a ... a a b b b ... b b c c c ... c c v x

  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 = {zzR: z∈ {a, b}*} L6 = {zz: z∈ {a, b}*}

  16. Example L6 = {zz: z∈ {a, b}*} choose n z= anb 1 write z = uvwxy i = ? 2 a a a a a a a a a b a a a a a a a a a b What if: a a a a a a a a a b a a a a a a a a a b x v w y u x v w y u

  17. Example L6 = {zz: z∈ {a, b}*} choose n z= anbn 1 write z = uvwxy i = ? 2 Recall that |vwx| ≤ 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 x v w y u

  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 Case 1: x v w 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: x v w 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: x v w 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: x v w uv0wx0y 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: x v w uv0wx0y 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: x v w uv0wx0y looks like anbnaibj, where i < n or j < n

  20. Example Apply pumping with i = 0 Case 1: uv0wx0y looks like aibjanbn, where i < n or j < n Not of the form zz Case 2: uv0wx0y looks like anbiajbn, where i < n or j < n Not of the form zz uv0wx0y looks like anbnaibj, where i < n or j < n Case 3: Not of the form zz This covers all the cases, so L6 is not context-free

More Related