13
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

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

Embed Size (px)

Citation preview

Page 1: 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

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

Page 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

Page 3: 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

Idea of Pumping Lemma for Context-Free Languages

S * uAz where A is a variable, u and z are in *

uAz * uvAyz * uvxyz where v, x and y are in *

S * uv2xy2z

uv10xy10z

uvnxynz for n = 1, 2, 3, …

Page 4: 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

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:

1. w = uvxyz2. |vxy| n3. v e or y e 4. uvixyiz L, for each i = 0, 1, 2, …

Page 5: 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

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}

421

F(G) = 4

Page 6: 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

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)

S

a S b S

aa b S b

e

Page 7: 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

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

Page 8: 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

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.

Page 9: 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

Proof (2)

R

ak

T

…A

A…

ama1 aiaj al ap

u v x y z

w = a1 …. ap

P has at least |V| + 2nodes

Page 10: 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

Example

• {anbncn | n = 0, 1, 2, …} is not context-free

• {ww | w {a,b}*}

Page 11: 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

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

Page 12: 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

Context-Free is not Closed under Intersection, Complement (2)

Proof (complement). By contradiction: suppose that the complement of a context-free language is always context-free. We show that this implies that the intersection must always be context free:

L M = (Lc Mc)c

Page 13: 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

Homework

• 2.30 (a)

• 2.31

• 2.32

• Show that the set of all context-free languages is not closed under intersection