Hmewrk #7 #1. True/ False a. The Pumping Lemma fr CFL s can be used t shw a language is cntext-free b. The string z = a k b k+1 c k can be used t shw {a n b n c n } is nt cntext free c. The string z = a k a k a k can be used t shw {w w R w w ε {a,b}* } is nt cntextfree d. Given a CFG, G, a string w, it is decidable whether w ε L(G) e. The intersectin f a cntext-free language a regular language is cntext-free #2. Why must we remve the recursive Start t cnvert t Chmsky Nrmal frm? If S ccurs n the right h side, S λ is a prductin, then S can ccur in the middle f a derivatin essentially shrten a sentential frm. We dn t want this because we want a relatinship between the length f the derivatin the length f the string generated. #3. What is the relatinship between the length f a string the length f its derivatin if the grammar is in Greibach nrmal Frm? If there are n lambda prductins, each prductin prduces exactly 1 terminal, s the derivatin is the same as the string length in this case. #4. Cnvert the fllwing grammar t Chmsky Nrmal Frm. Shw wrk clearly. Slutin Remve Recursive Start:
Remve λ Prductins: A is nullable, but the thers are nt (n prductin has an A n its rhs). New grammar: S S A B DD BCB D B AB B C Remve unit rules: S asb BB BCD ab BC A AB Cc c DD BCB Scc cc B AB Cc c Remve useless: Term = {D, C, A, S, S } s all useful s far Reach = {S, S, B, C, D, A} s all useful: S asb BB BCD ab BC A AB Cc c DD BCB Scc cc B AB Cc c
Cnvert t CNF (lts f ways t d this) S AT 1 BB B T 3 A T 2 BC A a T 1 S T 2 T 2 b T 3 CD A AB CT4 c DD BT 6 Scc cc S AT 1 BB B T 3 A T 2 BC B AB CT 4 c T 4 c D S T 5 T 4 T 4 T 5 T 4 T 4 T 6 CB #5. Shw the fllwing languages are r are nt cntext-free: a) {a i b j c m i j m} Many f yu tld me this was nt cntext-free. I think yu gt caught in what i j m means. Nte that when i = 2, j = 3, m = 2, i j m. ( is nt transitive). Here is a grammar: In what fllws: A generates 0 r mre a s B generates 0 r mre b s C generates 0 r mre c s E first generates an equal number f b s c s then 1 r mre b s (via B) r 1 r mre c s (via cc). S E b*c* (#b #c) Similarly D a*b* (#a #b) It is cntext-free: S A E D C A a A λ B b B b C c C λ D a D b B a A E b E c B cc S A E a A E a a A E a a E a a b E c a a b b E c c aabbbcc etc. b) {a i b j c m i < j < m; i,j,k > 0}
Nt cntext free: Let n be the integer frm the CFL pumping lemma Chse x = a n b n+1 c n+2 Cnsider all strings u, v, w, y, z such that x = uvwyz vwy <= n vy >= 1 There are five pssible cases fr strings v y v y cntain at least 1 a 0 b's c's v y cntain at least 1 a 1 b 0 c's v y cntain at least 1 b 0 a's c's v y cntain at least 1 b 1 c 0 a's v y cntain at least 1 c 0 a's b's In summary, v y cannt cntain bth a's c's. This fllws frm the fact that vwy <= n v y must cntain at least ne character This fllws frm the fact that vy >= 1 We will shw fr each case that there exists a k such that uv k wy k z is nt in L Case 1: v y cntain at least 1 a 0 b's c's Chse k=2 uv 2 wy 2 z is nt in L uv 2 wy 2 z cntains exactly n+1 b's exactly n+1 b's v y cntain 0 b's uv 2 wy 2 z cntains at least n+1 a's This fllws frm uvwyz cntains exactly n a's v y cntain at least 1 a Case 2: v y cntain at least 1 a b 0 c's Chse k=2 uv 2 wy 2 z is nt in L uv 2 wy 2 z cntains exactly n+2 c's exactly n+2 c's v y cntain 0 c's uv 2 wy 2 z cntains at least n+2 b's This fllws frm uvwyz cntains exactly n+1 b's v y cntain at least 1 b Case 3: v y cntain 0 a's c's at least 1 b Chse k=2 Culd chse k=0 as well
uv 2 wy 2 z is nt in L uv 2 wy 2 z cntains exactly n+2 c's exactly n+2 c's v y cntain 0 c's uv 2 wy 2 z cntains at least n+2 b's This fllws frm uvwyz cntains exactly n+1 b's v y cntain at least 1 b Case 4: v y cntain 0 a's at least 1 b 1 c Chse k=0 uwz is nt in L uwz cntains exactly n a's exactly n a's v y cntain 0 a's uwz cntains at mst n b's This fllws frm uvwyz cntains exactly n+1 b's v y cntain at least ne b Case 5: v y cntain 0 a's b's at least 1 c Chse k=0 uwz is nt in L uwz cntains exactly n+1 b's exactly n+1 b's v y cntain 0 b's uwz cntains at mst n+1 c's This fllws frm uvwyz cntains exactly n+2 c's v y cntain at least 1 c In all cases, we have shwn that there exists a chice f k such that uv k wy k z is nt in L. Thus L des nt satisfy the pumping cnditin. Thus L is nt a cntext-free language.