Proofs — Mathematical induction, Part 2 (CSCI 2824, Spring 2015)In this series of notes, we are going to
In 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. This lecture corresponds to section 2.3 of Ensley and Crawley's book. Some of the material is not available in Ensley-Crawley. Please refer to these notes.
Strong InductionTo prove a statement by strong induction.
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 weak induction.
Step-By-Two InductionTo prove a statement by step-by-two induction.
Q: Why does step-by-two induction need two base cases? Look-Back-By-Two InductionTo prove a statement by Look-Back-By-Two induction.
Q: Why does look-back-by-two induction need two base cases? Step-By-Three InductionTo prove a statement by step-by-three induction.
Q: Why does step-by-three induction need three base cases? We can continue with a cottage industry that produces induction principles, but we will stop here! Why Strong Induction?Let us try to prove a couple of theorems that will require strong induction. Theorem-1: Every number is divisible by a prime number. Proof Attempt # 1 (Weak Induction)
We will attempt prove by weak induction first.
Proof Failed Proof By Strong Induction
We will now try strong induction.
Notes: (a) here means is divisible by a prime number. (b) The theorem only applies for . We can start induction from there. 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:
QED Faulty Applications of InductionMiss out on the base case(s). Claim: Every number is odd. Sproof by “strong induction”
QED?? The proof failed because the Induction hypothesis proof is flawed. Let us split the proof step by step.
Here is a funny version of the same proof. Claim: All horses are of the same color. Sproof??
Proof by weak induction on number of horses.
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: Theorem: For all natural numbers , if is even and if is odd. Proof (Step-By-Two Induction)
Proof is by step-by-two induction on . Base Cases We verify that for , we have and likewise, for , we have . Induction-Hypothesis (Step by Two) For any , assume that , we wish to prove that for , . Proof of I.H. Let be any given number such that Consider . We have . Therefore, . Thus, if the property holds for it also holds for . This same proof can be done by strong induction or even weak induction, if you wish. 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 j remains between 0 and n ) (B) (The value of sum is the partial sum of the first j-1 array elements ). These facts are called loop invariants. Establishing a loop invariant is a fundamental task in proving that a program is correct. 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 sumArray program. Theorem Whenever control reaches LOOP HEAD the value of j satisfies the condition . 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. Base Case: . 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. Induction Hypothesis: 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.
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. Theorem Whenever the control reaches LOOP-HEAD, we have Proof
Once again, we prove by induction on , the number of times the loop has been executed. Base-Case For , we have that the loop body has never been executed. Therefore, and . We therefore have Therefore, we conclude that Ind.Hyp. Assume that the property holds after N loop executions, we wish to prove that it holds after N+1 loop executions. 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 loop invariants for the while loop. Proof
Proof is by induction on , the number of steps the while loop is executed. Base Case For , we know that , and . We are also assuming that . Therefore, it is easy to check that the invariant is satisfied. I.H If the loop invariant is true after the loop has been executed times then it remains true after the loop has been executed times. 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:
Let us now prove that going conjunct by conjunct. (a) Proof of
(b) Proof of
(c) Proof that .
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 LOOP-HEAD the loop invariant holds. Therefore, we have the following facts:
Putting them together, we conclude that when the loop terminates, . |