Pattern For Induction

94
Pattern For Induction CPSC 121 Steve Wolfman 2012/08/02 This work is licensed under a Creative Commons Attribution 3.0 Unported License .

description

Pattern For Induction. CPSC 121 Steve Wolfman 2012/08/02. This work is licensed under a Creative Commons Attribution 3.0 Unported License . Starting an Induction Proof. Theorem: some property is true for all integers n  ___. Scratch work: P(n)  some property on n. - PowerPoint PPT Presentation

Transcript of Pattern For Induction

Pattern For Induction

CPSC 121Steve Wolfman

2012/08/02

This work is licensed under a Creative Commons Attribution 3.0 Unported License.

Starting an Induction Proof

Theorem: some property is true for all integers n ___.

Scratch work: P(n) some property on n.“Structural” Insight: a problem of size n breaks down in terms of problems of size __________.

Laying Out the Structure of an Induction Proof

Theorem: ____________________.Proof: by induction on n.BC: For n = ___,

, P(___) is true.More?

IH: WLOG, let n be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since n > ____, ___________________________.By the IH, __________________________________.

P(n) is true.

Starting an Induction Proof

Theorem: some property is true for all integers n ___.

Scratch work: P(n) some property on n.“Structural” Insight: a problem of size n breaks down in terms of problems of size __________.

State the theorem explicitly or circle it if it’s given.It may help to define a function like “Let c(n) = the # of nodes in KST tree Kn”.

Starting an Induction Proof

Theorem: some property is true for all integers n ___.

Scratch work: P(n) some property on n.“Structural” Insight: a problem of size n breaks down in terms of problems of size __________.

State P(n) explicitly, regardless of whether it’s given. You’ll need P(n) over and over! On an exam, you can even use it to write long statements briefly.

Starting an Induction Proof

Theorem: some property is true for all integers n ___.

Scratch work: P(n) some property on n.“Structural” Insight: a problem of size n breaks down in terms of problems of size __________.

State this insight explicitly. It may be right in the problem statement! Say a function is recursive. Then the recursive calls tell you how the problem breaks down. Say a definition is recursive. Then the self-reference tells you how the problem breaks down. Say there’s a summation. Then our self-referential definitions for summations (or products or …) tell you how the problem breaks down.

Laying Out the Structure of an Induction Proof

Theorem: ____________________.Proof: by induction on n.BC: For n = ___,

, P(___) is true.More?

IH: WLOG, let n be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since n > ____, ___________________________.By the IH, __________________________________.

P(n) is true.

The theorem’s easy. You already wrote it.

Laying Out the Structure of an Induction Proof

Theorem: ____________________.Proof: by induction on n.BC: For n = ___,

, P(___) is true.More?

IH: WLOG, let n be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since n > ____, ___________________________.By the IH, __________________________________.

P(n) is true.

The smallest relevant value.

For the same value as above.Prove the property for this case.

Laying Out the Structure of an Induction Proof

Theorem: ____________________.Proof: by induction on n.BC: For n = ___,

, P(___) is true.More?

IH: WLOG, let n be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since n > ____, ___________________________.By the IH, __________________________________.

P(n) is true.

Ask: Does the structural insight break the next value of n down in terms of the existing base case? If not, add it as a base case. Continue until all remaining cases are “handled”.

Laying Out the Structure of an Induction Proof

Theorem: ____________________.Proof: by induction on n.BC: For n = ___,

, P(___) is true.More?

IH: WLOG, let n be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since n > ____, ___________________________.By the IH, __________________________________.

P(n) is true.

The largest base case.

P(i) for every i your structural insight tells you that you need!

Laying Out the Structure of an Induction Proof

Theorem: ____________________.Proof: by induction on n.BC: For n = ___,

, P(___) is true.More?

IH: WLOG, let n be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since n > ____, ___________________________.By the IH, __________________________________.

P(n) is true.

Restate your structural insight. Then, use the IH to “solve” the subproblems.

Finally, build back up to P(n).

Starting an Induction Proof

Theorem: some property is true for all integers n ___.

Scratch work: P(n) some property on n.“Structural” Insight: a problem of size n breaks down in terms of problems of size __________.

State the theorem explicitly or circle it if it’s given.It may help to define a function like “Let c(n) = the # of nodes in KST tree Kn”.

State P(n) explicitly, regardless of whether it’s given. You’ll need P(n) over and over! On an exam, you can even use it to write long statements briefly.

State this insight explicitly. It may be right in the problem statement! Say a function is recursive. Then the recursive calls tell you how the problem breaks down. Say a definition is recursive. Then the self-reference tells you how the problem breaks down. Say there’s a summation. Then our self-referential definitions for summations (or products or …) tell you how the problem breaks down.

Laying Out the Structure of an Induction Proof

Theorem: ____________________.Proof: by induction on n.BC: For n = ___,

, P(___) is true.More?

IH: WLOG, let n be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since n > ____, ___________________________.By the IH, __________________________________.

P(n) is true.

The theorem’s easy. You already wrote it.

The smallest relevant value.

For the same value as above.Prove the property for this case.

Ask: Does the structural insight break the next value of n down in terms of the existing base case? If not, add it as a base case. Continue until all remaining cases are “handled”.

The largest base case.

P(i) for every i your structural insight tells you that you need!

