## Lecture Ten NotesIn this lecture we will talk further about induction: including strong induction, the need to strengthen the statements for induction and talk about induction over programs.
The General (Strong) Induction. Fallacies with Strong Induction.
Induction on Programs
## Strong InductionTo prove a statement by strong induction. Base Case: Establish (or in general the smallest number for which the theorem is claimed to hold.). Inductive hypothesis: For all , Assuming hold, prove .
Strong induction is the “mother” of all induction principles. We can formulate many “baby” induction principles that are all just restatements of strong induction. In fact, mathematically they are all the same principle in different guises. However, seeing that is a little beyond the scope of this class. ## Weak InductionTo prove a statement by Base Case: Establish (or in general the smallest number for which the theorem is claimed to hold.). Inductive hypothesis: For any , assuming holds, prove .
## Step-By-Two InductionTo prove a statement by Base Case: Establish (or in general the smallest number and its successor). Inductive hypothesis: Assuming holds, prove .
## Look-Back-By-Two InductionTo prove a statement by Base Case: Establish (or in general the smallest number and its successor). Inductive hypothesis: For , assuming holds, prove .
## Step-By-Three InductionTo prove a statement by Base Case: Establish (or in general the smallest number and its next two successors). Inductive hypothesis: Assuming holds, prove .
## Why Strong Induction?Let us try to prove a couple of theorems that will require strong induction.
Proof Attempt # 1 (Weak Induction)
We will attempt prove by weak induction first. Base Case: This holds for , which is a prime number and is divisible by itself. Induction Hypothesis: If is divisible by a prime number then so is . The difficulty of proving this should be clear. Knowing something about divisibility of does not let us conclude the divisibility for .
Proof By Strong Induction
We will now try strong induction. Base Case: This holds for . Induction Hypothesis: Assume that hold for any and prove that holds.
Let us assume that for all , is divisible by a prime number. We wish to prove that is divisible by a prime number. Since , we know that is either prime or composite. We are allowed to split two cases: **Case-1**is a prime number itself. So in this case, it is trivially divisible by itself.**Case-2**is composite. Therefore there is a number such that is divisible by .**is divisible by some prime , by induction hypothesis.**Therefore is divisible by some prime .
## Faulty Applications of InductionMiss out on the base case(s). Claim: Every number is odd. Sproof by “strong induction”
Base Case: We know that is odd. So base case is verified.
Induction Hypothesis: Assuming that all numbers are odd, we wish to prove that is also odd. Let us assume all numbers are odd. We wish to prove that is odd. By induction hypothesis, is odd. Therefore for some . Therefore, we conclude that . Therefore, is also odd.
QED?? The proof failed because the Induction hypothesis proof is flawed. Let us split the proof step by step. Induction Hypothesis: Let us assume that all numbers are odd. ( Perfectly within your rights to assume because of the strong induction ) We wish to prove that is odd. ( good luck! ) By induction hypothesis is odd. ( Wait a minute, this does not work for . For , we have which falls outside the scope of the induction hypothesis! ) **FAIL!!**
Here is a funny version of the same proof.
Sproof??
Proof by weak induction on number of horses. Base case: Any single horse is of the same color as itself. Induction: Let us assume that for every set of horses have the same color. We wish to prove the same for a set of horses. Let us take any set of horses and call them . We can split the set into two parts has horses in it. By induction hypothesis, they all have the same color. Again is a set of horses. So they all have the same color. How do we know that both have the same color. Becase they have horses in common. Therefore must have the same color as .
All set of horses have the same color. Ergo, all horses indeed have the same color.
The flaw behind this failed proof was explained in this class. ## Application: Divisibility Test for Binary NumbersIn the very first lecture, we derived a divisibility test for binary number division by . As part of that test, we claimed the following theorem:
Proof (Step-By-Two Induction)
Proof is by
, we wish to prove that for , .
Consider . We have . Therefore, . Thus, if the property holds for it also holds for .
## Inductive proofs of programsOften, we are interested in proving that a program we wrote is correct. For instance, let us take a simple program that adds the elements of an array to find the total. We wish to prove that it is correct. Program to Sum Elements Of Array
def sumArray(a,n): # Assume a is an array of size n # Assume n > 0 # Array elements are a[0]..,a[n-1] sum = 0 j = 0 while (j < n): # LOOP HEAD sum = sum + a[j] j = j +1 We note that whenever we reach the loop head, the following facts always hold: (A) (The value of (B) (The value of These facts are called Loop Invariant
A condition involving the program variables is a loop invariant if it is true whenever the LOOP HEAD is reached. Let us try to state the loop invariant as a theorem involving the
Loop Invariant Proof
Proof is by weak induction on the number of times the loop body has been executed. We use here to distinguish it from the program variable.
. This corresponds to the very first time, the loop is reached. We know by looking at the program that . This satisfies the property , since we are given that is the size of array which cannot be negative.
Let us assume that the property holds after executions of the loop body. We wish to prove that it holds after executions. Let be values of the variables at the loop head after the loop has been executed times. We assume that the inductive hypothesis holds. In other words, is true. We wish to prove that if we execute the loop body once more, the resulting values for the variables will also satisfy the invariant. Since are such that the loop can be executed one more time, it must be the case that must be true. After the loop is executed, we have and where the prime ’ next to the variables are used to separate the values after the loop is executed once from the values before. We therefore have that if then . Similarly, since (due to the loop condition), we have .
Together, we have and . Thus, the loop condition holds even after the loop has been executed once. Let us now prove the loop invariant property of partial sums for the loop: Note that here is the index variable of the summation notation and not a program variable. on the other hand, is very much a program variable.
Proof
Once again, we prove by induction on , the number of times the loop has been executed.
Therefore, we conclude that
Let be the values of the corresponding variables after the loop has executed times. We assume that the loop executes one more time and gives us the values . Examining the loop, we conclude the following relevant facts: Assuming the induction hypothesis, we have In other words, we have established that QED To understand the value of inductive invariants, can you explain how the proof will fail if the program were modified slightly as Faulty program to Sum Elements Of Array
def sumArray(a,n): # Assume a is an array of size n # Assume n > 0 # Array elements are a[0]..,a[n-1] sum = 0 j = 0 while (j < n): # LOOP HEAD j = j +1 # Fault: incrementing j first and then adding sum = sum + a[j] # Fault: buffer overflow possible ## Program to compute logarithmWe now consider a program that given a number , returns a number such that . In other words . Log Program
def logtwo(n): # Assume n >= 1 lg = 0 j = 1 while (j < n): # LOOP HEAD lg = lg +1 j = j *2 return lg Please take a second to understand how the program works. You can try it in a python interpreter. To prove that this program is correct, we will provide the following Proof
Proof is by induction on , the number of steps the while loop is executed.
Therefore, it is easy to check that the invariant is satisfied.
Again, let us assume the loop has been executed times and and be the values for these variables. Let us assume that the loop executes one more time and the resulting values are and . Here is a summary of the facts we know about these: (from the induction hypothesis ) ( because, the loop condition should be satisfied ) ( body of the loop ) .
Let us now prove that going conjunct by conjunct. (a) Proof of (from the induction hypothesis ) ( body of the loop ) .
(b) Proof of ( because, the loop condition should be satisfied ) ( body of the loop ) ( chaining the inequalities together )
(c) Proof that . (from the induction hypothesis ) , ( body of the loop ) .
Therefore, we have proved that
Now, it remains to put together the inductive invariant to prove the the log function “works”. Note that the while loop finishes when (the negation of the loop condition holds).
However, if the control is at the Therefore, we have the following facts: .
Putting them together, we conclude that when the loop terminates, . |