Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of...

28
Overview •Mathematical Induction •Derivations •Recursive Inference •Parse Trees •Equivalence of Inference, Derivations, and Parse Trees

Transcript of Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of...

Page 1: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

Overview

• Mathematical Induction

• Derivations

• Recursive Inference

• Parse Trees

• Equivalence of Inference, Derivations, and Parse Trees

Page 2: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

Mathematical Induction

• Climbing a ladderGiven an infinitely long ladder, can we reach an arbitrarily high rung given that we can reach the first one and on any rung, we can climb up to the next one?

Page 3: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

• There are two operations involved in climbing a ladder:– Opn1 climb onto the first rung– Opn2 climb from the current rung to the next

rung

• Algorithm to reach nth rung is as follows:

Opn1 the basis step

for i = 2 to n do

Opn2 the inductive step

Page 4: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

• Suppose we label the rungs of the ladder with the positive integersOpn1 climb onto Rung 1

Opn2 climb from Rung k to Rung k+1

• For any n, let P( n ) be true if and only if you can get to Rung n. That is, positive integer n has property P

Page 5: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

• If we can prove P (1) and ( k ) [ P ( k ) → P ( k +1)]∀ then we can deduce ( n ) P ( n )∀

• Operationally:P (1) is proved directly;P (1) → P (2) by the inductive step;P (2) → P (3) by the inductive step;P (3) → P (4) by the inductive step;etc.

Page 6: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

Weak Mathematical Induction

• Given a predicate P :: Integer → Boolean,

the principle of weak mathematical induction says that if we prove the two hypotheses– P (1)– ( k ) [ P ( k ) → P ( k+1)]∀

then we can deduce ( n ) P ( n )∀

Page 7: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

Strategy for weak induction

(1)prove base case

(2) assume P ( k ), prove P ( k +1)

Page 8: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

Strong Mathematical Induction

Given predicate P :: Integer → Boolean, the principle of strong mathematical induction says that if we prove the two hypotheses

• P (1)• ( k )[ P (1) … P ( k –1) P ( k ) →P (k+1) ]∀ ∧ ∧ ∧

then we can deduce ( n ) P ( n )∀

Page 9: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

Strong Mathematical Induction

• Stated formally:

P (1) ( k )[( r ) ( r ≤ k → P ( r )) → ∧ ∀ ∀P ( k +1)] → ( n ) P ( n )∀

• We have more true assumptions to use, namely, P (1), …, P ( k )

Page 10: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

when is strong induction needed?

• when the proof of the inductive step involves “looking back” more than 1

• when the proof of the inductive step involves “looking back” an unknown amount

Page 11: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

Significance of MathematicalInduction

• To prove statements that assert a given property holds for all positive integers.

Page 12: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

Derivations• Example: Grammar

for expressions.

E → E + EE → E * EE → (E)E → id

• Show that a string is in the language by means of a derivation:

E E + E (E) + E (E) + E * E (id) + E * E (id) + id * E (id) + id * id

Page 13: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

Leftmost (rightmost) derivation

• Leftmost (rightmost) derivation:

Eliminate the leftmost (rightmost) variable at each step.

• Notation: lm, rm.

Page 14: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

Leftmost (rightmost) derivation

–Leftmost Deriv.E E + E

(E) + E

(id) + E

(id) + E * E

(id) + id * E

(id) + id * id

–Rightmost Deriv.E E + E

E + E * E

E + E * id

E + id * id

(E) + id * id

(id) + id * id

Page 15: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

Recursive InferenceProductions

1: E → I2: E → E + E3: E → E * E4: E → (E)5: I → a6: I → b7: I → Ia8: I → Ib9: I → I010: I → I1

String: a * (a + b00)Deductions:

i: a L(I) , by rule 5ii: b L(I) , by rule 6iii: b0 L(I) , by ii & rule 9iv: b00 L(I) , by iii & rule 9v: a L(E) , by i & rule 1vi: b00 L(E) , by iv & rule 1vii: a + b00 L(E) , by v, vi, & rule 2viii: (a + b00) L(E) , by vii & rule 4ix: a * (a + b00) L(E) , by v, viii & rule 3

Page 16: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

Parse Trees

S

S

(

S

S

)

Root is S.Leaves are in V T {}.Internal nodes are in V.

If then A → X1 … Xn.A

X1 … Xn

Page 17: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

Inference, Derivations, Parse Trees

