COMP250: Induction proofs.jeromew/teaching/250/W2018/COMP250_… · COMP250: Induction proofs....

19
COMP250: Induction proofs. Jérôme Waldispühl School of Computer Science McGill University Based on slides from (Langer,2012)

Transcript of COMP250: Induction proofs.jeromew/teaching/250/W2018/COMP250_… · COMP250: Induction proofs....

  • COMP250: Induction proofs.

    Jérôme WaldispühlSchool of Computer Science

    McGill UniversityBased on slides from (Langer,2012)

  • for any n ≥ 2, n2 ≥ 2n ?

    g(x) = 2x

    f(x) = x2

  • for any n ≥ 5, n2 ≤ 2n ?

    g(x) = 2x

    f(x) = x2

  • Motivation

    for anyn ≥1, 1+ 2+3+ 4+!+ n = n ⋅ (n+1)2

    for anyn ≥1, 1+3+ 5+ 7+!+ (2 ⋅n−1) = n2

    for anyn ≥ 5, n2 ≤ 2n

    How to prove these?

    And in general, any statement of the form:“for all n≥n0 , P(n)” where P(n) is some proposition.

  • Mathematical induction

    Many statement of the form “for all n≥n0 , P(n)” can be proven with a logical argument call mathematical induction.

    The proof has two components:• Base case: P(n0) • Induction step: for any n≥n0 , if P(n) then P(n+1)

    0 1 2 3 4 5 ... k k+1 …

    n0

  • Principle

    0 1 2 3 4 5 ... k k+1 …

    n0

    Implies

    0 1 2 3 4 5 ... k k+1 …

    etc.

  • Example 1

    for anyn ≥1, 1+ 2+3+ 4+!+ n = n ⋅ (n+1)2

    Claim:

    Proof:

    • Base case:

    • Induction step:

    n =1 1= 1⋅22

    for anyk ≥1, if 1+ 2+3+ 4+!+ k = k ⋅ (k +1)2

    then 1+ 2+3+ 4+!+ k + (k +1) = (k +1) ⋅ (k + 2)2

  • Example 1

    Assume 1+ 2+3+ 4+!+ k = k ⋅ (k +1)2

    then 1+ 2+3+ 4+!+ k + (k +1)

    =k ⋅ (k +1)2

    + (k +1)

    =k ⋅ (k +1)+ 2 ⋅ (k +1)

    2

    =(k + 2) ⋅ (k +1)

    2

    Induction hypothesis

  • Summary

    Base case: P(1) ✔

    Induction step: for any k≥1, if P(k) then P(k+1) ✔

    Thus for all n≥1, P(n)

  • Example 2

    for anyn ≥1, 1+3+ 5+ 7+!+ (2 ⋅n−1) = n2Claim:

    Proof:

    • Base case:

    • Induction step:

    n =1 1=12 ✔

    for anyk ≥1, if 1+3+ 5+ 7+!+ (2 ⋅ k −1) = k2

    then 1+3+ 5+ 7+!+ (2 ⋅ (k +1)−1) = (k +1)2

  • Example 2

    Assume 1+3+ 5+ 7+!+ (2 ⋅ k −1) = k2

    then 1+3+ 5+ 7+!+ (2 ⋅ k −1)+ (2 ⋅ (k +1)−1)= k2 + 2 ⋅ (k +1)−1= k2 + 2 ⋅ k +1= (k +1)2

    Induction hypothesis

  • Example 3

    f(x) = 2x+1

    g(x) = 2x

  • Example 3

    for anyn ≥ 3, 2 ⋅n+1< 2nClaim:

    Proof:

    • Base case:

    • Induction step:

    n = 3 2 ⋅3+1= 7 < 23 = 8 ✔

    for anyk ≥ 3, if 2 ⋅ k +1< 2k

    then 2 ⋅ (k +1)+1< 2k+1

  • Example 3

    Assume 2 ⋅ k +1< 2k

    then 2 ⋅ (k +1)+1= 2 ⋅ k + 2+1< 2k + 2≤ 2k + 2k for k ≥1= 2k+1

    Induction hypothesis

    Stronger than we need, but that works!

  • Example 4

    g(x) = 2x

    f(x) = x2

  • Example 4

    for anyn ≥ 5, n2 ≤ 2nClaim:

    Proof:

    • Base case:

    • Induction step:

    n = 5 25≤ 32 ✔

    for anyk ≥ 5, if k2 ≤ 2n

    then (k +1)2 ≤ 2k+1

  • Example 4

    Assume k2 ≤ 2k

    then (k +1)2

    = k2 + 2 ⋅ k +1≤ 2k + 2 ⋅ k +1≤ 2k + 2k

    = 2k+1

    Induction hypothesis

    From previous example

  • Example 5Fibonacci sequence:Fib0 = 0 base caseFib1 = 1 base caseFibn = Fibn-1 + Fibn-2 for n > 1 recursive case

    Claim: For all n≥0, Fibn

  • Example 5

    Assume that for all i ≤ k, Fibi < 2i (Note variation of induction hypothesis)

    Then Fibk+1 = Fibk + Fibk-1< 2k + 2k-1

    ≤ 2k + 2k for k≥1= 2k+1

    Induction hypothesis (x2)