Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees."— Presentation transcript:

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

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

3 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

4 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

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

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

7 Strategy for weak induction (1)prove base case (2) assume P ( k ), prove P ( k +1)

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

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

10 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

11 Significance of Mathematical Induction To prove statements that assert a given property holds for all positive integers.

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

13 Leftmost (rightmost) derivation Leftmost (rightmost) derivation: Eliminate the leftmost (rightmost) variable at each step. Notation:  lm,  rm.

14 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

15 Recursive Inference 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

16 Parse Trees S S ( S S  ) Root is S. Leaves are in V  T  {  }. Internal nodes are in V. If then A → X 1 … X n. A X 1 … X n

17 Inference, Derivations, Parse Trees Derivation Leftmost Derivation Rightmost Derivation Parse Tree Recursive Inference Thm. 5.12 Thm. 5.14 Thm. 5.18

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. 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 = x 1 x 2 …x n. x 1 x 2 … x n

19 Step Step: More than one step. Last step came from looking at the production A → X 1 X 2 …X n, where it had been previously verified that x i  L(X i ) for each i, where w = x 1 x 2 …x n. Therefore, we have the following tree. A X 1 X 2 … X n x 1 x 2 x n From A → X 1 X 2 …X n By induction hypothesis w

20 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. 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 → X 1 X 2 …X n = w is a production. X 1 … X n

21 Step Step: Height exceeds one. Tree looks like this: X 1 X 2 … X n-1 X n A x1x1 = x 2 = x n x n-1 = w

22 Step (Continued) X 1 X 2 … X n-1 X n A x1x1 = x 2 = x n x n-1 = w By induction hypothesis, X 1 *  lm x 1, X n-1 *  lm x n-1, etc. Trivially, X 2 *  lm x 2, X n *  lm x n, etc. From this, A  X 1 …X n, and w = x 1 …x n, it is quite easy to show A *  lm w.

23 Example Can prove the same thing for rightmost. In fact, the leftmost (rightmost) derivation corresponding to a parse tree 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

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

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

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

27 Solution

28 References http://undergraduate.csse.uwa.edu.au/units/230.227/lectures/CS227_15_2004_Cond. pdfhttp://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


Download ppt "Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees."

Similar presentations


Ads by Google