1 / 13

Test # 2

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.

liana
Télécharger la présentation

Test # 2

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. 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

  2. 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

  3. 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, …

  4. 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, …

  5. 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

  6. 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)

  7. 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

  8. 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.

  9. 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

  10. Example • {anbncn | n = 0, 1, 2, …} is not context-free • {ww | w {a,b}*}

  11. 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

  12. 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

  13. Homework • 2.30 (a) • 2.31 • 2.32 • Show that the set of all context-free languages is not closed under intersection

More Related