Presentation is loading. Please wait.

Presentation is loading. Please wait.

January 20, 2016CS21 Lecture 71 CS21 Decidability and Tractability Lecture 7 January 20, 2016.

Similar presentations


Presentation on theme: "January 20, 2016CS21 Lecture 71 CS21 Decidability and Tractability Lecture 7 January 20, 2016."— Presentation transcript:

1 January 20, 2016CS21 Lecture 71 CS21 Decidability and Tractability Lecture 7 January 20, 2016

2 CS21 Lecture 72 Outline non context-free languages deterministic PDAs deciding CFLs

3 January 20, 2016CS21 Lecture 73 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 1.for every i  0, uv i xy i z  L, and 2.|vy| > 0, and 3.|vxy|  p.

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

5 January 20, 2016CS21 Lecture 75 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) uv x yz

6 January 20, 2016CS21 Lecture 76 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.) uv x yz

7 January 20, 2016CS21 Lecture 77 CFL Pumping Lemma Example Theorem: the following language is not context-free: L = {xx : x  {0,1} * }. Proof: –let p be the pumping length for L –try w = 0 p 10 p 1 –can this be pumped?

8 January 20, 2016CS21 Lecture 78 CFL Pumping Lemma Example L = {xx : x  {0,1} * }. –try w = 0 2p 1 2p 0 2p 1 2p –w = uvxyz, with |vy| > 0 and |vxy|  p. –case: vxy in first half. then uv 2 xy 2 z = 0??...?1??...? –case: vxy in second half. then uv 2 xy 2 z = ??...?0??...?1 –case: vxy straddles midpoint then uv 0 xy 0 z = uxz = 0 2p 1 i 0 j 1 2p with i ≠ 2p or j ≠ 2p

9 January 20, 2016CS21 Lecture 79 CFL Pumping Lemma Proof: consider a parse tree for a very long string w  L: S ABC... ADS CSAAB AC SS ADDC BA BA a b aa b bb ab ba bbb long path some non-terminal must repeat on long path

10 January 20, 2016CS21 Lecture 710 CFL Pumping Lemma Schematic proof: uvxyz S A Auvyz S A A uvyz S A A vxy A

11 January 20, 2016CS21 Lecture 711 CFL Pumping Lemma Schematic proof: uvxyz S A Auz S A uz S A x

12 January 20, 2016CS21 Lecture 712 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 ≤ b h (so length > b h implies height > h)

13 January 20, 2016CS21 Lecture 713 CFL Pumping Lemma –let m be the # of nonterminals in the grammar –to ensure path of length at least m+2, require |w| ≥ p = b m+2 –since |w| > b m+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.

14 January 20, 2016CS21 Lecture 714 CFL Pumping Lemma –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, uv i xy i z  L uvxyz S A A –is |vy| > 0 ? smallest parse tree T ensures –is |vxy| ≤ p? red path has length ≤ m+2, so ≤ b m+2 = p leaves

15 January 20, 2016CS21 Lecture 715 Deterministic PDA A NPDA is a 6-tuple (Q, Σ, , δ, q 0, 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  Σ

16 January 20, 2016CS21 Lecture 716 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)

17 January 20, 2016CS21 Lecture 717 Example deterministic PDA L = {0 n 1 n : n  0} (unpictured transitions go to a “reject” state and stay there) ε, ε → $ ■, $ → ε 1, 0 → ε 0, ε → 0 1, 0 → ε Σ = {0, 1}  = {0, 1, $}

18 January 20, 2016CS21 Lecture 718 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

19 January 20, 2016CS21 Lecture 719 Example of problem 0, ε → ε 1, ε → ε ε, ε → $ Language of this DPDA is 0  * ■, ε → ε ε, ε → $

20 January 20, 2016CS21 Lecture 720 Example of problem 0, ε → ε 1, ε → ε ε, ε → $ Language of this DPDA is {  } ■, ε → ε ε, ε → $

21 January 20, 2016CS21 Lecture 721 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

22 January 20, 2016CS21 Lecture 722 Deterministic PDA step 1: keep track of when we have read to end of input ■, ? → ? q0q0 q1q1 q3q3 q2q2 q0’q0’ q1’q1’ q3’q3’ q2’q2’

23 January 20, 2016CS21 Lecture 723 Deterministic PDA step 1: keep track of when we have read to end of input ■, ? → ? q0q0 q1q1 q3q3 q2q2 q0’q0’ q1’q1’ q3’q3’ q2’q2’ for accept state q’: replace outgoing “ε, ? → ?” transition with self-loop with same label

24 January 20, 2016CS21 Lecture 724 Deterministic PDA step 2: eliminate infinite loops –add new “reject” states r’ r a, t →t (for all a, t) ε, t → t (for all t) ■, t → t (for all t)

25 January 20, 2016CS21 Lecture 725 Deterministic PDA step 2: eliminate infinite loops –on input x, if infinite loop, then: stack height time i0i0 i1i1 i2i2 i3i3 infinite sequence i 0 < i 1 < i 2 < … such that for all k, stack height never decreases below ht(i k ) after time i k


Download ppt "January 20, 2016CS21 Lecture 71 CS21 Decidability and Tractability Lecture 7 January 20, 2016."

Similar presentations


Ads by Google