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. 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
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
Step-By-Two InductionTo prove a statement
Q: Why does step-by-two induction need two base cases? Look-Back-By-Two InductionTo prove a statement
Q: Why does look-back-by-two induction need two base cases? Step-By-Three InductionTo prove a statement
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 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) Let us assume that for all
QED Faulty Applications of InductionMiss out on the base case(s). Claim: Every number 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 Theorem: For all natural numbers Proof (Step-By-Two Induction)
Proof is by step-by-two induction on Base Cases We verify that for Induction-Hypothesis (Step by Two) For any
we wish to prove that for
Proof of I.H. Let Consider Therefore, 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) (B) 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 Base Case:
Induction Hypothesis: Let us assume that the property holds after Let
Together, we have Let us now prove the loop invariant property of partial sums for the loop: Note that Theorem Whenever the control reaches LOOP-HEAD, we have Proof
Once again, we prove by induction on Base-Case For 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 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 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 Base Case For 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 Again, let us assume the loop has been executed Here is a summary of the facts we know about these:
Let us now prove that
(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 Therefore, we have the following facts:
Putting them together, we conclude that when the loop terminates,
|