Restate your structural insight. Then, use the IH to “solve” the subproblems.

Finally, build back up to P(n).

Reminder: Sigma, Pi, Factorial, Powers:All Self-Referential

14

Examples• K1 is a tree with only a root node. For all integers n 2, Kn is a

root node with all previous Ki as subtrees. Prove Kn has 2n-1 nodes. (You may assume .)

• Prove for every positive integer n:

• Prove that the following algorithm takes no more than multiplications:

∑𝑗=1

𝑛

𝑗( 𝑗+1)=𝑛(𝑛+1)(𝑛+2)3

;; Integer Natural -> IntegerPow(a,b): if b = 0: return 1 else if b = 1: return a else: let part = Pow(a,) if b is odd: return part*part*a else: return part*part

Example 1

Example 1, Getting Started

Problem: K1 is a tree with only a root node. For all integers n 2, Kn is a root node with all previous Ki as subtrees. Prove Kn has 2n-1 nodes. (You may assume .)

Theorem: some property is true for all integers n ___.

Scratch work: P(n) some property on n.“Structural” Insight: a problem of size n breaks down in terms of problems of size __________.

Example 1, Getting StartedProblem: K1 is a tree with only a root node. For all integers n 2, Kn is a root node with all previous Ki as subtrees. Prove Kn has 2n-1 nodes.

Theorem: some property is true for all integers n ___.

Scratch work: P(n) some property on n.“Structural” Insight: a problem of size n breaks down in terms of problems of size __________.

State the theorem explicitly or circle it if it’s given.It may help to define a function like “Let c(n) = the # of nodes in KST tree Kn”.

Example 1, Getting StartedProblem: K1 is a tree with only a root node. For all integers n 2, Kn is a root node with all previous Ki as subtrees. Prove Kn has 2n-1 nodes.

Let c(n) = the # of nodes in KST tree Kn.Theorem: c(Kn) = 2n-1 for all integers n 1.

Scratch work: P(n) some property on n.“Structural” Insight: a problem of size n breaks down in terms of problems of size __________.

State P(n) explicitly, regardless of whether it’s given. You’ll need P(n) over and over! On an exam, you can even use it to write long statements briefly.

Example 1, Getting StartedProblem: K1 is a tree with only a root node. For all integers n 2, Kn is a root node with all previous Ki as subtrees. Prove Kn has 2n-1 nodes.

Let c(n) = the # of nodes in KST tree Kn.Theorem: c(Kn) = 2n-1 for all integers n 1.

Scratch work: P(n) c(Kn) = 2n-1

“Structural” Insight: a problem of size n breaks down in terms of problems of size __________.State this insight explicitly. It may be right in the problem statement!

Say a definition is recursive. Then the self-reference tells you how the problem breaks down.

Example 1, Getting StartedProblem: K1 is a tree with only a root node. For all integers n 2, Kn is a root node with all previous Ki as subtrees. Prove Kn has 2n-1 nodes.

Let c(n) = the # of nodes in KST tree Kn.Theorem: c(Kn) = 2n-1 for all integers n 1.

Scratch work: P(n) c(Kn) = 2n-1

“Structural” Insight: For all integers n 2, Kn is a root node with all previous Ki as subtrees.

Example 1: Laying out the Structure

Theorem: ____________________.Proof: by induction on n.BC: For n = ___,

, P(___) is true.More?

IH: WLOG, let n be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since n > ____, ___________________________.By the IH, __________________________________.

P(n) is true.

The theorem’s easy. You already wrote it.

Example 1: Laying out the Structure

Let c(n) = the # of nodes in KST tree Kn.Theorem: c(Kn) = 2n-1 for all integers n 1.Proof: by induction on n.BC: For n = ___,

, P(___) is true.More?

IH: WLOG, let n be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since n > ____, ___________________________.By the IH, __________________________________.

P(n) is true.

The smallest relevant value. (Here: n 1; so, 1.)

For the same value as above.Prove the property for this case.

Example 1: Laying out the Structure

Let c(n) = the # of nodes in KST tree Kn.Theorem: c(Kn) = 2n-1 for all integers n 1.Proof: by induction on n.BC: For n = 1, TODO: prove the property., c(K1) = 21-1.More?

IH: WLOG, let n be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since n > ____, ___________________________.By the IH, __________________________________.

P(n) is true.

Ask: Does the structural insight break the next value of n (here: 2) down in terms of the existing base case? If not, add it as a base case. Continue until all remaining cases are “handled”.

Example 1: Laying out the Structure

Let c(n) = the # of nodes in KST tree Kn.Theorem: c(Kn) = 2n-1 for all integers n 1.Proof: by induction on n.BC: For n = 1, TODO: prove the property., c(K1) = 21-1.

IH: WLOG, let n be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since n > ____, ___________________________.By the IH, __________________________________.

P(n) is true.

NO MORE BCs. 2 breaks down in terms of 1, which is our base case. 3 breaks down in terms of 2 (which we know we can handle) and 1. Everything subsequent breaks down in terms of previous values, which eventually reach 1.

Example 1: Laying out the Structure

Let c(n) = the # of nodes in KST tree Kn.Theorem: c(Kn) = 2n-1 for all integers n 1.Proof: by induction on n.BC: For n = 1, TODO: prove the property., c(K1) = 21-1.

