1 / 28

Today

Today. Chapter 2: (Pushdown automata) Non-CF languages CFL pumping lemma Closure properties of CFL. Pushdown Automata. Pushdown automata are for context-free languages what finite automata are for regular languages.

nira
Download Presentation

Today

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. Today • Chapter 2: • (Pushdown automata) • Non-CF languages • CFL pumping lemma • Closure properties of CFL

  2. Pushdown Automata Pushdown automata are for context-free languages what finite automata are for regularlanguages. PDAs are recognizing automata that have a single stack (= memory):Last-In First-Out pushing and popping Difference: PDAs are inherently nondeterministic.(They are not practical machines.)

  3. x y y z x stack Informal Description PDA (1) input w = 00100100111100101 internal state set Q The PDA M reads w and stack element. Depending on - input wi , - stack sj  , and - state qk  Qthe PDA M: - jumps to a new state, - pushes an element (nondeterministically)

  4. Informal Description PDA (2) input w = 00100100111100101 internal state set Q After the PDA has read complete input, M will be in state  Q If possible to end in accepting state FQ,then M accepts w x y y z x stack

  5. Formal Description PDA • A Pushdown Automata M is defined by asix tuple (Q,,,,q0,F), with • Q finite set of states •  finite input alphabet •  finite stack alphabet • q0 start state  Q • F set of accepting states Q •  transition function : Q      P (Q  )

  6. 0, 0 , $ q2 q1 1, 0 , $ 1, 0 q3 q4 PDA for L = { 0n1n | n0 } Example 2.9: The PDA first pushes “ $ 0n ” on stack. Then, while reading the 1n string, thezeros are popped again.If, in the end, $ is left on stack, then “accept”

  7. 0, 0 , $ q2 q1 1, 0 , $ 1, 0 q3 q4 Machine Diagram for 0n1n • On w = 000111 (state; stack) evolution: • (q1; )  (q2; $)  (q2; 0$)  (q2; 00$) • (q2; 000$)  (q3; 00$)  (q3; 0$)  (q3; $) • (q4; ) This final q4 is an accepting state

  8. 0, 0 , $ q2 q1 1, 0 , $ 1, 0 q3 q4 Machine Diagram for 0n1n On w = 0101 (state; stack) evolution: (q1; )  (q2; $)  (q2; 0$)  (q3; $)  (q4; ) … But we still have part of input “01”. There is no accepting path.

  9. PDAs versus CFL Theorem 2.12: A language L is context-free if and only of there is a pushdown automata M that recognizes L. Two step proof: 1) Given a CFG G, construct a PDA MG 2) Given a PDA M, make a CFG GM

  10. Non-CF Languages The language L = { anbncn | n0 } does notappear to be context-free. Informal: The problem is that every variablecan (only) act ‘by itself’ (context-free). The problem of A * vAy :If S * uAz * uvAyz * uvxyz  L, then S * uAz * uvAyz * … * uviAyiz * uvixyiz  L as well, for all i=0,1,2,…

  11. “Pumping Lemma for CFLs” Idea: If we can prove the existence of derivationsfor elements of the CFL L that use the step A * vAy, then a new form of ‘v-y pumping’ holds: A * vAy * v2Ay2 * v3Ay3 * …) Observation: We can prove this existence if the parse-tree is tall enough.

  12. S b b A c a B c A c c a B c c c Remember Parse Trees Parse tree for S  AbbcBa * cbbccccaBca  cbbccccacca

  13. Pumping a Parse Tree S A A u v x y z If s = uvxyz  L is long, then its parse-tree is tall.Hence, there is a path on which a variable A repeats itself. We can pump this A–A part.

  14. A Tree Tall Enough Let L be a context-free language, and letG be its grammar with maximal b symbols on the right side of the rules: A  X1…Xb A parse tree of depth h produces a stringwith maximum length of bh. Long strings implies tall trees. Let |V| be the number of variables of G.If h = |V|+2 or bigger, then there is a variable ona ‘top-down path’ that occurs more than once.

  15. uvxyz L S A A u v x y z By repeating the A–A part we get…

  16. uv2xy2z L S A A A R y v u x z y x v … while removing the A–-A gives…

  17. uxz  L S A x u z In general uvixyiz  L for all i=0,1,2,…

  18. Pumping Lemma for CFL For every context-free language L, there is a pumping length p, such that for every string sL and |s|p, we can write s=uvxyz with1) uvixyiz  L for every i{0,1,2,…}2) |vy|  13) |vxy|  p Note that 1) implies that uxz  L 2) says that vy cannot be the empty string Condition 3) is not always used

  19. Formal Proof of Pumping Lemma Let G=(V,,R,S) be the grammar of a CFL.Maximum size of rules is b2: A  X1…Xb A string s requires a minimum tree-depth  logb|s|. If |s|  p=b|V|+2, then tree-depth  |V|+2, hence there is a path and variable A where A repeats itself: S * uAz * uvAyz * uvxyz It follows that uvixyiz  L for all i=0,1,2,… Furthermore: |vy|  1 because tree is minimal |vxy|  p because bottom tree with  p leaves has a ‘repeating path’

  20. Pumping anbncn (Ex. 2.20) Assume that B = {anbncn | n0} is CFL Let p be the pumping length, and s = apbpcp  B P.L.: s = uvxyz = apbpcp, with uvixyiz  B for all i0 Options for |vxy|:1) The strings v and y are uniform (v=a…a and y=c…c, for example). Then uv2xy2z will not contain the same number of a’s, b’s and c’s, hence uv2xy2zB 2) v and y are not uniform. Then uv2xy2z will not be a…ab…bc…c Hence uv2xy2zB

  21. Pumping anbncn (cont.) Assume that B = {anbncn | n0} is CFLLet p be the pumping length, and s = apbpcp  BP.L.: s = uvxyz = apbpcp, with uvixyiz  B for all i0 We showed: No options for |vxy| such that uvixyiz  B for all i. Contradiction. B is not a context-free language.

  22. Example 2.21 (Pumping down) Proof that C = {aibjck | 0ijk } is not context-free. Let p be the pumping length, and s = apbpcp  CP.L.: s = uvxyz, such that uvixyiz  C for every i0 Two options for 1  |vxy|  p:1) vxy = a*b*, then the string uv2xy2z has not enough c’s, hence uv2xy2zC 2) vxy = b*c*, then the string uv0xy0z = uxz has too many a’s, hence uv0xy0zC Contradiction: C is not a context-free language.

  23. D = { ww | w{0,1}* } (Ex. 2.22) Carefully take the strings sD.Let p be the pumping length, take s=0p1p0p1p. Three options for s=uvxyz with 1  |vxy|  p:1) If a part of y is to the left of | in 0p1p|0p1p, then second half of uv2xy2z starts with “1” 2) Same reasoning if a part of v is to the right of middle of 0p1p|0p1p, hence uv2xy2z  D 3) If x is in the middle of 0p1p|0p1p, then uxz equals 0p1i 0j1p  D(because i or j < p) Contradiction: D is not context-free.

  24. Pumping Problems Using the CFL pumping lemma is more difficultthan the pumping lemma for regular languages. You have to choose the string s carefully,and divide the options efficiently.Additional CFL properties would be helpful(like we had for regular languages). What about closure under standard operations?

  25. Union Closure Properties Lemma: Let A1 and A2 be two CF languages,then the union A1A2 is context free as well. Proof: Assume that the two grammars areG1=(V1,,R1,S1) and G2=(V2,,R2,S2). Construct a third grammar G3=(V3,,R3,S3) by: V3 = V1 V2{ S3 } (new start variable) with R3 = R1  R2  { S3  S1 | S2 }. It follows that L(G3) = L(G1)  L(G2).

  26. Intersection & Complement? Let again A1 and A2 be two CF languages. One can prove that, in general, the intersection A1 A2 , and the complement Ā1= * \ A1are not context free languages. One proves this with specific counter examples of languages (see homework).

  27. Homework • Exercise 2.2 (a, b) • Exercise 2.7 • Problem 2.18 (a, b, c, d)

  28. Practice Problems • Exercise 2.10 • Problem 2.19 • Problem 2.20 • Problem 2.23

More Related