130 likes | 360 Views
Test # 2. Friday, November 2 nd Covers all of Chapter 2 Test # 2 will be 20% of final score (same as Test #1) Final Exam will be 40% of the final score. Solution Exercise 2.23 (credits to Jeff Kleeblatt for finding this elegant solution). S AB | BA A XAX | 1 B XBX | 0 X 0 | 1.
E N D
Test # 2 • Friday, November 2nd • Covers all of Chapter 2 • Test # 2 will be 20% of final score (same as Test #1) • Final Exam will be 40% of the final score
Solution Exercise 2.23(credits to Jeff Kleeblatt for finding this elegant solution) • S AB | BA • A XAX | 1 • B XBX | 0 • X 0 | 1
Idea of Pumping Lemma for Context-Free Languages S * uAz whereA is a variable, u and z are in * uAz * uvAyz * uvxyz wherev, x and y are in * uv2xy2z S * uv10xy10z uvnxynz for n = 1, 2, 3, …
Pumping Lemma for Context-Free Grammars • Pumping Lemma for Context-Free Grammars. Given a context-free grammar G = (,V,R,S), there exists • n > 0 such that: • For any string w L with |w| n, there are u, v, x, y, z in * for which the following holds: • w = uvxyz • |vxy| n • v e or y e • uvixyiz L, for each i = 0, 1, 2, …
4 2 1 Preliminaries of the Proof Definition. Given a grammar G, the fanout of G, denoted f(G), is the greatest number of symbols on the right side of a rule in G Example: G ={ S aSbS, S ab, S e } F(G) = 4
S a S b S b a S a b e Preliminaries the Proof (2) S aSbS aSbaSb aSbab a2b2ab Parse Tree: • What is the maximum number of children for any node in this parse tree? F(G)
Preliminaries (3) Lemma. Given a grammar G and a parse tree T for G, let w be the word contained in T, then: if length(w) > F(G)h, then height(T) > h Proof. The maximum number of leaves in a parse tree of height h is F(G)h = maximum number of characters of any word for that tree
Proof of Pumping Lemma Proof. Let n = F(G)|V|+1 Consider any w L(G) with |w| n Let T be a parse tree for w with the smallest height Let P be a path of length h, such that h is the height of T. Since |w| F(G)|V|+1, then length(P) |V| + 1 Thus, the number of nodes in P is at least |V| + 2 Thus, there must be at least one repeated variable A.
w = a1 …. ap P has at least |V| + 2 nodes y z x v u Proof (2) T R … A … A … ak aj al am ap a1 ai
Example • {anbncn | n = 0, 1, 2, …} is not context-free • {ww | w {a,b}*}
Context-Free is not Closed under Intersection , Complement • Theorem. Let L and M two context-free languages. Then • L M is not necessarily context-free • Lc is not necessarily context-free Proof (intersection). Homework (Friday): find a counter-example
Context-Free is not Closed under Intersection, Complement (2) Proof (complement). By contradiction: suppose that the complement of a context-free languageis always context-free. We show that this implies that the intersection must always be context free: L M = (Lc Mc)c
Homework • 2.30 (a) • 2.31 • 2.32 • Show that the set of all context-free languages is not closed under intersection