IH: WLOG, let n be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since n > ____, ___________________________.By the IH, __________________________________.

P(n) is true.

The largest base case.

P(i) for every i your structural insight tells you that you need!

Reminder: our structural insight is “For all integers n 2, Kn is a root node with all previous Ki as subtrees.”

Example 1: Laying out the Structure

Let c(n) = the # of nodes in KST tree Kn.Theorem: c(Kn) = 2n-1 for all integers n 1.Proof: by induction on n.BC: For n = 1, TODO: prove the property., c(K1) = 21-1.

IH: WLOG, let n be an arbitrary integer > 1.Assume c(Ki) = 2i-1 for all “previous i” (that is, all integers 1 i < n).

IS: Since n > ____, ___________________________.By the IH, __________________________________.

P(n) is true.

Restate your structural insight. Then, use the IH to “solve” the subproblems.

Example 1: Laying out the Structure

Let c(n) = the # of nodes in KST tree Kn.Theorem: c(Kn) = 2n-1 for all integers n 1.Proof: by induction on n.BC: For n = 1, TODO: prove the property., c(K1) = 21-1.

IH: WLOG, let n be an arbitrary integer > 1.Assume c(Ki) = 2i-1 for all “previous i” (that is, all integers 1 i < n).

IS: Since n > 1, Kn is a root node with all previous Ki as subtrees.By the IH, for each of these subtrees, c(Ki) = 2i-1.

P(n) is true.

(Because n is an integer, n > 1 means the same as n 2.)

Finally, build back up to P(n).

Example 1: Laying out the Structure

Let c(n) = the # of nodes in KST tree Kn.Theorem: c(Kn) = 2n-1 for all integers n 1.Proof: by induction on n.BC: For n = 1, TODO: prove the property., c(K1) = 21-1.

IH: WLOG, let n be an arbitrary integer > 1.Assume c(Ki) = 2i-1 for all “previous i” (that is, all integers 1 i < n).

IS: Since n > 1, Kn is a root node with all previous Ki as subtrees.By the IH, for each of these subtrees, c(Ki) = 2i-1.

c(Kn) = 2n-1.

Finally, build back.

Example 1: Finishing the ProofLet c(n) = the # of nodes in KST tree Kn.Theorem: c(Kn) = 2n-1 for all integers n 1.Proof: by induction on n.BC: For n = 1, K1 is defined to contain only 1 node. Therefore, c(K1) = 1.And, 21-1 = 20 = 1., c(K1) = 21-1.

IH: WLOG, let n be an arbitrary integer > 1.Assume c(Ki) = 2i-1 for all “previous i” (that is, all integers 1 i < n).

IS: Since n > 1, Kn is a root node with all previous Ki as subtrees.By the IH, for each of these subtrees, c(Ki) = 2i-1.

c(Kn) = 2n-1.

Finally, build back.

Example 1: Finishing the ProofLet c(n) = the # of nodes in KST tree Kn.Theorem: c(Kn) = 2n-1 for all integers n 1.Proof: by induction on n.BC: For n = 1, K1 is defined to contain only 1 node. Therefore, c(K1) = 1.And, 21-1 = 20 = 1. , c(K1) = 21-1.

IH: WLOG, let n be an arbitrary integer > 1.Assume c(Ki) = 2i-1 for all “previous i” (that is, all integers 1 i < n).

IS: Since n > 1, Kn is a root node with all previous Ki as subtrees.By the IH, for each of these subtrees, c(Ki) = 2i-1.Thus:

c (K n) (one root node plus the nodes in the subtrees)

By the IH

Where j = i – 1.

By assumption in the problem statement.

QED

Example 1, Other Things to TryProblem: K1 is a tree with only a root node. For all integers n 2, Kn is a root node with all previous Ki as subtrees. Prove Kn has 2n-1 nodes. (You may assume .)

• Prove the assumption (by induction!).• Prove the alternate insight “For n 2, Kn is Kn-1 plus an extra subtree

that is also Kn-1” (not by induction), then use this insight to prove the theorem instead.

• Figure out what the height of Kn is and prove it by induction (with either insight).

• Change the definition to “K0 is the empty tree” rather than starting with K1 and change n 2 to n 1. Reprove the theorem.

Example 2

Example 2, Getting Started

Problem: Prove for every positive integer n,.

Theorem: some property is true for all integers n ___.

Scratch work: P(n) some property on n.“Structural” Insight: a problem of size n breaks down in terms of problems of size __________.

Example 2, Getting Started

Problem: Prove for every positive integer n,.

Theorem: some property is true for all integers n ___.

Scratch work: P(n) some property on n.“Structural” Insight: a problem of size n breaks down in terms of problems of size __________.

State the theorem explicitly or circle it if it’s given.It may help to define a function like “Let c(n) = the # of nodes in KST tree Kn”.

Example 2, Getting StartedProblem: Prove for every positive integer n, .

Theorem: For every positive integer n, .

Scratch work: P(n) some property on n.“Structural” Insight: a problem of size n breaks down in terms of problems of size __________.

State P(n) explicitly, regardless of whether it’s given. You’ll need P(n) over and over! On an exam, you can even use it to write long statements briefly.

Example 2, Getting Started

Problem: Prove for every positive integer n, .

Theorem: For every positive integer n, .

