CS70 - Lecture 3 - Jan 24, 2011 - 10 Evans


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


Review of last time:


Using and combining

    propositions (statement that must be true or false)

    predicates: propositions depending on variables

       EG: R(x) = "x is even"

    logical operators (not, and, or, xor, implies, if-and-only-if (iff) )

       EG: (1+1=3) -> (the moon is made of cheese)

    quantifiers thereexists and forall

we learned to make compound propositions, whose truth value 

(true or false) tells us something interesting or useful:


EG: (Lewis Carroll, author of 'Alice in Wonderland')

                Universe of Discourse = 'creatures'

                "All bears are fierce"

                "Some bears do not drink Peet's coffee"

                "Some fierce creatures do not drink Peet's coffee"

                 Let B(x) = "x is a bear"

                 Let F(x) = "x is fierce"

                 Let P(x) = "x drinks Peet's coffee"

                Express above using forall, thereexists:

 ASK&WAIT       "All bears are fierce"

 ASK&WAIT       "Some bears do not drink Peet's coffee"

 ASK&WAIT       why not "there exists x (B(x) -> not P(x))" ?

 ASK&WAIT       "Some fierce creatures do not drink Peet's coffee"


Recall E = even numbers, P = primes, 

EG: for all x in E,  ( (x >= 4) => (thereexist p1, p2 in P, p1 + p2 = x) )

Goldbach's conjecture

  

But to be useful, we need to prove that a compound proposition is true or false,

