1 / 23

CS21 Decidability and Tractability

CS21 Decidability and Tractability. Lecture 7 January 22, 2014. Outline. proof of CFL pumping lemma deterministic PDAs deciding CFLs. Pumping Lemma for CFLs.

miakoda
Download Presentation

CS21 Decidability and Tractability

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. CS21 Decidability and Tractability Lecture 7 January 22, 2014 CS21 Lecture 7

  2. Outline • proof of CFL pumping lemma • deterministic PDAs • deciding CFLs CS21 Lecture 7

  3. Pumping Lemma for CFLs CFL Pumping Lemma: Let L be a CFL. There exists an integer p (“pumping length”) for which every w  L with |w|  p can be written as w = uvxyz such that • for every i  0, uvixyiz  L , and • |vy| > 0, and • |vxy|  p. CS21 Lecture 7

  4. CFL Pumping Lemma Example Theorem: the following language is not context-free: L = {anbncn : n ≥ 0}. • Proof: • let p be the pumping length for L • choose w = apbpcp w = aaaa…abbbb…bcccc…c • w = uvxyz, with |vy| > 0 and |vxy|  p. CS21 Lecture 7

  5. CFL Pumping Lemma Example • possibilities: w = aaaa…aaabbb…bbcccc…c (if v, y each contain only one type of symbol, then pumping on them produces a string not in the language) u v y z x CS21 Lecture 7

  6. CFL Pumping Lemma Example • possibilities: w = aaaa…abbbb…bccccc…c (if v or y contain more than one type of symbol, then pumping on them might produce a string with equal numbers of a’s, b’s, and c’s – if vy contains equal numbers of a’s, b’s, and c’s. But they will be out of order.) u v y z x CS21 Lecture 7

  7. CFL Pumping Lemma Proof: consider a parse tree for a very long string w  L: long path S . . . A B C . . . . . . A D S C S A A B a A C b A D D C B A a b b S S b b B A b b b some non-terminal must repeat on long path a a b a CS21 Lecture 7

  8. CFL Pumping Lemma S • Schematic proof: S A S A A A A u v y z u v x y z A u v y z A v x y CS21 Lecture 7

  9. CFL Pumping Lemma S • Schematic proof: S A S A A A u z u v x y z x u z CS21 Lecture 7

  10. CFL Pumping Lemma • how large should pumping length p be? • need to ensure other conditions: |vy| > 0 |vxy| ≤ p • b = max # symbols on rhs of any production (assume b ≥ 2) • if parse tree has height ≤ h, then string generated has length ≤ bh (so length > bh implies height > h) CS21 Lecture 7

  11. CFL Pumping Lemma • let m be the # of nonterminals in the grammar • to ensure path of length at least m+2, require |w| ≥ p = bm+2 • since |w| > bm+1, any parse tree for w has height > m+1 • let T be the smallest parse tree for w • longest root-leaf path must consist of ≥ m+1 non-terminals and 1 terminal. CS21 Lecture 7

  12. CFL Pumping Lemma S • must be a repeated non-terminal A on long path • select a repetition among the lowest m+1 non-terminals on path. • pictures show that for every i  0, uvixyiz  L A A u v x y z • is |vy| > 0 ? • smallest parse tree T ensures • is |vxy| ≤ p? • red path has length ≤ m+2, so ≤ bm+2 = p leaves CS21 Lecture 7

  13. Deterministic PDA • A NPDA is a 6-tuple (Q, Σ, , δ, q0, F) where: • δ:Q x (Σ {ε}) x ( {ε}) → (Q x ( {ε})) is a function called the transition function • A deterministic PDA has only one option at every step: • for every state q  Q, a  Σ, and t  (  {ε}), exactly 1 element in δ(q, a, t), or • exactly 1 element in δ(q, ε, t), andδ(q, a, t) empty for all a  Σ CS21 Lecture 7

  14. Deterministic PDA • A technical detail: we will give our deterministic machine the ability to detect end of input string • add special symbol ■ to alphabet • require input tape to contain x■ • language recognized by a deterministic PDA is called a deterministic CFL (DCFL) CS21 Lecture 7

  15. Example deterministic PDA L = {0n1n : n  0} (unpictured transitions go to a “reject” state and stay there) 0, ε→ 0 ε, ε→ $ Σ = {0, 1}  = {0, 1, $} 1, 0→ε ■, $→ε 1, 0→ε CS21 Lecture 7

  16. Deterministic PDA Theorem: DCFLs are closed under complement (complement of L in Σ* is (Σ* - L) ) Proof attempt: • swap accept/non-accept states • problem: might enter infinite loop before reading entire string • machine for complement must accept in these cases, and read to end of string CS21 Lecture 7

  17. Example of problem 1, ε→ε 0, ε→ε 0, ε→ε ■, ε→ε ■, ε→ε 1, ε→ε ε, ε→ $ ε, ε→ $ Language of this DPDA is 0* CS21 Lecture 7

  18. Example of problem 1, ε→ε 0, ε→ε 0, ε→ε ■, ε→ε ■, ε→ε 1, ε→ε ε, ε→ $ ε, ε→ $ Language of this DPDA is {} CS21 Lecture 7

  19. Deterministic PDA Proof: • convert machine into “normal form” • always reads to end of input • always enters either an accept state or single distinguished “reject” state • step 1: keep track of when we have read to end of input • step 2: eliminate infinite loops CS21 Lecture 7

  20. Deterministic PDA step 1: keep track of when we have read to end of input q0’ q0 q1 q1’ ■, ? → ? ■, ? → ? q3 q3’ q2 q2’ CS21 Lecture 7

  21. Deterministic PDA step 1: keep track of when we have read to end of input ■, ? → ? q0’ q0 q1 q1’ ■, ? → ? q3 q3’ q2 q2’ for accept state q’: replace outgoing “ε, ? → ?” transition with self-loop with same label CS21 Lecture 7

  22. Deterministic PDA step 2: eliminate infinite loops • add new “reject” states a, t →t (for all a, t) ε, t → t (for all t) r’ r ■, t → t (for all t) CS21 Lecture 7

  23. Deterministic PDA step 2: eliminate infinite loops • on input x, if infinite loop, then: stack height time i0 i1 i2 i3 infinite sequence i0< i1< i2< … such that for all k, stack height never decreases below ht(ik) after time ik CS21 Lecture 7

More Related