Scratch work: P(n) “Structural” Insight: a problem of size n breaks down in terms of problems of size __________.State this insight explicitly. It may be right in the problem statement!

Say there’s a summation. Then our self-referential definitions for summations (or products or …) tell you how the problem breaks down.

Reminder: Sigma, Pi, Factorial, Powers:All Self-Referential

38

Example 2, Getting Started

Problem: Prove for every positive integer n, .

Theorem: For every positive integer n, .

Scratch work: P(n) “Structural” Insight: For all integers n 2,

Example 2: Laying out the Structure

Theorem: ____________________.Proof: by induction on n.BC: For n = ___,

, P(___) is true.More?

IH: WLOG, let n be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since n > ____, ___________________________.By the IH, __________________________________.

P(n) is true.

The theorem’s easy. You already wrote it.

Example 2: Laying out the Structure

Theorem: For every positive integer n, .Proof: by induction on n.BC: For n = ___,

, P(___) is true.More?

IH: WLOG, let n be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since n > ____, ___________________________.By the IH, __________________________________.

P(n) is true.

The smallest relevant value. (Here: n is positive or 1; so, 1.)

For the same value as above.Prove the property for this case.

Example 2: Laying out the Structure

Theorem: For every positive integer n, .Proof: by induction on n.BC: For n = 1, TODO: prove the property., .More?

IH: WLOG, let n be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since n > ____, ___________________________.By the IH, __________________________________.

P(n) is true.

Ask: Does the structural insight break the next value of n (here: 2) down in terms of the existing base case? If not, add it as a base case. Continue until all remaining cases are “handled”.

Example 2: Laying out the Structure

Theorem: For every positive integer n, .Proof: by induction on n.BC: For n = 1, TODO: prove the property., .

IH: WLOG, let n be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since n > ____, ___________________________.By the IH, __________________________________.

P(n) is true.

NO MORE BCs. 2 breaks down in terms of 1, which is our base case. 3 breaks down in terms of 2 (which we know we can handle). Everything subsequent breaks down in terms of the previous value, which eventually reaches 1.

Example 2: Laying out the Structure

Theorem: For every positive integer n, .Proof: by induction on n.BC: For n = 1, TODO: prove the property., .

IH: WLOG, let n be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since n > ____, ___________________________.By the IH, __________________________________.

P(n) is true.

The largest base case.

P(i) for every i your structural insight tells you that you need!

Reminder: our structural insight is “”

Example 2: Laying out the Structure

Theorem: For every positive integer n, .Proof: by induction on n.BC: For n = 1, TODO: prove the property., .

IH: WLOG, let n be an arbitrary integer > 1.Assume .

IS: Since n > ____, ___________________________.By the IH, __________________________________.

P(n) is true.

Restate your structural insight. Then, use the IH to “solve” the subproblems.

Example 2: Laying out the Structure

Theorem: For every positive integer n, .Proof: by induction on n.BC: For n = 1, TODO: prove the property., .

IH: WLOG, let n be an arbitrary integer > 1.Assume .

IS: Since n > 1, .By the IH, .

P(n) is true.

(Because n is an integer, n > 1 means the same as n 2.)

Finally, build back up to P(n).

Example 2: Laying out the Structure

Theorem: For every positive integer n, .Proof: by induction on n.BC: For n = 1, TODO: prove the property., .

IH: WLOG, let n be an arbitrary integer > 1.Assume .

IS: Since n > 1, .By the IH, .

.

Finally, build back.

Example 2: Finishing the ProofTheorem: For every positive integer n, .Proof: by induction on n.BC: For n = 1, and . , .

IH: WLOG, let n be an arbitrary integer > 1.Assume .

IS: Since n > 1, .By the IH, .

.

Finally, build back. At this point, we did scratch work on both sides of the formula: and until they connected.

Example 2: Finishing the Proof

Theorem: For every positive integer n, .Proof: by induction on n.BC: For n = 1, and . , .

IH: WLOG, let n be an arbitrary integer > 1.Assume .

IS: Since n > 1, .By the IH, .

QED

Example 2, Other Things to TryProblem: Prove for every positive integer n,.

• Find a formula for . Now, prove the formula correct by induction and, separately, by relating the new formula to the one you analysed in Example 2.

• Find a formula for . Prove it correct by induction. (Can’t figure out the formula? Type 1 + 8 + 27 + … into Wolfram Alpha hit enter.)

• Change the bounds to 0 to n (rather than 1 to n) and find new formulae/proofs.

Example 3

Example 3, Getting StartedProblem: Prove that Pow(a,b) takes no more than multiplications:;; Integer Natural -> IntegerPow(a,b): if b = 0: return 1 else if b = 1: return a else: let part = Pow(a,) if b is odd: return part*part*a else: return part*part

Theorem: some property is true for all integers n ___.

Scratch work: P(n) some property on n.“Structural” Insight: a problem of size n breaks down in terms of problems of size __________.

Example 3, Getting StartedProblem: Prove that Pow(a,b) takes no more than multiplications:;; Integer Natural -> IntegerPow(a,b): if b = 0: return 1 else if b = 1: return a else: let part = Pow(a,) if b is odd: return part*part*a else: return part*part

Theorem: some property is true for all integers n ___.

Scratch work: P(n) some property on n.“Structural” Insight: a problem of size n breaks down in terms of problems of size __________.

