The primary goal of this course is to become familiar with some of the basic mathematical ideas used in programming.

Reading:

Levin, 0.1 and 0.2

Aspnes, 2.1-2.3

Basic logic combinations:

A and B

A or B

A=> B

~A

From Levin, page 4:

While walking through a fictional forest, you
encounter three trolls guarding a bridge. Each is either a knight, who
always tells the truth, or a knave, who always lies. The trolls will not
let you pass until you correctly identify each as either a knight or a
knave. Each troll makes a single statement:

Troll 1: If I am a knave, then there are exactly two knights here.

Troll 2: Troll 1 is lying.

Troll 3: Either we are all knaves or at least one of us is a knight.

Which troll is which?

How do you go about analyzing this?

First, Troll 3 is telling the truth (why?) and so is a knight.

Second, analyze the consequences **if Troll 1 is a knave**.
What does it mean for A=>B to be false? It can only happen if A is true
and B is false. If Troll 1 is a knave, then his statement is false, so "I
am a knave" must be true and "there are exactly two knights" must be
false. We already know there is at least one knight.

If Troll 1 is a knave, then there can be only one knight (Troll 3), and
so Troll 2 is a knave. But Troll 2 told the truth **if Troll 1 is a
knave**.

This is a contradiction. So Troll 1 must be a knight! Which means Troll 2 is a knave.

---------------

Levin page 2:

3. After excavating for weeks, you finally arrive at the burial chamber. The room is empty except for two large chests. On each is carved a message (strangely in English):

Chest 1: If this chest is empty, then the other
chest’s message is true.

Chest 2: This chest is filled with treasure or the
other chest contains deadly scorpions.

How about rephrasing as two statements S1 and S2:

S1: if C1 is empty, then S2

S2: C2 is filled with treasure or C1 is filled with
scorpions

You know exactly one of these messages is true. What should you do? Which chest should you open?

Suppose S1 is false, so S2 is true. The negation of S1 is that C1 is
empty **and** not S2. This is a contradiction, because we
know S2 is true!

So we know S2 is true and S1 is false. Then C2 is not filled with
treasure **and** C1 does not have scorpions. And also C1 is
not empty. Let's open C1! (But carefully; it might be filled with spiders.
Or *half* full of scorpions.)

- sqrt(2) is irrational
- there are infinitely many prime numbers

**Wednesday**

- Chest problem, above
- sqrt(2) by contradiction

A few words about Atomic statements: **no variables**.

A->B: if A then B, or A implies B. But with atomic statements, there is really no cause-and-effect.

Converse: B->A **not** automatically
true, though sometimes an interesting question

Contrapositive: ~B -> ~A. This **is** automatically
true.

if and only if, or <->

P is sufficient for Q: P->Q. P is necessary for Q: Q->P

An example proof: if a and b are even, then so is a+ (Levin example 0.2.4)

Quantifiers

Some simple two-person two-move games. In each case, player A chooses a
whole number a, and then, seeing A's move, B chooses a whole number b.
Based on the choices a and b, we determine which player **wins**.

- The first player to choose a 3 wins (that is, B wins if a!=3 and b=3)
- B wins if a+b<100
- Whichever player chooses the largest number wins

In each game above, who has the winning strategy?

Does *every* 2-move game have a winning strategy?

Negation of quantifiers

**Friday**

From Levin p 15. Are any of the following equivalent? Do any imply any other?

- You can fool some people all of the time.
- You can fool everyone some of the time.
- You can always fool some people.
- Sometimes you can fool everyone.

The first is (∃ person p)(∀ time t) CanFool(p,t)

The second is either ∀p∃t(CanFool(p,t)) or else ∃t∀p CanFool(p,t). What is
the difference? Let's go with the first.

The third is ∃p∀t CanFool(p,t), same as the first.

The fourth is ∃t∀p CanFool(p,t)

A **predicate** is a formula with a free variable. We can **bind**
that variable by sticking a quantifier for it on the front.

A few more examples of quantifier negation:

Not exists

~∃a ∀b Win1(a,b)

lim f(x) = L as x->a: ∀e ∃d ∀x |x-a| < d => |f(x)-L| < e.

Suppose you are driving down the highway and see a sign:

No passing zones not striped

A hyphen is missing: no-passing zones are not striped, because they just repaved. But what if we take it to mean:

There are not any passing zones that are not striped

What does this mean?

sqrt(2)

start with: n is even if and only if n*n is even.

n is even if ∃k (n=2*k)

You are walking down a path when you come to two doors. Opening one of the
doors will lead you to a life of prosperity and happiness, while opening
the other door will lead to a life of misery and sorrow. You don't know
which door leads to which life. In front of the doors are two trolls who
know which door leads where. One of the trolls is a knight, the other is a
knave. You don't know which is which. You are allowed to ask one single
question to one of the trolls (not both) to figure out which door to open.
What question should you ask?

Homework 1, due Friday Jan 24, on Sakai