CS70 - Lecture 1 - Jan 19, 2011 - 10 Evans

Name, class, URLs



Read on-line summary for course rules and grading policies

You are responsible for reading this and knowing the rules!

Text are notes "Discrete Math and Probability Theory" available at Copy Central (Hearst&Euclid)

Lecture notes will be posted (hopefully before lecture)

First HW will be due next Thursday Jan 27 just before midnight; work in groups!

Midterms will be in the evening, 6-8pm, on Mar 3 and Apr 7.

Introduce staff (Head TA Nick Knight, Terry Filiba, Fares Hedayati, Sayak Ray)

Enrollment: There is usually some churn at the beginning of the semester,

so we hope that people on the waiting list will get in eventually without adding

another section. Nick Knight is in charge of making enrollment changes.

Course Outline:

   Propositions, logic and proofs

          common language for rest of course

          logical operations in programs (CS61)

          hardware design (CS150)

      Why proofs?

         So people know something is true

         So computers know something is true:

            Some Java enabled cell phones have required

              downloaded programs to be "proof carrying codes",

              that contain a proof that they can't do anything

              bad to your cell phone (see www.cs.berkeley.edu/~necula)

   Induction and recursion

       writing correct programs and showing they are correct

   Example: Stable Marriage Problem

   Modular arithmetic, RSA cryptosystem

        keeping your money safe when you login to your bank

   Polynomials over finite fields and their use in error correcting codes

        how to send data reliably over unreliable networks, like the internet

   Probability theory (random variables, expectation, variance, …) and

      its applications (load balancing, hashing, inference…)

  Using the same proof ("diagonalization") to show that

      there are programs that you provably cannot write, 

          like a debugger that finds infinite loops

      there are more irrational numbers than rational numbers

  Begin course:

          DEF: Proposition is a statement that must be either 

                     true (T) or false (F)

           EG: Which of the following are propositions:

               2+2 = 4  (Y)

               2+2 = 3  (Y)

               826th digit of pi is 4 (Y)

               all dinosaurs were warm-blooded (Y)

               Is 2+2=4? (N)

               Let x = 3. (N)

               x+1 = 2   (N, unless we know the value of x)

               Every even number > 2 is the sum of two primes. (Y)

                    (Goldbach's Conjecture; best result known to be true is <= 6 primes)

               My CS70 GSI is nice (N)

          Notation: propositions denoted p,q,r ...

          DEF: not p , p or q (disjunction), p and q (conjunction),

               p xor q (exclusive or)

          Truth tables

          EG: What are the values of

             2+2=3  and 2+2 = 4  

             2+2=3  or    2+2=4

             2+2=3  xor  2+2=4

          DEF: a compound proposition is formed by simple propositions

               connected by logical operators and parentheses; 

           EG: (p and q) or (r and s)

               programming example below

          DEF: p -> q,  pronounced "p implies q", or  "if p, then q",  "p sufficient for q",

                "q necessary for p";  but it is simply defined as not(p) or q;

            EG: if it is sunny, then we go to the beach

                p = it is sunny, q = we go to the beach

                (T unless it is sunny (p)  and we don't go (not q))

              Truth table

  ASK&WAIT  if (today is Friday), then (2+3 = 6); 

                on which days is this true?

                p = (today is Friday), q = (2+3=6)

                T every day except Friday

  ASK&WAIT  if (1+1=3) then (2+2=4)

            Note that p and q need not have anything to do with one another

            in order to form the expression p -> q

  ASK&WAIT  if (1+1=3) then (2+2=3)

  ASK&WAIT  if (the moon is made of cheese) then (the speed of light is 55mph)

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

               at the same time

  ASK&WAIT  EG: If I am exactly 18 years old then I am allowed to vote;

                converse is

                if I am allowed to vote, then I am exactly 18 years old

                note that converse not necessarily true if original is

          DEF: The contrapositive of p -> q is not q -> not p; 

               these are the same

  ASK&WAIT  EG: If I am exactly 18 years old then I am allowed to vote;

                converse is

                if I am not allowed to vote, then 

                       I am not exactly 18 years old

                contrapositive is true

          Truth table proof of prop <=> contrapositive

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

               Truth Table

  Application to programming (Java or C syntax)


          if (compound proposition, or logical expression) then do something...

          if ((n>0) && (m<k)) then do something ...

             (n>0) and (m<k) are propositions whose value (T or F)

             can be evaluated when you get to this line in the program, 

             and && means "and", || means "or", etc.

          in computer 1 represents true and 0 false (representation details

             in CS61C, CS150)

More generally, we like to be able to reason about statements like

     x>0 => x+1>1

but we can't yet, because x>0 is not a proposition, we need something new.


     R(x) = "x > 0"

     Think of this as a proposition with a free variable x;

     the truth value depends on the choice of x.  In other words, R is a

     function from the natural numbers (say) to the set of propositions; for

     instance, R(7) is the proposition "7>0" (which, incidentally, is true).

EG: Application to Web search

          In www.google.com you can type into the Advanced Search form:

               With all the words: guano

               and With at least one of the words: geometry tickle

          Same as "find all web pages W for which the proposition is true"

               (W contains guano) and 

                  ((W contains geometry) or (W contains tickle))

  ASK&WAIT: what web pages do you get? (besides the Ma55 2004/07 web pages,

                    which have all three, like this one)

            EX: Flickr photo with title "tickle my nose with guano"  (not the word geometry)

            EX: WIkipedia entry for Dr Strangelove, with character named Guano talking

                    about geometry of B-52 fuselage (not the word tickle)

            EX: Mass movement in cave sediments, how the geometry

                   depends on bat guano deposits.

                   contains guano and geometry, not tickle


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 number = {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,  S(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:  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:

  "doubling a number always makes it larger"

    \forall x in N . 2x > x (false; x=0)

    \forall x in N . 2x >= x (true.)

    but: latter proposition is false in integers! (x<0)

    highlights need to include set over which you're quantifying

  "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

  "every even number >= 4 can be written as the sum of two primes"

    \forall x in N, (x>=4 and x even) => \exists y,z in Primes . x = y+z

    E = {even integers >= 4}

    \forall x in E . \exists y,z in N . y,z prime and x = y+z

       (unknown; Goldbach's conjecture!)

  "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)

True or false?

  \forall x in N \exists y in N . x = 2*y  (false in integers; true in reals)

  \forall x in N \exists y in N . y = 2*x  (true)

    (note: y is allowed to depend on x; think of this as a game

     where you pick x, then I pick y, and I win if y=2x; the proposition

     is true if I have a winning strategy that lets me win no matter what

     you do)

  \exists x in N \forall y in N . y  = 2*x  (false)

  \exists x in N \exists y in N . y  = 2*x  (true)

  \forall x in N \forall y in N . y  = 2*x  (false)


  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)