State the theorem explicitly or circle it if it’s given.It may help to define a function like “Let c(n) = the # of nodes in KST tree Kn”.

Example 3, Getting StartedProblem: Prove that Pow(a,b) takes no more than multiplications:;; Integer Natural -> IntegerPow(a,b): if b = 0: return 1 else if b = 1: return a else: let part = Pow(a,) if b is odd: return part*part*a else: return part*part

Let m(b) = the # of multiplications required to compute Pow(a,b) for any integer a.Theorem: For every natural number b, .

Scratch work: P(n) some property on n.“Structural” Insight: a problem of size n breaks down in terms of problems of size __________.

State P(n) explicitly, regardless of whether it’s given. You’ll need P(n) over and over! On an exam, you can even use it to write long statements briefly.

Example 3, Getting StartedProblem: Prove that Pow(a,b) takes no more than multiplications:;; Integer Natural -> IntegerPow(a,b): if b = 0: return 1 else if b = 1: return a else: let part = Pow(a,) if b is odd: return part*part*a else: return part*part

Let m(b) = the # of multiplications required to compute Pow(a,b) for any integer a.Theorem: For every natural number b, .

Scratch work: P(b) “Structural” Insight: a problem of size n breaks down in terms of problems of size __________.

State this insight explicitly. It may be right in the problem statement! Say a function is recursive. Then the recursive calls tell you how the problem breaks down.

Example 3, Getting StartedProblem: Prove that Pow(a,b) takes no more than multiplications:;; Integer Natural -> IntegerPow(a,b): if b = 0: return 1 else if b = 1: return a else: let part = Pow(a,) if b is odd: return part*part*a else: return part*part

Let m(b) = the # of multiplications required to compute Pow(a,b) for any integer a.Theorem: For every natural number b, .

Scratch work: P(b) “Structural” Insight: For all integers b 2, Pow(a,b) is computed in terms of Pow(a,).

Example 3: Laying out the Structure

Theorem: ____________________.Proof: by induction on b.BC: For b = ___,

, P(___) is true.More?

IH: WLOG, let b be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since b > ____, ___________________________.By the IH, __________________________________.

P(b) is true.

The theorem’s easy. You already wrote it.We’ll also go through and replace n by b right away so we can keep using b.

Example 3: Laying out the Structure

Let m(b) = the # of multiplications required to compute Pow(a,b) for any integer a.Theorem: For every natural number b, .Proof: by induction on b.BC: For b = ___,

, P(___) is true.More?

IH: WLOG, let b be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since b > ____, ___________________________.By the IH, __________________________________.

P(b) is true.

The smallest relevant value. (Here: b is a natural or 0; so, 0.)

For the same value as above.Prove the property for this case.

Example 3: Laying out the Structure

Let m(b) = the # of multiplications required to compute Pow(a,b) for any integer a.Theorem: For every natural number b, .Proof: by induction on b.BC: For b = 0, TODO: prove the property., .More?

IH: WLOG, let b be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since b > ____, ___________________________.By the IH, __________________________________.

P(b) is true.

Ask: Does the structural insight break the next value of b (here: 1) down in terms of the existing base case? If not, add it as a base case. Continue until all remaining cases are “handled”.

Example 3: Laying out the Structure

Let m(b) = the # of multiplications required to compute Pow(a,b) for any integer a.Theorem: For every natural number b, .Proof: by induction on b.BC: For b = 0, TODO: prove the property. , .For b = 1, TODO: prove the property. , .

IH: WLOG, let b be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since b > ____, ___________________________.By the IH, __________________________________.

P(b) is true.

The structural insight was “For all integers b 2, Pow(a,b) is computed in terms of Pow(a,).” NO, it doesn’t handle the 1 case; so, we add 1 as a base case. Ask: does it handle the 2 case?

Example 3: Laying out the Structure

Let m(b) = the # of multiplications required to compute Pow(a,b) for any integer a.Theorem: For every natural number b, .Proof: by induction on b.BC: For b = 0, TODO: prove the property. , .For b = 1, TODO: prove the property. , .

IH: WLOG, let b be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since b > ____, ___________________________.By the IH, __________________________________.

P(b) is true.

NO MORE BCs. 2 breaks down in terms of 1, which is one of our base cases. 3 breaks down in terms of 1 (a base case). Everything subsequent breaks down in terms of the a value half as large, which eventually reaches 1 (via 2 or 3).

Example 3: Laying out the Structure

Let m(b) = the # of multiplications required to compute Pow(a,b) for any integer a.Theorem: For every natural number b, .Proof: by induction on b.BC: For b = 0, TODO: prove the property. , .For b = 1, TODO: prove the property. , .

IH: WLOG, let b be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since b > ____, ___________________________.By the IH, __________________________________.

P(b) is true.

The largest base case.

P(i) for every i your structural insight tells you that you need!

Reminder: our structural insight is “”

Example 3: Laying out the Structure

Let m(b) = the # of multiplications required to compute Pow(a,b) for any integer a.Theorem: For every natural number b, .Proof: by induction on b.BC: For b = 0, TODO: prove the property. , .For b = 1, TODO: prove the property. , .

IH: WLOG, let b be an arbitrary integer > 1.Assume .

IS: Since b > ____, ___________________________.By the IH, __________________________________.

