(Weak) (Mathematical) Induction

Introductory example

f(n) = 0, if n=0; n+f(n), if n>0

More examples

We probably won't have time for all of these. There are more examples in the book.

Note that we've generalized induction to the form: To prove ∀n∈{k,k+1,k+2,…}.P(n)

Incorrect uses of induction

Example:

Okay, we'll patch that problem for this example:

Example:


Strong (mathematical) induction

Examples

Relation to Weak Induction


Structural induction

Introductory example

Define: a binary tree is either empty, called a leaf, or (make-node datum t1 t2), where t1,t2 are binary trees.

Prove: for any binary tree t, #leaves(t) = #nodes(t) + 1.

How to prove?

Example

Define: for an arbitrary n, an n-ary tree is either empty, or (make-node datum ts), where ts is an n-tuple of n-ary trees.

Prove: For any n-ary tree t, #nodes(t) ≤ nheight(t)-1

Semi-aside: other ways to prove same thing?

Example

Prove: For any propositional WFF f, #connectives(f) ≥ #propositions(f) - 1.

Proof has same number of base and inductive cases as the data definition.

Example

Define strings: For a set Σ (the alphabet), the set Σ* (strings over Σ) contains:

Define length.

Define concatenation: For v,w ∈ Σ*, define vw ∈ Σ* as follows:

Prove: length(vw) = length(v) + length(w).

Example

; append: list, list -> list
;
(define (append x y)
   (cond [(empty? x) y]
         [(cons?  x) (cons (first x)
                           (append (rest x) y))]))

Prove:

For any list a, (append a (append a a)) = (append (append a a) a)
Hmm, proof gets stuck.

Ironically, by proving a stronger statement, your life actually becomes easier! Prove:

For any lists a,b,c, (append a (append b c)) = (append (append a b) c).

First, must decide what to do induction on: a, b, or c?

Induction on a: let P(a) = "For all lists b,c, (append a (append b c)) = (append (append a b) c).

Known as generalizing, strengthening, or loading the inductive hypothesis.


Induction Overview

Why all these different forms of induction?

To ponder: Is weak induction on numbers enough?

Induction can be used on any data defined recursively (or inductively), i.e., anything tree-like.

Note: Other forms of induction, e.g., co-induction and transfinite induction, allow you to do different kinds of things. They are more advanced, but still sometimes useful in CS — consider streams (e.g., I/O) and infinite trees.

Structuring proofs correctly

What's wrong with the following?

Let our domain be 2-3 trees. Have some P(t), but for this example, don't care what it is.

Biggest problem: Never reasons about 2-nodes. Structuring this way obscures the fact that the case split is incomplete.

Fixes the previous problem, although we still can't just look at the beginning of each case to verify this.

Other problems: It doesn't state much of what we should know about the ordering relationships among the keys and trees. But, it does overstate one ordering relationship — for 2-nodes, it doesn't allow k1 to be the maximal key.

All of these problems are more easily seen with a better structure.

Or, rather than having two subcases of the inductive case (as most textbooks suggest), have two inductive cases (following the data definition, as in COMP 210/212.)