Derivation

LeftmostDerivation

RightmostDerivation

Parse Tree

RecursiveInference

Thm. 5.12

Thm. 5.14

Thm. 5.18

Page 18: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

Recursive Inference → TreeTheorem 5.12: Let G = (V, T, P, S) be a CFG, w T*, andA V. If w L(A) can be inferred from the recursiveinference procedure, then an A-tree exists with yield w.

Theorem 5.12: Let G = (V, T, P, S) be a CFG, w T*, andA V. If w L(A) can be inferred from the recursiveinference procedure, then an A-tree exists with yield w.

Proof:

The proof is by induction on the number of steps in therecursive inference.

Basis: One step. Then A → w is a production. Thus,there exists a tree A where w = x1x2…xn.

x1 x2 … xn

Page 19: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

StepStep: More than one step. Last step came from lookingat the production A → X1X2…Xn, where it had beenpreviously verified that xi L(Xi) for each i, wherew = x1x2…xn. Therefore, we have the following tree.

A

X1 X2 … Xn

x1 x2 xn

From A → X1X2…Xn

By induction hypothesis

w

Page 20: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

Tree → Derivation

Theorem 5.14: Let G = (V, T, P, S) be a CFG, w T*, andA V. If an A-tree with yield w exists, then there is aleftmost derivation A *lm w in grammar G.

Theorem 5.14: Let G = (V, T, P, S) be a CFG, w T*, andA V. If an A-tree with yield w exists, then there is aleftmost derivation A *lm w in grammar G.

Proof:

The proof is by induction on the tree height.

Basis: Height is one. Tree looks like this: A

So, A → X1X2…Xn = w is a production.X1 … Xn

Page 21: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

StepStep: Height exceeds one. Tree looks like this:

X1 X2 … Xn-1 Xn

A

x1

= x2 = xn

xn-1

= w

Page 22: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

Step (Continued)

X1 X2 … Xn-1 Xn

A

x1

= x2 = xn

xn-1

= w

By induction hypothesis,X1 *lm x1, Xn-1 *lm xn-1, etc.

Trivially, X2 *lm x2,Xn *lm xn, etc.

From this, A X1…Xn,and w = x1…xn, it isquite easy to showA *lm w.

Page 23: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

ExampleCan prove the same thing for rightmost. In fact, theleftmost (rightmost) derivation corresponding to a parsetree is unique.

Example:

S

a A S

S b A a

a b a

Leftmost:S aAs aSbAS aabAS aabbaS aabbaa

Rightmost:S aAS aAa AsbAa aSbbaa aabbaa

Page 24: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

Derivation → Recursive Inference

Theorem 5.18: Let G = (V, T, P, S) be a CFG, w T*, andA V. If a derivation A * w exists in grammar G,then w L(A) can be inferred via the recursive inferenceprocedure.

Theorem 5.18: Let G = (V, T, P, S) be a CFG, w T*, andA V. If a derivation A * w exists in grammar G,then w L(A) can be inferred via the recursive inferenceprocedure.

Proof:

The proof is by induction on the length of the derivation.

Basis: One step. Then A → w is a production, and clearlyw L(A) can be inferred.

Page 25: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

Step

Step: More than one step. We can write the derivation as

A X1X2…Xn * x1x2…xn = w.

By the induction hypothesis, we can infer that xi L(Xi)

for each i. Also A → X1X2…Xn is clearly a production,

and hence we can infer that w L(A).

Page 26: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

Pumping Lemma -- Example

(a) A1 = {0n1n2n|n >= 0}– Assume that A1 is regular– Then the pumping lemma is valid, let p be the pumping

length– Let w = 0p1p2p be in A1,with |w| > p– Let w = xyz and x = 0^(p-1), y= 0, z = 1p2p. (WRONG!) Since |xy|<= p and |y| > 0– According to the pumping lemma w0 = xyyz should be in

A1 but w0 = 0^(p-1)1p2p is not in A1 => contradiction to the assumption

– This means A1 is not regular

Page 27: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

Solution

Page 28: Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.

References• http://undergraduate.csse.uwa.edu.au/units/230.227/lectures/CS227_15_2004_Cond.

pdf

• http://www.cs.unc.edu/~anderson/teach/comp181/slides/05-contextfree.ppt

• http://graphics.cs.ucdavis.edu/~ingrid/Homework/solutions04.pdf

• Text Book: section 5.2