P(b) is true.

Restate your structural insight. Then, use the IH to “solve” the subproblems.

Example 3: Laying out the Structure

Let m(b) = the # of multiplications required to compute Pow(a,b) for any integer a.Theorem: For every natural number b, .Proof: by induction on b.BC: For b = 0, TODO: prove the property. , .For b = 1, TODO: prove the property. , .

IH: WLOG, let b be an arbitrary integer > 1.Assume .

IS: Since b > 1, .By the IH, .

P(b) is true.

(Because b is an integer, n > 1 means the same as b 2.)Finally, build back up to P(b).

Example 3: Laying out the Structure

Let m(b) = the # of multiplications required to compute Pow(a,b) for any integer a.Theorem: For every natural number b, .Proof: by induction on b.BC: For b = 0, TODO: prove the property. , .For b = 1, TODO: prove the property. , .

IH: WLOG, let b be an arbitrary integer > 1.Assume .

IS: Since b > 1, .By the IH, .

.

Finally, build back.

Example 3: Finishing the ProofLet m(b) = the # of multiplications required to compute Pow(a,b) for any integer a.Theorem: For every natural number b, .Proof: by induction on b.BC: For b = 0, Pow returns 0 without any multiplications.

, .For b = 1, TODO: prove the property. , .

IH: WLOG, let b be an arbitrary integer > 1.Assume .

IS: Since b > 1, .By the IH, .

.

Finally, build back.

Of course, we did scratch work to get this!

Example 3: Finishing the ProofLet m(b) = the # of multiplications required to compute Pow(a,b) for any integer a.Theorem: For every natural number b, .Proof: by induction on b.BC: For b = 0, Pow returns 0 without any multiplications.

, .For b = 1, Pow returns a without any multiplications.

, .

IH: WLOG, let b be an arbitrary integer > 1.Assume .

IS: Since b > 1, .By the IH, .

.

Finally, build back.

Of course, we did scratch work to get this!

Example 3: Finishing the ProofLet m(b) = the # of multiplications required to compute Pow(a,b) for any integer a.Theorem: For every natural number b, .Proof: by induction on b.BC: For b = 0, Pow returns 0 without any multiplications.

, .For b = 1, Pow returns a without any multiplications.

, .

IH: WLOG, let b be an arbitrary integer > 1.Assume .

IS: Since b > 1, .By the IH, .

.

Of course, we did scratch work to get this!

Finally, build back. We cannot do this without referring to the original algorithm.

So, we include it, with numbered lines, on the next slide.

Pow(a,b) algorithm

;; Integer Natural -> IntegerPow(a,b):1. if b = 0: return 12. else if b = 1: return a3. else:4. let part = Pow(a,)5. if b is odd: return part*part*a6. else: return part*part

Example 3: Finishing the ProofLet m(b) = the # of multiplications required to compute Pow(a,b) for any integer a.Theorem: For every natural number b, .Proof: by induction on b.BC: Dropped for space.IH: WLOG, let b be an arbitrary integer > 1. Assume .IS: Since b > 1, .By the IH, . Since b 2, however, .Thus, .For b > 1, Pow proceeds in two cases. We therefore divide our proof into two cases:Case 1 (b is even): TODO: prove Case 2 (b is odd): TODO: prove

(We proceed in cases to follow the algorithm’s structure.But… it will turn out that we can do it all in one case.)

Example 3: Finishing the ProofLet m(b) = the # of multiplications required to compute Pow(a,b) for any integer a.Theorem: For every natural number b, .Proof: by induction on b.BC: Dropped for space.IH: WLOG, let b be an arbitrary integer > 1. Assume .IS: Since b > 1, .By the IH, . Since b 2, however, .Thus, .For b > 1, Pow proceeds in two cases. We therefore divide our proof into two cases:Case 1 (b is even): Then, the algorithm returns its result with one additional multiplication, and . So, it uses a total # of multiplications of:

Case 2 (b is odd): TODO: prove

by the IHsee above

Example 3: Finishing the ProofLet m(b) = the # of multiplications required to compute Pow(a,b) for any integer a.Theorem: For every natural number b, .Proof: by induction on b.BC: Dropped for space.IH: WLOG, let b be an arbitrary integer > 1. Assume .IS: Since b > 1, .By the IH, . Since b 2, however, .Thus, .For b > 1, Pow proceeds in two cases. We therefore divide our proof into two cases:Case 1 (b is even): Dropped for space.Case 2 (b is odd): Then, the algorithm returns its result with one additional multiplication, and . So, it uses a total # of multiplications of:

by the IHsee above

QED

Example 3: SIMPLIFIED VERSIONLet m(b) = the # of multiplications required to compute Pow(a,b) for any integer a.Theorem: For every natural number b, .Proof: by induction on b.BC: Dropped for space.IH: WLOG, let b be an arbitrary integer > 1. Assume .IS: Since b > 1, .By the IH, . Since b 2, however, .Thus, .For b > 1, Pow uses at most two extra multiplications to compute its result (when b is odd). Note also that . Thus, the total # of multiplications is:

by the IHsee above

QED

We notice that there’s plenty of “slop”; so, we can handle both even and odd cases at once.

