mathematical induction
play

Mathematical Induction n The inductive proof will sometimes point out - PDF document

2/28/16 Why induction? n Prove algorithm correctness Mathematical Induction n The inductive proof will sometimes point out an algorithmic solution to a problem n Strongly connected to recursion Rosen Chapter 5 Motivation Motivation n A group


  1. 2/28/16 Why induction? n Prove algorithm correctness Mathematical Induction n The inductive proof will sometimes point out an algorithmic solution to a problem n Strongly connected to recursion Rosen Chapter 5 Motivation Motivation n A group of people live on an island. They are all perfect logicians. n We can also answer the more general case where there are N blue- No one knows the color of their eyes. Every night at midnight, a ferry eyed people, and N brown-eyed people, stops at the island. Any islanders who have figured out the color of their own eyes then leave the island, and the rest stay. Everyone can see everyone else at all times and keeps a count of the number of people they see with each eye color (excluding themselves), but they cannot otherwise communicate. n On this island there are 100 blue-eyed people, 100 brown-eyed people, and the Oracle (with green eyes). n One day the oracle says: "I can see someone who has blue eyes." n Who leaves the island, and on what night? https://xkcd.com/blue_eyes.html 1

  2. 2/28/16 Motivation Motivation Ø Show that any postage of ≥ 8¢ can be n Let n be a positive integer. Show that every 2 n x 2 n chessboard with one square removed can be obtained using 3¢ and 5¢ stamps. tiled using triominoes, each covering three Ø First check for a few values: squares at a time. 8¢ = 3¢ + 5¢ 9¢ = 3¢ + 3¢ + 3¢ 10¢ = 5¢ + 5¢ 11¢ = 5¢ + 3¢ + 3¢ 12¢ = 3¢ + 3¢ + 3¢ + 3¢ Ø How to generalize this? Motivation Motivation n Prove that for every positive value of n, n Many mathematical statements have the form: 1 + 2 + ,…, + n = n(n + 1)/2. ∀ n ∈ N , P(n) P(n): Logical predicate n Example: For every positive value of n, 1 + 2 + ,…, + n = n(n + 1)/2. n Predicate – propositional function that depends on a variable, and has a truth value once the variable is assigned a value. n Mathematical induction is a proof technique for proving such statements 2

  3. 2/28/16 Proving P(3) Example : 1 + 2 + … + n = n ( n + 1)/2. n Let F(n) = 1 + 2 + … + n n Suppose we know: P(1) ∧ P( n ) → P( n + 1) ∀ n ≥ 1. Prove: P(3) n P(n): F(n) = n(n + 1) / 2 n Proof: n Verify: P(1): 1(1 + 1)/2 = 1 . 1. P(1). [premise] n Assume P(n), i.e. F(n) = n(n + 1)/2 2. P(1) → P(2). [specialization of premise] n Show P(n+1): F(n + 1) = (n + 1)(n + 2)/2 . 3. P(2). [step 1, 2, & modus ponens] F(n + 1) = 1 + 2 + . . . + n + (n + 1) 4. P(2) → P(3). [specialization of premise] 5. P(3). [step 3, 4, & modus ponens] = F(n) + n + 1 = n(n + 1)/2 + n + 1 [Induction hyp.] We can construct a proof for every finite value of n = n(n + 1)/2 + 2(n + 1)/2 n Modus ponens: if p and p → q then q = (n + 1)(n + 2)/2. A Geometrical interpretation A Geometrical interpretation 1: 2: n 3: Put these blocks, which represent numbers, together to form sums: n 1 + 2 = Area is n 2 /2 + n/2 = n(n + 1)/2 1 + 2 + 3 = 3

  4. 2/28/16 The Principle of Mathematical Induction Mathematical Induction and the Domino Principle n Let P(n) be a statement that, for each natural If number n, is either true or false. the 1 st domino falls over n To prove that ∀ n ∈ N , P(n) , it suffices to prove: and q P(1) is true. (basis step) the n th domino falls over implies that domino ( n + 1) q ∀ n ∈ N , P(n) → P(n + 1) . (inductive step ) falls over n This is not magic. then n It is a recipe for constructing a proof for an arbitrary n ∈ N . domino n falls over for all n ∈ N. image from http://en.wikipedia.org/wiki/File:Dominoeffect.png Proof by induction Example Ø Show that any postage of ≥ 8¢ can be n 3 steps: obtained using 3¢ and 5¢ stamps. q Prove P(1). [the basis step] q Assume P(n) [the induction hypothesis] Ø Basis step: q Using P(n) prove P(n + 1) [the inductive step] 8¢ = 3¢ + 5¢ 4

  5. 2/28/16 Example Example n Let P(n) be the statement “n cents postage can be Case 1: k cents contain at least one 5¢ stamp. obtained using 3¢ and 5¢ stamps”. Replace 5¢ n Want to show that stamp by two k cents 3¢ stamps k+1 cents “P(k) is true” implies “P(k+1) is true” for all k ≥ 8. 5¢ 3¢ 3¢ n 2 cases: 1) P(k) is true and Case 2: k cents do not contain any 5¢ stamp. the k cents contain at least one 5¢. 2) P(k) is true and Then there are at least three 3¢ stamp. the k cents do not contain any 5¢. Replace three 3¢ stamps by k cents k+1 cents two 5¢ stamps 3¢ 3¢ 3¢ 5¢ 5¢ 18 Examples All horses have the same color n Show that 1 + 2 + 2 2 + … + 2 n = 2 n + 1 – 1 n Base case: If there is only one horse, there is only one color. n Show that for n ≥ 4 2 n < n! n Induction step: Assume as induction hypothesis that n Show that n 3 –n is divisible by 3 for every within any set of n horses, there is only one color. Now positive n. look at any set of n + 1 horses. Number them: 1, 2, 3, ..., n, n + 1. Consider the sets {1, 2, 3, ..., n} and {2, 3, 4, ..., n Show that 1 + 3 + 5 + ... + (2n+1) = (n+1) 2 n + 1}. Each is a set of only n horses, therefore within n Prove that a set with n elements has 2 n each there is only one color. But the two sets overlap, so there must be only one color among all n + 1 horses. subsets n This is clearly wrong, but can you find the flaw? 5

  6. 2/28/16 All horses have the same color More induction examples n The inductive step requires that k >= 3, n Let n be a positive integer. Show that every 2 n x otherwise there is no intersection! So P(2) 2 n chessboard with one square removed can be should be the base case, which is obviously tiled using triominoes, each covering three incorrect. squares at a time. n In the book there is a similar example. Odd Pie Fights Example n An odd number of people stand at mutually n Prove that all natural numbers ≥ 2 can be distinct distances. Each person throws a pie at represented as a product of primes. their nearest neighbor. Show that there is at least one survivor. n Basis: 2: 2 is a prime. http://laughingsquid.com/san-francisco-pie-fight-at-the-powell- street-cable-car-turnaround/ 6

  7. 2/28/16 Example Strong induction n Inductive step: show that n+1 can be n Induction: represented as a product of primes. q P(1) is true. q If n+1 is a prime: It can be represented as a q ∀ n ∈ N, P(n) → P(n + 1). product of 1 prime, itself. q Implies ∀ n ∈ N, P(n) q If n+1 is composite: Then, n + 1 = ab, for some n Strong induction: a,b < n + 1. q P(1) is true. n Therefore, a = p 1 p 2 . . . p k & b = q 1 q 2 . . . q l , where the p i s q ∀ n ∈ N, (P(1) ∧ P(2) ∧ … ∧ P(n)) → P(n + 1). & q i s are primes. n Represent n+1 = p 1 p 2 . . . p k q 1 q 2 . . . q l. q Implies ∀ n ∈ N, P(n) Breaking chocolate Induction and Recursion Theorem : Breaking up a n Several of the inductive proofs we looked at chocolate bar with n “squares” lead to recursive algorithms: takes n-1 breaks. q The triomino tiling problem q Making postage using 3 and 5 cent stamps q Generating all subsets of a set recursively 7

  8. 2/28/16 Induction and Recursion Induction and Recursion public static int pow(int x, int n) { n Induction is useful for proving correctness/design if (n == 0){ of recursive algorithms return 1; } else { n Example return x * pow(x, n-1); // Returns base ^ exponent. } // Precondition: exponent >= 0 } public static int pow(int x, int n) { if (n == 0) { Claim: the algorithm correctly computes x n . // base case; any number to 0th power is 1 return 1; Proof: By induction on n } else { Basis step: n = 0: it correctly returns 1 // recursive case: x^n = x * x^(n-1) Inductive step: assume that for n the algorithm correctly return x * pow(x, n-1); returns x n . } } Then for n+1 it returns x x n = x n+1 . Induction and Recursion Induction in CS n n! of some integer n can be characterized as: n Induction is a powerful tool for showing n! = 1 for n = 0; otherwise algorithm correctness – not just for recursive n! = n (n - 1) (n - 2) ... 1 algorithms (CS320) n Want to write a recursive method for computing it. We notice that n! = n (n – 1)! n This is all we need to put together the method: public static int factorial(int n) { if (n == 0) { return 1; } else { return n * factorial(n-1); } } 8

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend