CS70 - Lecture 4 - Jan 26, 2011 - 10 Evans


Reminder: First homework posted (on Demmel's  web page and bspace), due Jan 27

We are increasing sections sizes, will see how big remaining waitlist is


Back to examples of proof techniques

How to prove propositions like "forall n, P(n)":

  Consider arbitrary n, prove it for n without making any assumptions

  about x, conclude that your proof must work for every n.


Theorem: For every n in N, n^3 - n is divisible by 3.

Proof: Consider any n in N.  n^3 - n = (n-1)n(n+1).  One of these

is divisible by three, since they are three consecutive integers.  Three divides

the RHS, so it must divide the LHS.  So 3 divides n^3 - n.  This is true

for any n we choose; our choice of n was completely arbitrary, so

it must be true for all n.


Recall our attempt last time time to prove

Theorem: There are infinitely many primes.

We tried to do a proof by contradiction:

   Assume there are only finitely many primes, call them p1,….,pn

   Consider N = p1*p2*…*pn + 1.

   N  is not divisible by any of p1,…,pn, because you get a remainder of 1.

      What does this contradict?

Lemma: Every natural number N>1 is either prime or can be written as a product of primes.

     Assuming this lemma, we can finish the proof of the Theorem:

     Either N is prime itself (and not one of p1,…,pn, a contradiction) or

     can be written as a product of primes, none of which can be  p1,…,pn, 

     also contradicting the assumption that p1,…,pn is the list of all primes.

But how do we prove this lemma? Need a new proof technique: induction


Simplest case of Induction:

Suppose we want to prove

   forall n in N, P(n)

(1) We could try writing down separate proofs for each of P(0), P(1), … but we'd never finish

(2) We could write down one proof for P(n) that works for any n; we did this for

      P(n) = "n^3 - n is divisible by 3", but we can't always do this, as in case of showing

      there are infinitely many primes

(3) We could write down a proof for P(0) ("Base case"), and then separate proofs for

      P(0) -> P(1), P(1) -> P(2), P(2) -> P(3) but again we'd never finish

(4) We could write down a proof for P(0) (base case), and then one proof for P(n) -> P(n+1) that

      works for any n. This is called "induction (on n)", and the proof that P(n) -> P(n+1) 

      is the "induction step".


EG: Prove by induction that n^3 - n is divisible by 3

  Base case: We need to prove P(0), that is show that 0^3 - 0 is divisible by 3; easy.

  Induction step: We need to show that if

        P(n) = "n^3 - n is divisible by 3"  is true then

        P(n+1) = "(n+1)^3 - (n+1) is divisible by 3" is true:

        (n+1)^3 - (n+1) = n^3 + 3n^2 + 3*n  + 1 - (n+1)

                                    = n^3 - n + 3*n^2 + 3*n

                                    = (n^3 - n) + 3*(n^2+n)

        which is the sum of two terms, each of which is divisible by 3:

               P(n) -> n^3-n is divisible by 3, and 3*(n^2+n) is obviously divisible by 3

        so (n+1)^3-(n+1) is divisible by 3 as desired.


EG:  Show that 1+2+…+n = n*(n+1)/2


Proof 1: a proof for each P(n) = "1+2+…+n = n*(n+1)/2" independently

    Write  and add:

          s =     1    +    2     +    3     + … + (n-2)  + (n-1)   + n

          s =     n    + (n-1)  + (n-2)  + … +    3     +    2      + 1

      2*s = (n+1) + (n+1) + (n+1) + … + (n+1) + (n+1) + (n+1)

             = (n+1)*n

so s = n*(n+1)/2.   Gauss thought of this too...


Proof 2: by induction (note: base case is for n=1, not n=0)

    Base case: check that P(1) = "1 = 1*(1+1)/2"  is true 

    Induction step: Given 

          P(n) = "1+2+…+n = n(n+1)/2"

    is true, show that 

          P(n+1) = "1+2+…+n+(n+1) = (n+1)(n+2)/2" 

    is true:

         1+2+…+n + (n+1) = n(n+1)/2 + (n+1)      … since P(n) is true

                                          = (n/2 + 1)*(n+1)

                                          = (n+2)/2 * (n+1)      as desired.

        

EG: sum 1 + 3 + … + n (sum of odd numbers) is a perfect square 


FIrst attempted proof by induction: try P(n) = "1+3+…+n = k^2 for some integer k"

    base case: check P(1) = "1 = k^2 for k=1" is true

    induction step:  Given

       P(n) = "1+3+… + n = k^2 for some k" 

    is true, show that

       P(n+1) = "1+3+…+n+(n+2) = j^2 for some j" 

    is true. i.e. that for some j

        1+3+…+n+(n+2) = k^2 + (n+2) = j^2

    hard to do without more information about what k and j might be...


Second attempted proof  by induction: we will prove the "harder" fact that

    P(k) = "1+3+…+ (2*k-1) = k^2" is true by induction on k (note that n = 2*k-1)

    base case: P(1) = "1 = 1^2" is true as before

    induction step:

    Given

       P(k) = "1+3+… + (2*k-1) = k^2"

    is true, show that

       P(k+1) = "1+3+…+(2*k-1)+(2*k+1) = (k+1)^2" 

    is true. i.e. 

        1+3+…+(2*k-1)+(2*k+1) = k^2 + (2*k+1) 

                                                    =  (k+1)^2  as desired


Moral: sometime it is easier to prove something harder than you thought you wanted! 


Third proof (without induction). as before, add

       s = 1           +      3      + … + (2*k-1)

       s = (2*k-1) + (2*k-3) + … +     1

   2*s =  2*k      +   2*k     + …  +  2*k = 2*k^2

so s = k^2 as desired.


EG:  P(n) = "if x neq 1, then 1 + x + x^2 + … + x^n = (x^(n+1) - 1)/(x-1)"   (geometric sum)

Why do we have to assume x neq 1?


Proof by induction:

   base case: P(1) = "if x neq 1 then 1+x = (x^2-1)/(x-1)"  , true!

   induction step:  Given

        P(n) = "if x neq 1, then 1 + x + x^2 + … + x^n = (x^(n+1) - 1)/(x-1)"  

   is true, show that

        P(n+1) = "if x neq 1, then 1 + x + x^2 + … + x^n + x^{n+1) = (x^(n+2) - 1)/(x-1)"

   is true, i.e. if x neq 1, then

        1 + x + x^2 + … + x^n + x^{n+1) = (x^(n+1) - 1)/(x-1) + x^{n+1)

                             = (x^(n+1) - 1)/(x-1) + x^{n+1)*(x-1)/(x-1)

                             = (x^{n+1) - 1 + x^{n+1)*(x-1))/(x-1)

                             = (x^{n+1) - 1 + x^{n+2} - x^(n+1))/(x-1)

                             = (x^{n+2) - 1)/(x-1)   as desired

 

Another proof: Subtract

        s   = 1 + x + x^2 + … + x^n

    x*s   =        x + x^2 +      + x^n  + x^{n+1)

 x*s-s   =  x^(n+1) - 1

 s*(x-1)= x^(n+1) - 1

so if x neq 1, we can divide by x-1 to get s = (x^(n+1)-1)/(x-1)  


EG: Let's prove something harder that we can only do with induction, the "2 Color Theorem"

 P(n) = "if you draw n lines in the plane, dividing the plane into regions with the lines

              as borders, then you can color each region either Red or Blue so that

              no two regions sharing a border have the same color. (Sharing a border means

              they share a line or line segment as a border, not just a point.) 


Proof by induction on n = the number of lines

  Base case: P(1): clearly true (one side of the line is Red, the other Blue)

  Induction step: Suppose P(n) is true, we need to show P(n+1) is true:

       Given n+1 lines, take just n of them. So since P(n) is true we know that

       just these n lines divide the planes into regions that we can color Red and Blue.

       Now add line n+1 and think about what happens: it will pass through some of the

       regions and not others. Pick one side of line n+1:  If we take the R and B regions

       on this one side, and swap their colors, they still have the property that two

       regions sharing a border have different colors. But now a single region divided

       by line n+1 will have different colors on either side of line n+1, so we are done.


Note: The 2-color theorem is an easy special case of a much harder result, called

the 4-color theorem: This says that if you draw any curves in the plane (not just lines)

to divide the plane into regions, you only need at most 4 colors to color the regions

so that no two regions sharing a border (not just a point) have the same color. This

was conjectured in 1852, and "proven" several times (with errors in the proofs

discovered years later), until a real "proof" was published in 1976. But it used a computer

to check an enormous number of cases, so no one could read it and understand it,

one had to believe the computer program was correct and had been executed correctly.

Eventually a human-readable (but still very long) proof was published in 1996.


EG: Consider a checkerboard of size 2^n by 2^n squares. Suppose we have a lot

of L-shaped tiles that cover exactly 3 squares each. The problem is to prove

   P(n) = "It is possible to cover the 2^n by 2^n checkerboard with nonoverlapping

                L-shaped tiles so that all squares but one are completely covered."

This is one of those cases where it is easier to prove something that looks harder;

we will add the condition to P(n):

    "Furthermore, it is possible for the uncovered square to be any of the (2^n)^2 squares

     in the checkerboard."


The base case, P(1), is a 2x2 checkerboard, which is easy to confirm.

The induction step goes as follows: Assume P(n) is true. To prove P(n+1),

consider the 2^(n+1)x2^(n+1) checkerboard as 4 smaller checkerboards

of size 2^nx2^n touching at one corner, in the center of the larger checkerboard.

The square to be left uncovered is in one of these 2^nx2^n checkerboards,

which we know we can cover with L-shaped tiles since P(n) applies to it.

Now consider the other three 2^nx2^n checkerboards, which themselves form

a (large) L-shaped region. Mark the 3 1x1 squares at the inner angle of this

large L; each one lies in a different 2^nx2^n checkerboard. Applying P(n)

to each of these three 2^nx2^n checkerboards, we can cover all but the

marked square it contains using small L-shaped tiles. One more small

L-shaped tile covers the 3 marked 1x1 squares, completing the covering

and the proof. 


EG Here is bogus proof: What is wrong with it?

Theorem: All horses have same color, i.e. the proposition

  P(n) = "in any set of n horses, they all have the same color" is true

Base case: P(1) is obviously true, since these is just one horse

Induction step: To prove P(n+1) given P(n) being true,

take the n+1 horses and call then h(1),…,h(n+1). Now apply

P(n) to the sets {h(1),…,h(n)} and {h(2),…,h(n+1)} to conclude

that h(1),…,h(n) all have the same color, and

h(2),…h(n+2) all have the same color. Since these two subsets

overlap in h(2), we conclude that all of h(1),…,h(n+1) have the same color.


EG:  Theorem. There are infinitely many primes.  Tried this before, but

it didn't quite work, let's try again.


Lemma: Every integer n>1 is either prime or can be written as the product of primes.


Assuming this for a moment, let's prove the Theorem. We assume it is false,

that there only finitely many primes, call them p(1),…,p(k), and get a contradiction: 

Let N = p(1)*…*p(k)+1, as we did before. Then N is not divisible by any of p(1),…,p(k),

since you get a remainder of 1. But by the Lemma, N is either prime itself, or a

product of other primes other than p(1),…,p(k). Either way we get a contradiction.


To prove the Lemma, we will use a different form of induction than before called

strong induction: to prove "forall n P(n)", we will

   prove a base case, P(2) in our case

   show that ( P(2) and P(3) and … and P(n) ) -> P(n+1)

This differs from the induction we did before, because we need to use

all of P(2), P(3),…,P(n) to prove P(n+1), not just P(n)


Returning to our Lemma, suppose we have proven

    P(k) = "either k is a prime or a product of primes"

for k = 2, 3, … n, and now we want to prove P(n+1):

   Case 1:  n+1 is prime:  then the Lemma is true

   Case 2:  n+1 is composite: then we can write n+1 = r*s, where r and s

                   are some integers > 1, and < n+1. So we know P( r ) and P(s) are true.

                   So (by induction), either r is prime or a product of primes, and the same holds for s.

                   So the product r*s is the product of primes, and the Lemma is also true as desired.


EG: Fibonacci numbers: Let F(0)=0, F(1)=1 and F(n)=F(n-1)+F(n-2).

So F(0,1,2,…) = 0,1,1,2,3,5,8,13,21,...

Theorem: Let x_+ = (1+sqrt(5))/2 ~ 1.6 and x_- = (1-sqrt(5))/2 ~ -.6

 Then F(n) = ( x_+^n - x_-^n )/sqrt(5) ~ 1.6^n / sqrt(5)

  grows exponentially fast


Proof by induction:

  Bases case(s): Check that the formula yields F(0) = 0 and F(1) = 1 as desired

  Induction step: need to confirm

    F(n-1)+F(n-2) = ( x_+^(n-1) - x_-^(n-1) )/sqrt(5) + (x_+^(n-2) - x_-^(n-2))/sqrt(5)

                             = … = ( x_+^n - x_-^n)/sqrt(5)

                             = F(n)


Consider following 2 algorithms for computing F(n):


   func F1(n)

       if n=0 return 0

       elseif n = 1 return 1

       else 

            x = 0, y = 1, 

            for i= 2 to n

                tmp = y,  y = x+y, x=tmp  

 

  func F2(n)

      if n=0 return 0

      else if n= 1 return 1

      else return F2(n-1) + F2(n-2)


Which algorithm is faster? More simply: how many additions does each one perform?


   Let A1(n) = #additions_in_F1(n) = ?

   Let A2(n) = #additions_in_F2(n) = 1 + A2(n-1) + A2(n-2)

   So A2(0,1,2,…) = 0, 0, 1, 2, 4, 7, 12, 20,...

   What is the relationship between A2(n) and F(n)?

   Looks like A2(n) = F(n+1)-1.

   Proof by induction:  A2(n) = 1 + A2(n-1) + A2(n-2)

                                                  = 1 + (F(n)-1) + (F(n-1)-1)     … by induction

                                                  = F(n) + F(n-1) -1

                                                  = F(n+1) -1   … as desired!


Looks like F1(n) is *much* faster than F2(n)


How would you ever guess the formula for F(n)? Exactly: guess!

Try F(n) = x^n and see what x has to be for this to be true:

    F(n) = x^n = F(n-1) + F(n-2) = x^(n-1) + x^(n-2)

or            x^n = x^(n-1) + x^(n-2)

or            x^2 = x + 1

or            x = (1+sqrt(5))/2 = x_+   or   x = (1-sqrt(5))/2 = x_-

So both F(n) = x_+^n and F(n) = x_-^n  satisfy F(n) = F(n-1)+F(n-2).

But neither satisfies F(0)=0 and F(1) = 1: what to do?

Note that for any constants r and s, F(n) = r*x_+^n + s*x_-^n

also satisfies F(n) = F(n-1) + F(n-2), so we can pick the 2 constants r and s

to satisfy the 2 constraints F(0)=0 and F(1) = 1 (or F(0)=7 and F(1) = -pi, whatever we like).