Example 3, Other Things to TryProblem: Prove that Pow(a,b) takes no more than multiplications:;; Integer Natural -> IntegerPow(a,b): if b = 0: return 1 else if b = 1: return a else: let part = Pow(a,) if b is odd: return part*part*a else: return part*part

• Prove the algorithm correct.• Prove for all positive integers n that Pow(a,2n-1) takes 2(n-1)

multiplications.• Discuss why before our induction proof, we really should be saying

“WLOG, let a be an arbitrary integer.”

One More Example(Not as Good Fit to the Pattern)

Example 4: Product of Primes

Problem: Prove for any integer n 2 that n can be written as a product of primes. (For example, 7 alone is a product of primes (just one of them). 24 can be written as 2*3*2*2, among other ways, as a product of primes.)Reminder, an integer 2 or larger is a prime exactly when it has no integer factor larger than 1 but smaller than itself.An integer 2 or larger that is not prime is “composite”.

Example 4, Getting Started

Problem: Prove for any integer n 2 that n can be written as a product of primes.

Theorem: some property is true for all integers n ___.

Scratch work: P(n) some property on n.“Structural” Insight: a problem of size n breaks down in terms of problems of size __________.

State the theorem explicitly or circle it if it’s given.It may help to define a function like “Let c(n) = the # of nodes in KST tree Kn”.

Example 4, Getting StartedProblem: Prove for any integer n 2 that n can be written as a product of primes.

Theorem: n can be written as a product of primes for all integers n 2.

Scratch work: P(n) some property on n.“Structural” Insight: a problem of size n breaks down in terms of problems of size __________.

State P(n) explicitly, regardless of whether it’s given. You’ll need P(n) over and over! On an exam, you can even use it to write long statements briefly.

Example 4, Getting StartedProblem: Prove for any integer n 2 that n can be written as a product of primes.

Theorem: n can be written as a product of primes for all integers n 2.

Scratch work: P(n) n can be written as a product of primes“Structural” Insight: a problem of size n breaks down in terms of problems of size __________.State this insight explicitly. It may be right in the problem statement!

Say a definition is recursive. Then the self-reference tells you how the problem breaks down.

Example 4, Getting StartedProblem: Prove for any integer n 2 that n can be written as a product of primes.

Theorem: n can be written as a product of primes for all integers n 2.

Scratch work: P(n) n can be written as a product of primes“Structural” Insight: For all composite integers n 2, n has a factor 1 < k < n; that is, n = k*q for some integer 1 < q < n. So, n can be written as (product of primes = to k)*(product of primes = to q).

Example 4: Laying out the Structure

Theorem: ____________________.Proof: by induction on n.BC: For n = ___,

, P(___) is true.More?

IH: WLOG, let n be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since n > ____, ___________________________.By the IH, __________________________________.

P(n) is true.

The theorem’s easy. You already wrote it.

Example 4: Laying out the Structure

Theorem: n can be written as a product of primes for all integers n 2.Proof: by induction on n.BC: For n = ___,

, P(___) is true.More?

IH: WLOG, let n be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since n > ____, ___________________________.By the IH, __________________________________.

P(n) is true.

The smallest relevant value. (Here: n 2; so, 2.)

For the same value as above.Prove the property for this case.

Example 4: Laying out the Structure

Theorem: n can be written as a product of primes for all integers n 2.Proof: by induction on n.BC: For n = 2, TODO: prove the property., 2 can be written as a product of primes.More?

IH: WLOG, let n be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since n > ____, ___________________________.By the IH, __________________________________.

P(n) is true.

Ask: Does the structural insight break the next value of n (here: 3) down in terms of the existing base case? If not, add it as a base case. Continue until all remaining cases are “handled”.

Example 4: Laying out the Structure

Theorem: n can be written as a product of primes for all integers n 2.Proof: by induction on n.BC: For n = 2, TODO: prove the property., 2 can be written as a product of primes.More?

IH: WLOG, let n be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since n > ____, ___________________________.By the IH, __________________________________.

P(n) is true.

TOTALLY UNCLEAR. Some cases aren’t composite. Some cases break down into other cases that aren’t composite. Let’s come back to it after we’re done with the inductive step!

Example 4: Laying out the Structure

Theorem: n can be written as a product of primes for all integers n 2.Proof: by induction on n.BC: For n = 2, TODO: prove the property., 2 can be written as a product of primes.More?

IH: WLOG, let n be an arbitrary integer > ____.Assume _________________________________________________________________________________.

IS: Since n > ____, ___________________________.By the IH, __________________________________.

P(n) is true.

The largest base case.

P(i) for every i your structural insight tells you that you need!

Reminder: our structural insight is “n can be written as p*q for integers 1 < p < n and 1 < q < n.”

Example 4: Laying out the Structure

Theorem: n can be written as a product of primes for all integers n 2.Proof: by induction on n.BC: For n = 2, TODO: prove the property., 2 can be written as a product of primes.More?

IH: WLOG, let n be an arbitrary composite integer > ??.Assume all “previous i” can be written as a product of primes (that is, all integers 1 < i < n).

IS: Since n > ____, ___________________________.By the IH, __________________________________.

P(n) is true.

Restate your structural insight. Then, use the IH to “solve” the subproblems.

Again, totally unclear what the largest base case is. Come back to it. Remember, our real goal is to keep n from being a base case.We do need n to be composite, however.

Example 4: Laying out the Structure

