280 likes | 412 Views
Overview. Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees. Mathematical Induction. Climbing a ladder
E N D
Overview • Mathematical Induction • Derivations • Recursive Inference • Parse Trees • Equivalence of Inference, Derivations, and Parse Trees
Mathematical Induction • Climbing a ladder Given 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?
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
Suppose we label the rungs of the ladder with the positive integers Opn1 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
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.
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 )
Strategy for weak induction • prove base case (2) assume P ( k ), prove P ( k +1)
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 )
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 )
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
Significance of MathematicalInduction • To prove statements that assert a given property holds for all positive integers.
Example: Grammar for expressions. E → E + E E → E * E E → (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 Derivations
Leftmost (rightmost) derivation • Leftmost (rightmost) derivation: Eliminate the leftmost (rightmost) variable at each step. • Notation:lm, rm.
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 Leftmost (rightmost) derivation
Productions 1: E → I 2: E → E + E 3: E → E * E 4: E → (E) 5: I → a 6: I → b 7: I → Ia 8: I → Ib 9: I → I0 10: I → I1 String:a * (a + b00) Deductions: i: a L(I) , by rule 5 ii: b L(I) , by rule 6 iii: b0 L(I) , by ii & rule 9 iv: b00 L(I) , by iii & rule 9 v: a L(E) , by i & rule 1 vi: b00 L(E) , by iv & rule 1 vii: a + b00 L(E) , by v, vi, & rule 2 viii: (a + b00) L(E) , by vii & rule 4 ix: a * (a + b00) L(E) , by v, viii & rule 3 Recursive Inference
Parse Trees Root is S. Leaves are in V T {}. Internal nodes are in V. If then A → X1 … Xn. S S S A ( ) S X1 … Xn
Inference, Derivations, Parse Trees Leftmost Derivation Thm. 5.14 Derivation Parse Tree Rightmost Derivation Thm. 5.12 Recursive Inference Thm. 5.18
Recursive Inference → Tree Theorem 5.12: Let G = (V, T, P, S) be a CFG, w T*, and A V. If w L(A) can be inferred from the recursive inference procedure, then an A-tree exists with yield w. Proof: The proof is by induction on the number of steps in the recursive inference. Basis: One step. Then A → w is a production. Thus, there exists a tree A where w = x1x2…xn. x1 x2 … xn
Step Step: More than one step. Last step came from looking at the production A → X1X2…Xn, where it had been previously verified that xi L(Xi) for each i, where w = x1x2…xn. Therefore, we have the following tree. A From A → X1X2…Xn X1 X2 … Xn By induction hypothesis x1 x2 xn w
Tree → Derivation Theorem 5.14: Let G = (V, T, P, S) be a CFG, w T*, and A V. If an A-tree with yield w exists, then there is a leftmost 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
Step A X1 X2 … Xn-1 Xn = xn = x2 xn-1 x1 = w Step: Height exceeds one. Tree looks like this:
Step (Continued) A X1 X2 … Xn-1 Xn = xn = x2 xn-1 x1 = 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 is quite easy to show A *lm w.
Example S a A S S b A a a b a Can prove the same thing for rightmost. In fact, the leftmost (rightmost) derivation corresponding to a parse tree is unique. Example: Leftmost: S aAs aSbAS aabAS aabbaS aabbaa Rightmost: S aAS aAa AsbAa aSbbaa aabbaa
Derivation → Recursive Inference Theorem 5.18: Let G = (V, T, P, S) be a CFG, w T*, and A V. If a derivation A * w exists in grammar G, then w L(A) can be inferred via the recursive inference procedure. Proof: The proof is by induction on the length of the derivation. Basis: One step. Then A → w is a production, and clearly w L(A) can be inferred.
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).
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
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