770 likes | 840 Views
Induction and Recursion. Chapter 5. Chapter Summary. Mathematical Induction Strong Induction Well-Ordering Recursive Definitions Structural Induction Recursive Algorithms Program Correctness ( not yet included in overheads ). Mathematical Induction. Section 5.1. Section Summary.
E N D
Induction and Recursion Chapter 5
Chapter Summary • Mathematical Induction • Strong Induction • Well-Ordering • Recursive Definitions • Structural Induction • Recursive Algorithms • Program Correctness (not yet included in overheads)
Mathematical Induction Section 5.1
Section Summary Mathematical Induction Examples of Proof by Mathematical Induction Mistaken Proofs by Mathematical Induction Guidelines for Proofs by Mathematical Induction
Climbing an Infinite Ladder Suppose we have an infinite ladder: We can reach the first rung of the ladder. If we can reach a particular rung of the ladder, then we can reach the next rung. From (1), we can reach the first rung. Then by applying (2), we can reach the second rung. Applying (2) again, the third rung. And so on. We can apply (2) any number of times to reach any particular rung, no matter how high up. This example motivates proof by mathematical induction.
Peano’s Postulates • In the work FormularioMatematico, published 1889, Giuseppe Peano formulated the set of nonnegative integers on the basis of three terms: zero, number, and successor. • Peano’s postulates: • Zero is a number. • For any number n, its successor is a number. • No number has zero as its successor. • If two numbers m and n have the same successor, the m=n. • If T is a set of numbers where 0T and the successor of n is in T whenever n is in T, then T is the set of all numbers.
Constructive Theory • The theory is used to formally construct a class of objects recursively and prove properties of the class objects inductively. • The construction process include the following steps: Step 1: A set of basic elements. Step 2: A basic element recognizer, to recognize basic elements. Step 3: A constructor to construct other elements. Step 4: A recognizer to recognize elements of the class. Step 5: A destructor to access “previous” elements of the class. Step 6: A well-founded relation to compare “measurement” of the elements. Step 7: Sound axioms for the elements of the class. • Predicate L(x, y) is a well-founded relation, if for all x and y, when L(x, y)=true, there does not exist an infinite sequence x1, x2, , xn and x1=x, xn=y, such that L(xk, xk+1)=true, for all 1k<n. • For N, “< ” is a well-founded relation; “” is not a well-founded relation.
Natural Numbers • Construction of natural numbers N: • Basic elements: 0N (zero) • Basic elements recognizer: zerop(x) if (x=0) thentrueelsefalse. • Constructor: ifxNthenadd1(x)N. • Recognizer: numberp(x) if (xN) thentrueelsefalse • Destructor: if x is a non-zero element, sub1(x) is also a natural number • sub1(add1(x)) = x • if zerop(x)then add1(sub1(x)) = x • Well-founded relation: lessp (<) lessp(x, y) if (zerop(y))thenfalse elseif (zerop(x))thentrue elselessp(sub1(x), sub1(y))
Natural Numbers (cont’d) • Numbers 1, 2, 3, 4, 5, are only symbols representing: • 1: add1(0) sub1(1) = sub1(add1(0)) = 0 • 2: add1(1) = add1(add1(0)) sub1(2) = sub1(add1(1)) = 1 • 3: add1(2) = add1(add1(1)) = add1(add1(add1(0))) • 4: add1(3) = add1(add1(add1(add1(0)))) • 5: add1(5) = add1(add1(add1(add1(add1(0))))) • 2<5: lessp(2, 5) = lessp(sub1(2), sub1(5)) = lessp(1, 4) = lessp(0, 3) = true • 3<2: lessp(3, 2) = lessp(sub1(3), sub1(2)) = lessp(2, 1) = lessp(1, 0) = false
Recursion: Addition and Multiplication • Addition: x+y plus(x, y) ifzerop(x) theny elseadd1(plus(sub1(x), y)) plus(2, 3) = add1(plus(1, 3)) = add1(add1(plus(0, 3))) = add1(add1(3)) = add1(4) =5 • Multiplication: xy multiply(x, y) ifzerop(x) then 0 elseplus(multiply(sub1(x), y), y) multiply(3, 5) = plus(multiply(2, 5), 5) = plus(plus(multiply(1, 5), 5) 5) = plus(plus(plus(multiply(0, 5), 5) 5), 5) = plus(plus(plus(0, 5), 5), 5) = plus(plus(5, 5), 5) = plus(10, 5) = 15
Induction: Commutative Law of Addition • Assume the two lemmas hold: Lemma 1: plus(x, 0) = x Lemma 2: add1(plus(x, y)) = plus(x, add1(y)) • Prove plus(x, y) = plus(y, x) Basis step: plus(0, y)=y (plus definition) plus(y, 0)=y (Lemma 1) plus(0, y) = plus(y, 0) Inductive step: inductive hypothesis plus(sub1(x), y) = plus(y, sub1(x)) plus(x, y) = add1(plus(sub1(x), y)) (plus definition) = add1(plus(y, sub1(x))) (inductive hypothesis) = plus(y, add1(sub1(x))) (Lemma 2) = plus(y, x) (Axiom)
Principle of Mathematical Induction • To prove that P(n) is true for all natural numbers in N, where P(n) is a positional function, two steps are completed: Basis step: Verify P(0) is true. Inductive step: Show the conditional statement P(k)P(k+1) for all natural number k. • Predicate P(k)intheinductivestepiscalledinductive hypothesis. • In the textbook, the principle of mathematical induction is stated for positive integers, N+. In this case the basis step is changed to P(1).
Important Points About Using Mathematical Induction (P(1) ∧ ∀k (P(k)→ P(k + 1))) → ∀n P(n), Mathematical induction can be expressed as the rule of inference where the domain is the set of positive integers. In a proof by mathematical induction, we don’t assume that P(k) is true for all positive integers! We show that if we assume that P(k) is true, then P(k + 1) must also be true.
A Simple Example • Prove Basis step: so P(0) is true. Inductive step: Inductive hypothesis: holds. is true. Q.E.D.
Summation of Even Numbers • Formulate summation of the first n even numbers: • Proof: Basis step: n=1, Inductive step: Inductive hypothesis: Q.E.D.
Summation of Odd Numbers • Formulate summation of the first n odd numbers: • Proof: Basis step: n=1, Inductive step: Inductive hypothesis: Q.E.D.
Summation of Squares • Recall that • Proof: Basis Step: Inductive Step: Inductive hypothesis: To be continued.
Summation of Arithmetic Progression Revisit • Recall that Proof: Basis step: Inductive step: Inductive hypothesis: Q.E.D.
Summation of Geometric Progression Revisit • Recall that Proof: Basis step: Inductive step: Inductive hypothesis: Q.E.D.
Summation of Polynomials • What is ? • Use the known results
Inductive Proof of Summation of a Polynomial • Prove Basis step: Inductive step: Inductive hypothesis:
Inequality of Power of 2 Q.E.D. Prove the inequality P(n): n<2n, for all positive integer. Proof: Basis step: P(1) is true since 1<21. Inductive step: Assume P(k) is true for k with 1k, i.e., k<2k. For k with 1k, k+1<2k+1 k+1<2k+2k=22k k+1<2(k+1). Hence, P(k+1) is true. P(n): n<2n is true for all positive integer.
Inequalityof Factorial Numbers Q.E.D. Prove the inequality P(n): 2n<n!, for all positive integer n with 4n. Proof: Basis step: P(4) is true since 24=16<24=4!. Inductive step: Assume P(k) is true is true for k with k4, i.e., 2k<k!. For k with k4, 2(k+1) = 22k< 2k! < (k+1)k! = (k+1)! Hence, P(k+1) is true. P(n): 2n<n!, is true for all positive integer n with 4n.
Inequality of Harmonic Numbers Harmonic numbers Prove the inequality P(n): , for all natural numbers, 0n. Proof: Basis step: Hence, P(0) is true. Inductive step: Induction hypothesis: Assume P(k) is true for k with k0, i.e., .
Inequality of Harmonic Numbers (cont’d) Hence, P(k+1) is true. Q.E.D. For k0, = . P(n): is true for all natural numbers.
Divisibility of Integers Q.E.D. Prove P(n): n3–n is divisible by 3, for all positive integers. Proof: Basis step: 13–1=1–1=0 is divisible by 3. Hence P(1) is true. Inductive step: for any positive integer k: Inductive hypothesis: Assume k3–k is divisible by 3. (k+1)3– (k+1) = (k3+3k2+3k+1)–(k+1) = (k3–k)+3(k2+k) is divisible by 3 because k3–k is divisible by 3 (by inductive hypothesis) and 3(k2+k) is also divisible by 3. Hence, P(k+1) is true. n3–n is divisible by 3, for all positive integers, i.e., P(n) is true.
More Divisibility of Integers Q.E.D. Proveis divisible by 57 for all natural numbers. Proof: Basis step: For n=0, 70+2+820+1=72+81=57 is divisible by 57. Inductive step: Inductive hypothesis: Assume is divisible by 57 for any natural number k. = is divisible by 57, because is divisible by 57 by inductive hypothesis and is also divisible by 57. is divisible by 57 for all natural numbers.
Number of Finite Subsets Revisit Q.E.D. P(n): If S is a finite set of n elements, prove that S has 2n subsets. Proof: Basis step: P(0) is true since the set with zero element is the empty set, , which has exactly 20=1 subset, i.e., itself. Inductive step: AssumeP(k) is true, i.e., any set of k elements has 2k subsets. Let T be a set of k+1 elements and T=S{a}, for some S with k elements and element a,such that aS. We know that S has 2k subsets. Since any subset of S is also a subset of T, there are 2ksubsets of T. For any subset X of S, we construct X{a} which is also a subset of T, but it is distinct from X. Hence there are 2k subsets of T with this form X{a}. Totally, we have 22k=2k+1 subsets of T, i.e., P(k+1) is true. P(n) is true for every natural number n.
Generalized DeMorgan’s Laws Revisit Q.E.D. Prove for n2. Proof: Basis step: (by DeMorgan’s law). Inductive step: Inductive hypothesis: Assume is true. = (DeMorgan’s Law) =(Inductive hypothesis) = Hence is true. for n2.
Tiling Checkerboards A right triomino is an L-shaped tile which covers three squares at a time. continued→ Example: Show that every 2n×2n checkerboard with one square removed can be tiled using right triominoes. Solution: Let P(n) be the proposition that every 2n×2n checkerboard with one square removed can be tiled using right triominoes. Use mathematical induction to prove that P(n) is true for all positive integers n. • Basis step: P(1) is true, because each of the four 2×2 checkerboards with one square removed can be tiled using one right triomino. • Inductive step: Assume that P(k) is true for every 2k×2k checkerboard, for some positive integer k.
Tiling Checkerboards Inductive Hypothesis: Every 2k×2k checkerboard, for some positive integer k, with one square removed can be tiled using right triominoes. Q.E.D. • Consider a 2k+1×2k+1 checkerboard with one square removed. Split this checkerboard into four checkerboards of size 2k×2k,by dividing it in half in both directions. • Remove a square from one of the four 2k×2k checkerboards. By the inductive hypothesis, this board can be tiled. Also by the inductive hypothesis, the other three boards can be tiled with the square from the corner of the center of the original board removed. We can then cover the three adjacent squares with a triominoe. • Hence, the entire 2k+1×2k+1checkerboard with one square removed can be tiled using right triominoes.
An Incorrect “Proof” by Mathematical Induction continued→ Example: Let P(n) be the statement that every set of n lines in the plane, no two of which are parallel, meet in a common point. Here is a “proof” that P(n) is true for all positive integers n≥ 2. • BASIS STEP: The statement P(2) is true because any two lines in the plane that are not parallel meet in a common point. • INDUCTIVE STEP: The inductive hypothesis is the statement that P(k) is true for the positive integer k≥ 2, i.e., every set of k lines in the plane, no two of which are parallel, meet in a common point. • We must show that if P(k) holds, then P(k + 1) holds, i.e., if every set of k lines in the plane, no two of which are parallel, k≥ 2, meet in a common point, then every set of k + 1 lines in the plane, no two of which are parallel, meet in a common point.
An Incorrect “Proof” by Mathematical Induction Inductive Hypothesis: Every set of k lines in the plane, where k≥ 2, no two of which are parallel, meet in a common point. Not true for P(3)! • Consider a set of k + 1 distinct lines in the plane, no two parallel. By the inductive hypothesis, the first k of these lines must meet in a common point p1. By the inductive hypothesis, the last k of these lines meet in a common point p2. • If p1 and p2 are different points, all lines containing both of them must be the same line since two points determine a line. This contradicts the assumption that the lines are distinct. Hence, p1 = p2 lies on all k + 1 distinct lines, and therefore P(k + 1) holds. Assuming that k≥2, distinct lines meet in a common point, then every k + 1 lines meet in a common point. • There must be an error in this proof since the conclusion is absurd. But where is the error? • Answer: P(k)→ P(k + 1) only holds for k≥3. It is not the case that P(2) implies P(3). The first two lines must meet in a common point p1 and the second two must meet in a common point p2. They do not have to be the same point since only the second line is common to both sets of lines.
Strong Induction and Well-Ordering Section 5.2
Section Summary • Strong Induction • Example Proofs using Strong Induction • Using Strong Induction in Computational Geometry (not yet included in overheads) • Well-Ordering Property
Strong Induction Strong Induction is sometimes called the second principle of mathematical induction or complete induction. • Strong Induction: To prove that P(n) is true for all positive integers n, where P(n) is a propositional function, complete two steps: • Basis Step: Verify that the proposition P(1) is true. • Inductive Step: Show the conditional statement [P(1)∧P(2)∧∙∙∙∧ P(k)]→P(k + 1)holds for all positive integers k.
Strong Induction and the Infinite Ladder Strong induction tells us that we can reach all rungs if: We can reach the first rung of the ladder. For every integer k, if we can reach the first k rungs, then we can reach the (k + 1)st rung. • To conclude that we can reach every rung by strong induction: • BASIS STEP: P(1) holds • INDUCTIVE STEP: Assume P(1)∧P(2)∧∙∙∙∧ P(k) • holds for an arbitrary integer k, and show that • P(k + 1)must also hold. • We will have then shown by strong induction that for every positive integer n, P(n) holds, i.e., we can • reach the nth rung of the ladder.
Proof using Strong Induction Q.E.D. Example: Suppose we can reach the first and second rungs of an infinite ladder, and we know that if we can reach a rung, then we can reach two rungs higher. Prove that we can reach every rung. (Try this with mathematical induction.) Solution: Prove the result using strong induction. • BASIS STEP: We can reach the first step. • INDUCTIVE STEP: The inductive hypothesis is that we can reach the first k rungs, for any k≥ 2. We can reach the (k + 1)st rung since we can reach the (k − 1)st rung by the inductive hypothesis. • Hence, we can reach all rungs of the ladder.
Which Form of Induction Should Be Used? We can always use strong induction instead of mathematical induction. But there is no reason to use it if it is simpler to use mathematical induction. (See page 335of text.) In fact, the principles of mathematical induction, strong induction, and the well-ordering property are all equivalent. (Exercises 41-43) Sometimes it is clear how to proceed using one of the three methods, but not the other two.
Prime Products Q.E.D. Prove P(n): n can be written as the product of primes, for 1<n. Proof: Basis step: 2 is the product of one prime, i.e., 2 itself. Hence, P(2) is true. Inductive step: Inductive hypothesis: Assume for an integer k, 1<k, thatP(j) is true, i.e., j can be written as a product of primes for all 1<jk. If k+1 is a prime number, then k+1 is the product of one prime, i.e., k+1 itself. If k+1 is not a prime number, then there exist a and b, 2ab<k+1 such that k+1=ab. By inductive hypothesis, both a and b can be written as products of primes. Since k+1 is the product of a and b, k+1 can also be written as a product of primes. We have shown P(k+1) is true. P(n):n can be written as the product of primes, for 1<n, is true.
Sums of Multiples of Four and Five Q.E.D. Prove for integer n, n12,P(n): n=4s+5t, for some s and t. Proof: Basis step: Consider the cases of n=12, 13, 14, and 15. P(12) = 43, P(13) = 42+51, P(14) = 41+52, P(15) = 53. Inductive Step: Inductive hypothesis: If k15, P(j) is true, i.e., j=4s+5t, for some s and t, for 12jk. Since P(k3)is true, k+1=(k3)+4=(4s+5t)+4=4(s+1)+5t. We have shown P(k+1)is true. P(n): n=4t+5s, for some s and tis true, for integers 12n.
Sums of Multiples of Four and Five Revisit Prove for integer n, n12,P(n): n=4s+5t, for some s and t. Proof: Basis step: Consider the cases of n=12, 13, 14, and 15. P(12) = 43, P(13) = 42+51, P(14) = 41+52, P(15) = 53. Inductive Step: (using only mathematical induction) Inductive hypothesis: If k15, P(k) is true, i.e., k=4s+5t, for some s and t. Case 1: When s>0, k+1=4(s-1)+5t+4+1=4(s-1)+5(t+1) Case 2: When s=0, we must have t3, and we have the result k+1=5(t-3)+53+1=44+5(t-3). P(n): n=4t+5s, for some s and tis true, for integers 12n. Q.E.D.
Well-Ordering Property • Well-ordering property: Every nonempty set of nonnegative integers has a least element. • The well-ordering property is one of the axioms of the positive integers listed in Appendix 1. • The well-ordering property can be used directly in proofs, as the next example illustrates. • The well-ordering property can be generalized. • Definition: A set is well ordered if every subset has a least element. • N is well ordered under ≤. • The set of finite strings over an alphabet using lexicographic ordering is well ordered. • We will see a generalization of induction to sets other than the integers in the next section.
Well-Ordering Property −2 . Example: Use the well-ordering property to prove the division algorithm, which states that if a is an integer and d is a positive integer, then there are unique integers q and r with 0 ≤ r < d, such that a = dq + r. Solution: Let S be the set of nonnegative integers of the form a− dq, where q is an integer. The set is nonempty since −dqcan be made as large as needed. • By the well-ordering property, S has a least element r = a− dq0. The integer r is nonnegative. It also must be the case that r < d. If it were not, then there would be a smaller nonnegative element in S, namely, a− d(q0 + 1) = a− dq0 − d = r− d > 0. • Therefore, there are integers q and r with 0 ≤ r < d. (uniqueness of q and r is Exercise 37)
Recursive Definitions and Structural Induction Section 5.3
Section Summary • Recursively Defined Functions • Recursively Defined Sets and Structures • Structural Induction • Generalized Induction
Recursive Function Definition The arguments must satisfy a well-ordering relation, e.g., n-1<n. A recursive function is defined in two parts: basisstep and recursivestep. f(0) = 3, basis step f(n) = 2f(n-1)+3 if 0<n recursive step Mathematical notation: Functional notation: f(n) ifn=0 then 3 else 2f(n-1)+3