Theorem: n can be written as a product of primes for all integers n 2.Proof: by induction on n.BC: For n = 2, TODO: prove the property., 2 can be written as a product of primes.More?

IH: WLOG, let n be an arbitrary composite integer > ??.Assume all “previous i” can be written as a product of primes (that is, all integers 1 < i < n).

IS: Since n is composite, it has a factor k between 2 and n-1, where k*q = n for some (possibly different) factor q between 2 and n-1. By the IH, k and q can be written as products of primes.

P(n) is true.

Finally, build back up to P(n).

Example 4: Laying out the Structure

Theorem: n can be written as a product of primes for all integers n 2.Proof: by induction on n.BC: For n = 2, TODO: prove the property., 2 can be written as a product of primes.More?

IH: WLOG, let n be an arbitrary composite integer > ??.Assume all “previous i” can be written as a product of primes (that is, all integers 1 < i < n).

IS: Since n is composite, it has a factor k between 2 and n-1, where k*q = n for some (possibly different) factor q between 2 and n-1. By the IH, k and q can be written as products of primes.

n can be written as a product of primes.

Finally, build back.

Example 4: Finishing the ProofTheorem: n can be written as a product of primes for all integers n 2.Proof: by induction on n.BC: For n = 2, TODO: prove the property., 2 can be written as a product of primes.More?

IH: WLOG, let n be an arbitrary composite integer > ??.Assume all “previous i” can be written as a product of primes (that is, all integers 1 < i < n).

IS: Since n is composite, it has a factor k between 2 and n-1, where k*q = n for some (possibly different) factor q between 2 and n-1. By the IH, k and q can be written as products of primes.

n can be written as a product of primes.

Finally, build back.

How do we resolve this? Well, any composite integer actually works. Let’s drop it. But, we’ll need to handle anything not composite as a base case!

Example 4: Finishing the ProofTheorem: n can be written as a product of primes for all integers n 2.Proof: by induction on n.BC: For n = 2, TODO: prove the property., 2 can be written as a product of primes.More?

IH: WLOG, let n be an arbitrary composite integer (greater than or equal to 2).Assume all “previous i” can be written as a product of primes (that is, all integers 1 < i < n).

IS: Since n is composite, it has a factor k between 2 and n-1, where k*q = n for some (possibly different) factor q between 2 and n-1. By the IH, k and q can be written as products of primes.

n can be written as a product of primes.

Finally, build back.

Let’s try the 2 base case and then work on “all primes” as base cases.

Example 4: Finishing the ProofTheorem: n can be written as a product of primes for all integers n 2.Proof: by induction on n.BC: For n = 2, 2 is itself a prime and so is a “product of primes” with just one term in the product. More?

IH: WLOG, let n be an arbitrary composite integer (greater than or equal to 2).Assume all “previous i” can be written as a product of primes (that is, all integers 1 < i < n).

IS: Since n is composite, it has a factor k between 2 and n-1, where k*q = n for some (possibly different) factor q between 2 and n-1. By the IH, k and q can be written as products of primes.

n can be written as a product of primes.

Finally, build back.

Example 4: Finishing the ProofTheorem: n can be written as a product of primes for all integers n 2.Proof: by induction on n.BC: For all prime numbers n (greater than or equal to 2), n is itself a prime and so is a “product of primes” with just one term in the product.

IH: WLOG, let n be an arbitrary composite integer (greater than or equal to 2).Assume all “previous i” can be written as a product of primes (that is, all integers 1 < i < n).

IS: Since n is composite, it has a factor k between 2 and n-1, where k*q = n for some (possibly different) factor q between 2 and n-1. By the IH, k and q can be written as products of primes.

n can be written as a product of primes.

Finally, build back.

Example 4: Finishing the ProofTheorem: n can be written as a product of primes for all integers n 2.Proof: by induction on n.BC: For all prime numbers n (greater than or equal to 2), n is itself a prime and so is a “product of primes” with just one term in the product.

IH: WLOG, let n be an arbitrary composite integer (greater than or equal to 2).Assume all “previous i” can be written as a product of primes (that is, all integers 1 < i < n).

IS: Since n is composite, it has a factor k between 2 and n-1, where k*q = n for some (possibly different) factor q between 2 and n-1. By the IH, k and q can be written as products of primes.Thus, n can be written as the product of primes formed by multiplying the product of primes equal to k by the product of primes equal to q.

QED

Example 4: What Does It Teach Us?Theorem: n can be written as a product of primes for all integers n 2.Proof: by induction on n.BC: For all prime numbers n (greater than or equal to 2), n is itself a prime and so is a “product of primes” with just one term in the product.

IH: WLOG, let n be an arbitrary composite integer (greater than or equal to 2).Assume all “previous i” can be written as a product of primes (that is, all integers 1 < i < n).

IS: Since n is composite, it has a factor k between 2 and n-1, where k*q = n for some (possibly different) factor q between 2 and n-1. By the IH, k and q can be written as products of primes.Thus, n can be written as the product of primes formed by multiplying the product of primes equal to k by the product of primes equal to q.

QED

Remember that we really write our induction proofs backward.(1) Figure out what the inductive step needs to assume and for what cases thestructural insight works. (2) For the IH, assume what needs to be assumed.(3) For the BC, prove every case that the IS cannot handle.