80 likes | 201 Views
L ECTURE 9 Theory of Computation Review Pumping Lemma for CFLs Correctness of CFGs. Intro to Theory of Computation. CS 464. Sofya Raskhodnikova. Pumping lemma for CFLs. Let L be a context-free language. Then there exists P such that For every w L with |w| ≥ P.
E N D
LECTURE9 • Theory of Computation • Review • Pumping Lemma for CFLs • Correctness of CFGs Intro to Theory of Computation CS 464 Sofya Raskhodnikova Sofya Raskhodnikova; based on slides by Nick Hopper
Pumping lemma for CFLs Let L be a context-free language Then there exists P such that For every w L with |w| ≥ P there exist uvxyz=w, where: 1. |vy| > 0 2. |vxy| ≤ P 3. uvixyiz L for all i ≥ 0
Negating the pumping lemma L is not context-free Let L be a context-free language. Then there exists P such that For every w L with |w| ≥ P for every P, If There is a For every there exist uvxyz=w, where: 1. |vy| > 0 2. |vxy| ≤ P There is an 3. For every i ≥ 0, uvixyiz L
Using the pumping lemma Prove L = {w#wR | w 2 {0,1}* and #1s = #0s} is not context-free Assume L is context-free. Then there is a pumping length P. No matter what P is, the string s = 0P1P#1P0P has |s| ¸ P and s 2 L. So there should be uvxyz=s with: 1) |vy| > 0, 2) |vxy| · P, 3) 8i, uvixyiz2 L. P P P P s = 00…0011…11#11…1100…00
{w#wR | w 2 {0,1}* and #1s = #0s}is not a CFL: proof Assume L is context-free. Then there is a pumping length P. vxy cannot be only in either half, since pumping would make one side of # longer than the other. since # is in x and |vxy| · P, neither v nor y can have 0s, and at least one must have a 1. Then uv2xy2z has more 1s than 0s and is not in L. No matter what P is, the string s = 0P1P#1P0P has |s| ¸ P and s 2 L. # cannot be in v or y since pumping would add too many #s. So it must be in x. So there should be uvxyz=s with: 1) |vy| > 0, 2) |vxy| · P, 3) 8 i, uvixyiz 2 L. P P P P s = 00…0011…11#11…1100…00 vxy
Give the language of this CFG Answer: the set of all strings over alphabet {a,b} that have the same number of ’s and ’s Prove that your answer is correct
Proof of correctness Every generated string has the same number of ’s and ’s Proof: Every rule that generates terminals, generates the same number of ’s and ’s Sofya Raskhodnikova; based on slides by Nick Hopper
Proof of correctness Every string that has the same number of ’s and ’s is generated. Proof idea: Consider a string that has the same number of ’s and ’s. Plot ’s of ’s in the first characters of as a function of (Done on the board). Sofya Raskhodnikova; based on slides by Nick Hopper