Announcements CS311H: Discrete Mathematics Mathematical Induction Homework 5 out today
Transcription
Announcements CS311H: Discrete Mathematics Mathematical Induction Homework 5 out today
Announcements CS311H: Discrete Mathematics Mathematical Induction I¸sıl Dillig I¸sıl Dillig, CS311H: Discrete Mathematics Mathematical Induction I Homework 5 out today I Due next Thursday (Oct 30) I¸sıl Dillig, 1/26 Review: Strong Induction CS311H: Discrete Mathematics Mathematical Induction Example I Prove that every integer n ≥ 12 can be written as n = 4a + 5b for some non-negative integers a, b. I Base case same as regular induction, different in inductive step I Proof by strong induction on n and consider 4 base cases I Regular induction: assume P (k ) holds and prove P (k + 1) I Base case 1 (n=12): 12 = 3 · 4 + 0 · 5 I Strong induction: assume P (1), P (2), .., P (k ); prove P (k + 1) I Base case 2 (n=13): 13 = 2 · 4 + 1 · 5 I Base case 3 (n=14): 14 = 1 · 4 + 2 · 5 I Base case 4 (n=15): 15 = 0 · 4 + 3 · 5 I¸sıl Dillig, CS311H: Discrete Mathematics 2/26 Mathematical Induction 3/26 I¸sıl Dillig, Example, cont. CS311H: Discrete Mathematics Mathematical Induction 4/26 Matchstick Example Prove that every integer n ≥ 12 can be written as n = 4a + 5b for some non-negative integers a, b. I¸sıl Dillig, I Inductive hypothesis: Suppose every 12 ≤ i ≤ k can be written as i = 4a + 5b. I Inductive step: We want to show k + 1 can also be written this way for k + 1 ≥ 16 I Observe: k + 1 = (k − 3) + 4 I By the inductive hypothesis, k − 3 = 4a + 5b for some a, b because k − 3 ≥ 12 I But then, k + 1 can be written as 4(a + 1) + 5b CS311H: Discrete Mathematics Mathematical Induction I¸sıl Dillig, 5/26 1 I The Matchstick game: There are two piles with same number of matches initially I Two players take turns removing any positive number of matches from one of the two piles I Player who removes the last match wins the game I Prove: Second player always has a winning strategy. CS311H: Discrete Mathematics Mathematical Induction 6/26 Matchstick Proof I Matchstick Proof, cont. P (n): Player 2 has winning strategy if initially n matches in each pile I Base case: I Induction: Assume ∀j .1 ≤ j ≤ k → P (j ); show P (k + 1) I Inductive hypothesis: I Prove Player 2 wins if each pile contains k + 1 matches I¸sıl Dillig, CS311H: Discrete Mathematics Mathematical Induction Case 1: Player 1 takes k + 1 matches from one of the piles. I What is winning strategy for player 2 I Case 2: Player 1 takes r matches from one pile, where 1≤r ≤k I Now, player 2 takes r matches from other pile I Now, the inductive hypothesis applies ⇒ player 2 has winning strategy for rest of the game I¸sıl Dillig, 7/26 The Horse Paradox I I CS311H: Discrete Mathematics I Induction: Assume P (k ); prove P (k + 1) I Consider a collection of k + 1 horses: h1 , h2 , . . . , hk +1 I Consider the statement: All horses have the same color I By IH, h1 , h2 , . . . , hk have the same color; let this color be c I What is wrong with the following bogus proof of this statement? I By IH, h2 , . . . , hk +1 have same color; call this color c 0 I P (n) : A collection of n horses have the same color I Since h2 has color c and c 0 , we have c = c 0 I Base case: P (1) X I Thus, h1 , h2 , . . . , hk +1 also have same color I What’s the fallacy? CS311H: Discrete Mathematics Mathematical Induction I¸sıl Dillig, 9/26 Recursive Definitions CS311H: Discrete Mathematics Should be familiar with recursive functions from programming: 10/26 I Mathematical Induction This sequence can be defined recursively as follows: a0 an Recursive definitions are also used in math for defining sets, functions, sequences etc. CS311H: Discrete Mathematics Consider the following sequence: 1, 3, 9, 27, 81, . . . public int fact(int n) { if(n <= 1) return 1; return n * fact(n - 1); } I Mathematical Induction Recursive Definitions in Math I I 8/26 Bogus Proof, cont. Easy to make subtle errors when trying to prove things by induction – pay attention to details! I¸sıl Dillig, I¸sıl Dillig, Mathematical Induction I¸sıl Dillig, 11/26 2 = 1 = 3 · an−1 I First part called base case; second part called recursive step I Very similar to induction; in fact, recursive definitions sometimes also called inductive definitions CS311H: Discrete Mathematics Mathematical Induction 12/26 Recursively Defined Functions Recursive Definition Examples I Just like sequences, functions can also be defined recursively I Example: f (0) = 3 f (n + 1) = 2f (n) + 3 (n ≥ 1) I Consider f (n) = 2n + 1 where n is non-negative integer I What’s a recursive definition for f ? I Consider the sequence 1, 4, 9, 16, . . . I What is f (1)? I What is a recursive definition for this sequence? I What is f (2)? I Recursive definition of function defined as f (n) = n P i? i=1 I What is f (3)? I¸sıl Dillig, CS311H: Discrete Mathematics Mathematical Induction 13/26 I¸sıl Dillig, Recursive Definitions of Important Functions I Some important functions/sequences defined recursively I Factorial function: Fibonacci numbers: 1, 1, 2, 3, 5, 8, 13, 21, . . . a1 a2 an I = 1 = 1 = an−1 + an−2 CS311H: Discrete Mathematics I¸sıl Dillig, I Recursive definitions and inductive proofs are very similar I Natural to use induction to prove properties about recursively defined structures (sequences, functions etc.) I Consider the recursive definition: f (0) = 1 f (n) = f (n − 1) + 2 (n ≥ 3) I Mathematical Induction 15/26 Prove that f (n) = 2n + 1 I¸sıl Dillig, Example CS311H: Discrete Mathematics Mathematical Induction 16/26 Example, cont. I Let fn denote the n’th element of the Fibonacci sequence I Prove: For n ≥ 3, fn > αn−2 where α = I Proof is by strong induction on n with two base cases I 14/26 Just like there can be multiple bases cases in inductive proofs, there can be multiple base cases in recursive definitions I¸sıl Dillig, I Mathematical Induction Inductive Proofs for Recursively Defined Structures f (1) = 1 f (n) = n · f (n − 1) (n ≥ 2) I CS311H: Discrete Mathematics Prove: For n ≥ 3, fn > αn−2 where α = √ 1+ 5 2 Intuition 1: Definition of fn has two base cases I Inductive step: Assuming property holds for fi where 3 ≤ i ≤ k , need to show fk +1 > αk −1 I First, rewrite αk −1 as α2 αk −3 I α2 is equal to 1 + α because: Intuition 2: Recursive step uses fn−1 , fn−2 ⇒ strong induction I Base case 1 (n=3): f3 = 2, and α < 2, thus f3 > α I Base case 2 (n=4): f4 = 3 and α2 = CS311H: Discrete Mathematics √ (3+ 5) 2 Mathematical Induction 2 α = <3 I I¸sıl Dillig, 17/26 3 √ 1+ 5 2 √ !2 √ 1+ 5 5+3 = =α+1 2 2 Thus, αk −1 = (α + 1)(αk −3 ) = αk −2 + αk −3 CS311H: Discrete Mathematics Mathematical Induction 18/26 Example, cont. Recursively Defined Sets and Structures I αk −1 = αk −2 + αk −3 I We saw how to define functions and sequences recursively I By recursive definition, we know fk +1 = fk + fk −1 I We can also define sets and other data structures recursively I Furthermore, by inductive hypothesis: I Example: Consider the set S defined as: fk > αk −2 I fk −1 > αk −3 3∈S If x ∈ S and y ∈ S , then x + y ∈ S Therefore, fk +1 > αk −2 + αk −3 = αk −1 I I¸sıl Dillig, CS311H: Discrete Mathematics Mathematical Induction 19/26 I¸sıl Dillig, More Examples I I Base case: I Recursive step: Give a recursive definition of N, the set of all natural numbers: I Base case: I Recursive step: I¸sıl Dillig, Mathematical Induction 21/26 Recursive definitions play important role in study of strings I Strings are defined over an alphabet Σ I Example: Σ1 = {a, b} I Example: Σ2 = {0} I Examples of strings over Σ1 : a, b, aa, ab, ba, bb, . . . I Set of all strings formed from Σ forms language called Σ∗ 20/26 Σ∗2 = {, 0, 00, 000, . . .} I¸sıl Dillig, Recursive Definition of Strings I¸sıl Dillig, Mathematical Induction I I CS311H: Discrete Mathematics I CS311H: Discrete Mathematics Strings and Alphabets Give a recursive definition of the set E of all even integers: I What is the set S defined as above? CS311H: Discrete Mathematics Mathematical Induction 22/26 Recursive Definitions of String Operations The language Σ∗ has natural recursive definition: I Base case: ∈ Σ∗ (empty string) I Many operations on strings can be defined recursively. I Recursive step: If w ∈ Σ∗ and x ∈ Σ, then wx ∈ Σ∗ I Consider function l (w ) which yields length of string w I Example: Give recursive definition of l (w ) I Since is the empty string, s = s I Consider the alphabet Σ = {0, 1} I How is the string ”1” formed according to this definition? I How is ”10” formed? CS311H: Discrete Mathematics Mathematical Induction I¸sıl Dillig, 23/26 4 I Base case: I Recursive step: CS311H: Discrete Mathematics Mathematical Induction 24/26 Another Example I¸sıl Dillig, Palindromes I A palindrome is a string that reads the same forwards and backwards Example: Reverse of ”abc” is ”bca” I Examples: ”mom”, ”dad”, ”abba”, ”Madam I’m Adam”, . . . Give a recursive definition of the reverse(s) operation I Give a recursive definition of the set P of all palindromes over the alphabet Σ = {a, b} I Base cases: I Recursive step: I The reverse of a string s is s written backwards. I I I Base case: I Recursive step: CS311H: Discrete Mathematics Mathematical Induction I¸sıl Dillig, 25/26 5 CS311H: Discrete Mathematics Mathematical Induction 26/26