CS70 - Lecture 2 - Jan 21, 2011 - 10 Evans

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

Review of last time:


DEF: Proposition is a statement that must be either  true (T) or false (F)

EG: 2+2=4,   2+2=3

Notation: propositions denoted p, q, etc

DEF:  logical operators not p,  p and q,  p or q, p xor q

DEF:  compound propositions: constructed from simpler propositions using not, and, or, ()

EG:  (p and not q) or (not p and q)

DEF: A truth table is a table of all possible values of a compound proposition

ASK & WAIT: can this be simplified, i.e. written more briefly using other logical operators?

DEF: Implication: p => q,  same as (not p)  or q

ASK&WAIT:  Is  (1+1=3)  =>  (1+1=2)   True or False?

DEF: The converse of p -> q is q -> p; they need not be true  at the same time

EX: converse of last example is (1+1=2) => (1+1=3)

ASK&WAIT:  is this True or False?

DEF: The contrapositive of p -> q is not q -> not p;  these are the same (both True or both False)

DEF: p <-> q "p if and only if q",  "p->q and q->p", biconditional

Predicates: a proposition depending on one or more free variables x, y, ...

EG: R(x) = "x > 0",   so R(7) = "7>0" which is true

EG: S(x,y) = "x>y",   so S(1,2) = "1>2" which is false


Now that we understand a predicate like

   R(x) =  "x>0 => x+1>1"


   S(x) =  "2*x > x"

we'd like to be able to reason about when they are true.

For this we need Quantifiers:

Notation: N = natural numbers = {0,1,2,3…}

                 Z = integers { …, -2, -1, 0, 1, 2, …}


  To say a proposition R(x) is "always true," we write the new proposition

     forall x in N,  R(x), 

  For example

     \forall x in N . x^2 >= 0

     x^2 >= 0 is true for every x in N

     "the square of any natural number is non-negative"

     0^2 >= 0  /\  1^2 >= 0  /\  2^2 >= 0  /\ ...

  ASK&WAIT:  Which are true?

                         forall x in N, 2*x > x

                         forall x in N, 2*x >= x

                         forall x in Z, 2*x >= x

                         forall x in Z  ( forall y in Z   x^2-y^2 = (x-y)*(x+y)  )

  To say a proposition R(x) is true for at least one value of x, we write the new proposition

     thereexists x in N, S(x)

  For example

     thereexists x in N,  x = x^2

     "there is a solution x in N of x = x^2"

     0 = 0^2 or 1 = 1^2 or 2 = 2^2 or …


  "there exists a number greater than 5"

    \exists x in N . x > 5

  "for any x, x+1 is always strictly greater than x"

    \forall x in N . x+1 > x (true)

      consequence: 5+1 > 5  (substitute x by 5)

  "Let n be a natural number satisfying n>5.  Then n^2 > 25."

    \forall x in N . (n > 5) => (n^2 > 25)

Ask the class to translate the following into prop.logic:

  "there is no largest number"

    \forall x in N . \exists y in N . y>x

    \not \exists x in N . \forall z in N . z<x

  "the square of any even number is even"

    Evens = {all even integers}

    \forall x in Evens . x^2 in Evens

    \forall x in N . (\exists k in N . x=2k) => (\exists k in N . x^2=2k)


             Does this mean that x^2=x for every x in N?

    easier to understand:

    \forall x in N . (\exists k in N . x=2k) => (\exists j in N . x^2=2j)


  The order of quantifiers matters!

  \not \exists x . P(x)  <==>  \forall x . \not P(x)

  \forall x . \forall y . P(x,y)  <==>  \forall y . \forall x . P(x,y)

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"


     Proof techniques (aka rules of inferences, tautologies)

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

     Names: modus ponens, law of detachment, "common sense"

     EX: p = "3|n", q = "9|n^2", then "p -> q" is clearly true.

           So for example, if n=6, so that p is true, you can conclude 9|6^2

     Other common sense stuff:

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

     EX: p = '3|n', q = '9|n^2', r = '18|2*n^2', so p->q and q->r

         Thus p->r, i.e. 3|n -> 18|2*n^2

     (p and q) -> p

     EX: p = "3|n" , q = "2|n", (p and q) = '6|n', so 6|n -> 3|n

     p -> (p or q)

     EX: p = '3|n', q = '2|n', so 3|n -> (3|n or 2|n)

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

     Name: modus tollens, contrapositive

     Works because (p -> q) <-> (not q -> not p)

     EX: Show "if 3n+2 is odd then n is odd",

         use p="n is even", q="3n+2 is even"; then p -> q is clearly true,

         so 3n+2 odd and (p -> q) is the same as not q and (p -> q) whence

         not p i.e. n is odd

     [ not p -> F) ] -> p

     Name: proof by contradiction

     EX: cuberoot(5) is irrational, i.e. cannot be written as a/b where

         a and b are nonzero integers without common divisor

         let p = "cuberoot(5) is irrational"

         so not p = "cuberoot(5) is rational"

                  -> cuberoot(5) = a/b, where a and b have no common divisor, b != 0

                  -> 5 = a^3/b^3, or 5 b^3 = a^3 (use b != 0)

                  -> 5 | a^3 -> 5 | a -> a=5*c -> 5 b^3 = 125 c^3 (why 5|a ?)

                  -> b^3 = 25 c^3 -> 5 | b^3 -> 5 | b

                  -> 5|a and 5|b 

                  -> a and b have a common factor and do not have a 

                     common factor 

                  -> false

         so p is true

      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: Are this statement and its proof correct?

          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


                         \           /

                           \       /

                             \   /


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

                 is 180 degrees.

ASK&WAIT: Are this statement and its proof correct?

      EX: Are this statement and its proof correct?

          The number of primes is infinite:

          Proof: Suppose that the number of primes is finite; we will

                 get a contradiction.  Denote these primes by

                 p1,p2, ... , pn. Let N = p1*p2*...*pn+1. N is not

                 divisible by any of p1, p2, ..., pn, because it has

                 a remainder of 1 when you divide by any of them.

                 Therefore N is another prime.


ASK&WAIT: Are this statement and its proof correct?

      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 this statement and its proof correct?

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

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