CSE 311 Lecture 17: Strong Induction

Topics

Midterm review on Sunday 3-5pm in SAV 260
Bring questions!
Induction
A brief review of Lecture 16.
Induction starting at any integer
Proving theorems about all integers $n\geq b$ for some $b\in\mathbb{Z}$.
Strong induction
Induction with a stronger hypothesis.
Using strong induction
An example proof and when to use strong induction.
Recursively defined functions
Recursive function definitions and examples.

$\newcommand{hilite}[2]{\color{#1}{#2}}$ $\newcommand{qed}{\square}$ $\newcommand{\N}{\mathbb{N}}$ $\newcommand{\Z}{\mathbb{Z}}$ $\newcommand{\mod}[2]{#1\ \text{mod}\ #2}$ $\renewcommand{\div}[2]{#1\ \text{div}\ #2}$ $\newcommand{\congruent}[3]{#1\equiv #2\,(\text{mod}\,#3)}$ $\newcommand{\gcd}[2]{\text{GCD}(#1, #2)}$ $\newcommand{ra}[1]{\color{SteelBlue}{#1}}$ $\newcommand{rb}[1]{\color{MediumSeaGreen}{#1}}$ $\newcommand{rule}[2]{\begin{array}{c}#1\\ \hline \therefore #2\end{array}}$

Bring questions!

Induction

A brief review of Lecture 16.

A template for proofs by induction

① Let $P(n)$ be [ definition of $P(n)$ ].
We will show that $P(n)$ is true for every integer $n\geq 0$ by induction.
② Base case ($n=0$):
[ Proof of $P(0)$. ]
③ Inductive hypothesis:
Suppose that $P(k)$ is true for an arbitrary integer $k\geq 0$.
④ Inductive step:
We want to prove that $P(k+1)$ is true.
[ Proof of $P(k+1)$. This proof must invoke the inductive hypothesis. ]
⑤ The result follows for all $n\geq 0$ by induction.

Induction$\rule{P(0); \forall k. P(k)\rightarrow P(k+1)}{\forall n. P(n)}$

Induction starting at any integer

Proving theorems about all integers $n\geq b$ for some $b\in\mathbb{Z}$.

Changing the start line

How can we prove $P(n)$ for all integers $n\geq b$ for some integer $b$?

Define a predicate $Q(n) = P(n+b)$ for all $n\geq0$.
Then $(\forall n. Q(n))\equiv(\forall n \geq b. P(n))$.
Use ordinary induction to prove $Q$:
Prove $Q(0) \equiv P(b)$.
Prove $(\forall k. Q(k)\rightarrow Q(k+1)) \equiv (\forall k\geq b. P(k)\rightarrow P(k+1))$.
This gives us a proof of $P$.

By convention, we don’t define $Q$ explicitly. Instead, we modify our proof template to account for the non-zero base case $b$.

Inductive proofs for any base case $b\in\Z$

① Let $P(n)$ be [ definition of $P(n)$ ].
We will show that $P(n)$ is true for every integer $n\geq b$ by induction.
② Base case ($n = b$):
[ Proof of $P(b)$. ]
③ Inductive hypothesis:
Suppose that $P(k)$ is true for an arbitrary integer $k\geq b$.
④ Inductive step:
We want to prove that $P(k+1)$ is true.
[ Proof of $P(k+1)$. This proof must invoke the inductive hypothesis. ]
⑤ The result follows for all $n\geq b$ by induction.

Example: prove $3^n \geq n^2 + 3$ for all $n\geq 2$

① Let $P(n)$ be $3^n \geq n^2 + 3$.
We will show that $P(n)$ is true for every integer $n\geq 2$ by induction.
② Base case ($n = 2$):
$3^2 = 9 \geq 7 = 4 + 3 = 2^2 + 3$ so $P(2)$ is true.
③ Inductive hypothesis:
Suppose that $P(k)$ is true for an arbitrary integer $k\geq 2$.
④ Inductive step:
We want to prove that $P(k+1)$ is true, i.e., $3^{(k+1)} \geq (k+1)^2 + 3$ $=$ $k^2 + 2k + 4$. Note that $3^{(k+1)} = 3($$3^k$$)$ $\geq$ $3($$k^2+3$$)$ by the inductive hypothesis. From this we have $3(k^2+3) = 2k^2 + k^2 + 9$ $\geq$ $k^2 + 2k + 4$ $=$ $(k+1)^2 + 3$ since $k\geq 2$. Therefore $P(k+1)$ is true.
⑤ The result follows for all $n\geq 2$ by induction.

Strong induction

Induction with a stronger hypothesis.

Recall how induction works

Induction$\rule{P(0); \forall k. P(k)\rightarrow P(k+1)}{\forall n. P(n)}$

Domain: natural numbers ($\N$).

How do we get $P(5)$ from $P(0)$ and $\forall k. P(k)\rightarrow P(k+1)$?

 1. First, we have $P(0)$. $P(0)$ 2. Since $P(k)\rightarrow P(k+1)$ for all $k$, we have $P(0)\rightarrow P(1)$. $\ \Downarrow_{\ P(0)\rightarrow P(1)}$ 3. Applying Modus Ponens to 1 and 2, we get $P(1)$. $P(1)$ 4. Since $P(k)\rightarrow P(k+1)$ for all $k$, we have $P(1)\rightarrow P(2)$. $\ \Downarrow_{\ P(1)\rightarrow P(2)}$ 5. Applying Modus Ponens to 3 and 4, we get $P(2)$. $P(2)$ $\vdots$ $\ \Downarrow_{\ P(k)\rightarrow P(k+1)}$ 11. Applying Modus Ponens to 9 and 10, we get $P(5)$. $P(5)$

Note that we have $P(0), \ldots, P(k)$ when proving $k+1$.
So we can safely assume all of them, rather than just $P(k)$.

The strong induction rule of inference

Strong Induction$\rule{P(0); \forall k. (P(0)\wedge P(1)\wedge\ldots\wedge P(k))\rightarrow P(k+1)}{\forall n. P(n)}$

Domain: $\N$.

Strong induction for $P$ follows from ordinary induction for $Q$ where
$Q(k) = P(0) \wedge P(1) \wedge P(2) \wedge \ldots \wedge P(k)$
To see why, note the following:
$Q(0) \equiv P(0)$
$Q(k+1) \equiv Q(k) \wedge P(k+1)$
$(\forall n. Q(n))\equiv(\forall n. P(n))$

Strong inductive proofs for any base case $b\in\Z$

① Let $P(n)$ be [ definition of $P(n)$ ].
We will show that $P(n)$ is true for every integer $n\geq b$ by strong induction.
② Base case ($n = b$):
[ Proof of $P(b)$. ]
③ Inductive hypothesis:
Suppose that for some arbitrary integer $k\geq b$, $P(j)$ is true for every integer $b \leq j \leq k$.
④ Inductive step:
We want to prove that $P(k+1)$ is true.
[ Proof of $P(k+1)$. The proof must invoke the strong inductive hypothesis. ]
⑤ The result follows for all $n\geq b$ by strong induction.

Using strong induction

An example proof and when to use strong induction.

Example: the fundamental theorem of arithmetic

Fundamental theorem of arithmetic
Every positive integer greater than 1 has a unique prime factorization.
Examples
$48= 2\cdot 2\cdot 2\cdot 2\cdot 3$
$591 = 3 \cdot 197$
$45,523 = 45,523$
$321,950 = 2 \cdot 5 \cdot 5 \cdot 47 \cdot 137$
$1,234,567,890 = 2 \cdot 3 \cdot 3 \cdot 5 \cdot 3,607 \cdot 3,803$

We use strong induction to prove that a factorization into primes exists (but not that it is unique).

Prove that every integer $\geq 2$ is a product of primes

① Let $P(n)$ be “$n$ is a product of one or more primes”.
We will show that $P(n)$ is true for every integer $n\geq 2$ by strong induction.
② Base case ($n = 2$):
2 is prime, so it is a product of primes. Therefore $P(2)$ is true.
③ Inductive hypothesis:
Suppose that for some arbitrary integer $k\geq 2$, $P(j)$ is true for every integer $2 \leq j \leq k$.
④ Inductive step:
We want to prove that $P(k+1)$ is true, i.e., $k+1$ is a product of primes.
Case: $k+1$ is prime. Then by definition, $k+1$ is a product of primes.
Case: $k+1$ is composite. Then by $k+1 = ab$ for some integers $ab$ where $2\leq a, b\leq k$. By inductive hypothesis, we have $P(a) = p_1p_2\ldots p_r$ and $P(b) = q_1q_2\ldots q_s$, where $p_1,p_2,\ldots, p_r, q_1, q_2, \ldots, q_s$ are prime. Thus, $k+1 = ab = p_1p_2\ldots p_rq_1q_2\ldots q_s$, which is a product of primes.
⑤ The result follows for all $n\geq 2$ by strong induction.

Strong induction is particularly useful when …

We need to reason about procedures that given an input $k$ invoke themselves recursively on an input different from $k-1$.

Example:
Euclidean algorithm for computing $\gcd{a}{b}$.
// Assumes a >= b >= 0.
public static int gcd(int a, int b) {
if (b == 0)
return a;             // GCD(a, 0) = a
else
return gcd(b, a % b); // GCD(a, b) = GCD(b, a mod b)
}



Recursively defined functions

Recursive function definitions and examples.

Giving a recursive definition for a function

To define a recursive function $f$ over $\N$, give its output in two cases:
Base case: the value of $f(0)$.
Recursive case: the value of $f(n+1)$, given in terms of $f(n)$.
Examples:
$F(0) = 1, F(n+1) = F(n) + 1$ $\quad\quad n+1$ for $n\in\N$
$G(0) = 1, G(n+1) = 2\cdot G(n)$ $\quad\quad 2^n$ for $n\in\N$
$K(0) = 1, K(n+1) = (n+1)\cdot K(n)$ $\quad\quad n!$ for $n\in\N$

When the recursive case refers only to $f(n)$, as in these examples, we can prove properties of $f(n)$ easily using ordinary induction.

Example: prove $n! \leq n^n$ for all $n\geq 1$

① Let $P(n)$ be $n! \leq n^n$.
We will show that $P(n)$ is true for every integer $n\geq 1$ by induction.
② Base case ($n = 1$):
$1! = 1\cdot 0! = 1 \cdot 1 = 1 = 1^1$ so $P(1)$ is true.
③ Inductive hypothesis:
Suppose that $P(k)$ is true for an arbitrary integer $k\geq 1$.
④ Inductive step:
We want to prove that $P(k+1)$ is true, i.e., $(k+1)! \leq (k+1)^{(k+1)}$.
⑤ The result follows for all $n\geq 1$ by induction.

Fun: can we verify $n! \leq n^n$ for all natural numbers?

Prove $n! \leq n^n$ for $n\in\N$ with Dafny:

// x^y where 0^0 = 1
function expt(x : nat, y: nat) : nat {
if y == 0 then 1 else x * expt(x, y-1)
}

// n!
function fact(n : nat) : nat {
if n == 0 then 1 else n * fact(n-1)
}

// n! <= n^n for all natural numbers
lemma factLemma(n : nat)
ensures fact(n) <= expt(n, n)
{ }


Dafny can’t prove this theorem because the proof involves several steps that are too difficult for Dafny to discover on its own.

Really prove $n! \leq n^n$ for $n\in\N$ with Dafny:

// x^y where 0^0 = 1
function expt(x : nat, y: nat) : nat {
if y == 0 then 1 else x * expt(x, y-1)
}

// n!
function fact(n : nat) : nat {
if n == 0 then 1 else n * fact(n-1)
}

// n! <= n^n for all natural numbers
lemma factLemma(n : nat)
ensures fact(n) <= expt(n, n)
{
if (n == 0) {           // Base case
assert fact(0) <= expt(0, 0);
} else {               // Inductive step
factLemma(n-1);      // Inductive hypothesis
exptLemma(n-1, n-1); // (n-1)^(n-1) <= n^(n-1)
assert fact(n) == n * fact(n-1);               // by fact defn
assert n * fact(n-1) <= n * expt(n-1, n-1);    // by IH
assert n * expt(n-1, n-1) <= n * expt(n, n-1); // by exptLemma
assert fact(n) <= expt(n, n);                  // qed.
}
}

// x^y <= (x+1)^y for all natural numbers.
lemma exptLemma(x: nat, y: nat)
ensures expt(x, y) <= expt(x + 1, y)
{}


Summary

Induction lets us prove statements about all natural numbers.
A proof by induction must show that $P(0)$ is true (base case).
And it must use the inductive hypothesis $P(k)$ to show that $P(k+1)$ is true (inductive step).
Induction also lets us prove theorems about integers $n\geq b$ for $b\in\Z$.
Adjust all parts of the proof to use $n\geq b$ instead of $n\geq 0$.
Strong induction lets us assume a stronger inductive hypothesis.
This makes some proofs easier.
But every proof by strong induction can be transformed into a proof by ordinary induction and vice versa.