so we need proof techniques:

     [ p and (p -> q)] -> q

     [(p -> q) and (q -> r)] -> (p -> r)

     (p and q) -> p

     p -> (p or q)

     [ not q and (p -> q) ] -> not p    also called contrapositive 

     [ not p -> F) ] -> p    also called proof by contradiction

     not( forall x . P(x)   <->   thereexists x  (not P(x))

     not( thereexists x . P(x))  <->  forall x  (not P(x))


Now we will look at a number of proofs. The goal is not to learn

these particular proofs, but rather see how to use these techniques

to prove theorems, and tell the difference between a valid proof

and an invalid one.      


Next proof technique: case analysis

      EX: show that min(x,y) + max(x,y) = x+y

          Three possible cases: x<y, x=y and x > y

             Case 1: min(x,y) = x, max(x,y)=y, so min+max=x+y

             Case 2: min(x,y) = x = y, max(x,y) = y = x, so min+max=x+y=2*x

             Case 3: min(x,y) = y, max(x,y)= x , so min+max=y+x=x+y


     EX: there exists irrational x and irrational y such that x^y is rational

          proof: assume we know that sqrt(2) is irrational

                (similar proof to showing 5^(1/3) irrational from last time)

             Case 1:  sqrt(2)^sqrt(2) rational

             Case 2:  sqrt(2)^sqrt(2) irrational

          Clearly one of these two cases must hold, even if we don't know which one

             Case 1:  Choose x = y = sqrt(2) irrational, and so by assumption x^y rational, so done

             Case 2:  Chose x = sqrt(2)^sqrt(2) and y = sqrt(2), both irrational, and

                             x^y = (sqrt(2)^sqrt(2))^sqrt(2) = sqrt(2)^2 = 2 is rational, so done


      EX: Let a(0), a(1), and a(2) be three different points in the plane, 

          and let T be the triangle they form. Let 

             theta(1) be the clockwise angle from the line segment

                  (a(0),a(1)) to the segment (a(1),a(2))

             theta(2) be the clockwise angle from the line segment

                  (a(1),a(2)) to the segment (a(2),a(0))

             theta(0) be the clockwise angle from the line segment

                  (a(2),a(0)) to the segment (a(0),a(1))

          Then theta(1)+theta(2)+theta(3) = 180 degrees.

          Proof: Draw the figure

                       a(1)-----a(0)

                         \           /

                           \       /

                             \   /

                            a(2)

                 and use the fact that the sums of the angles in a triangle

                 is 180 degrees.


ASK&WAIT: Are the above statement and its proof correct? Or did we miss a case?


      Recall Def: "p if and only if q" means "p <-> q"

           To prove this is true you have to show that p and q are 

           both true at at the same time, and both false at the same time

                 

      EX: Are this statement and its proof correct?

          a*b is rational if and only a and b are rational

          Proof: Suppose a=p/q and b=r/s are rational, i.e. quotients

                 of integers. Then a*b = (p*r)/(q*s) is rational.


ASK&WAIT: Are the above statement and its proof correct?


      Recall: proving "NOT EXIST x such that P(x)" is same as

          "FORALL x NOT P(x)"

      EX: Are following statement and proof correct?

          There is no polynomial p(n) with integer coefficients 

          such that p(n) is prime for all integers n >= 0.

          In other words, there is no simple (polynomial) formula for

          generating primes.

          Proof: instead show "FORALL polynomials p(n), 

                 there is an n >= 0 such that p(n) is not prime":

                Write p(n) = p_(d)*n^d + p_(d-1)*n^(d-1) + ... + p_(1)*n + p_(0)

                           = r(n) + p_(0)

                 If p_(0) = 0, then p(0)=0 is not prime

                 If p_(0) = 1 or -1, then p(0)=1 or -1, so not prime

                 If p_(0) is composite, so is p(0) = p_(0)

                 If p_(0)=q is prime, then q|r(i*q), so q|p(i*q)=r(i*q)+q


ASK&WAIT: Are the above statement and its proof correct?


Here are two more reasons why proofs are important (beyond proving that some

theorem is true, or algorithm is correct)


     It is possible to embed proofs in downloadable programs and email,

     so that the recipient is guaranteed (by running a program to check

     the proof) that the program or email does not contain a virus, or

     will not otherwise cause mischief.


     For example, Java enabled cell-phones in Japan use this technique

     of "proof-carrying code" when they download code. When a phone downloads

     Java code it checks the proof that the code will not cause damage

     (eg write into memory it should not). The alternative

     is to run them using an interpreter that keeps downloaded code from

     causing mischief. But it uses fewer instructions (and so

     less battery power!) to check a proof and then run noninterpreted code.

     Prof. George Necula has pioneered this idea (www.cs.berkeley.edu/~necula)


     Bill Gates once proposed a list of techniques to combat spam, 

     including proof-carrying-email, which would contain a

     proof that the email did not come from a spammer, i.e. sent out to

     lots and lots of people.  One way to do this would be for the email

     to contain a very difficult puzzle and its solution, where the puzzle

     is known to be so difficult that only by spending at least, say,

     1 CPU second could the puzzle have been solved, although it is easy

     for your mailer to check that the solution is correct. 

     And the puzzle would have to depend on the address of the recipient.

     Thus, sending a billion spam messages would cost a billion CPU seconds

     instead of a few seconds, making span uneconomical to send.

     Unfortunately, this would just motivate spammers to try to take over

     other machines and make them spammer-zombies, which they do already.

     Obviously a good solution to spam still awaits us...



Back to examples of proof techniques

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

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

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


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 consecutive.  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.


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

Proof: Consider any n in N.  There are three cases:

   n = 3*k, n=3*k+1 or n = 3*k+2 for some k in N

Why? Divide n by 3, then the remainder is either 0, 1 or 2

case 0: n=3k for some k in N:

  n^3 - n = (3k)^3 - 3k = 27k^3 - 3k, which is divisible by 3, since it is a sum of 

     terms each of which is divisible by 3

case 1: n=3k+1 for some k in N:

  n^3 - n = (3k+1)^3 - (3k+1) = 27k^3 + 27k^2 + 6k, which is divisible by 3 (same reason)

case 2: n=3k+2 for some k in N:

  n^3 - n = (3k+2)^3 - (3k+2) = 27k^3 + 54k^2 + 33k + 6, which is divisible by 3 (same reason)

These 3 cases exhaust all the possibilities, and in every case,

n^3 - n is divisible by 3.  So therefore n^3 - n is divisible by 3

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

it must be true for all n.



Theorem: Forall n in N, (n is even) -> (n^2 is even).

Proof: Assume n is even.  Then n=2k for some k in N.

Plugging in, n^2 = (2k)^2.  So n^2 = 4k^2 = 2 * (2k),

which is twice an even number.  This means that n^2 is even.


ASK&WAIT: Why is this OK?  Why can we just assume that n is even?


Proof by contrapositive

Theorem: For all n in N, (n^2 is even) -> (n is even)

Comment: notice that direct proof seems hard; suppose n^2 is even,

so there exists k s.t. n^2 = 2k; now what can we conclude about n?

It's hard to say anything, because n = sqrt(2k), and is this even

or not?  who knows?  this is why we need proof by contrapositive.

Proof: Let n be arbitrary.  We will prove n^2 even => n even by

proving its contrapositive, n odd => n^2 odd.  Assume n is odd,

i.e., n=2k+1 for some k in N.  Then

  n^2 = (2k+1)^2 = 4k^2 + 4k + 1 = 2m+1   where m=2k^2+2k

Since m in N, this shows that n^2 is odd.  QED.


Having proven both the last two theorems

   forall n in N  (n even) -> (n^2 even)

   forall n in N  (n^2 even) -> (n even)

we can conclude that

   forall n in N  (n even if and only if (n^2 even)


Proof by contradiction

Theorem: x^5 - x + 1 = 0 has no solution in the rationals.

Lemma: If x^5 - x + 1 = 0 and x=a/b for a,b in Z, b nonzero, then

both a and b are even.

Proof of lemma: We have (a/b)^5 - (a/b) + 1 = 0.  Therefore

  a^5 - a b^4 + b^5 = 0

Now split by cases on the parity of a and b:

  Case 1: a odd, b odd: then the LHS is odd-odd+odd = odd, but RHS is even.  Impossible.

  Case 2: a odd, b even: LHS is odd-even+even = odd, but RHS is even.  Impossible.

  Case 3: a even, b odd: LHS is even-even+odd = odd, but RHS is even.  Impossible.

So we must have a even, b even, since it is the only remaining possibility.

Proof of theorem: Suppose (for a contradiction) that there exists

some rational number, call it x, such that x^5 - x + 1 = 0.

Then we can write x=a/b, with a,b in Z, b nonzero.

By dividing out any common factors, we conclude that at least one

of a and b is odd. But our lemma says that both a and b are even.

This contradiction proves that our initial assumption was false,

that x was rational.


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, which is not divisible by any of p1,…,pn

      What does this contradict?

Lemma: Every natural number n>1 is either prime or has a prime divisor

that's larger than one.

     Assuming this lemma, we can conclude either that N is prime itself,

     or that it has a prime factor, which can't be one of p1,…,pn, 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

(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, and the proof that P(n) -> P(n+1) is the "induction step".


EG: Use induction to prove 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.