The primary goal of this course is to become familiar with some of the basic mathematical ideas used in programming.
Levin, 0.1 and 0.2
Basic logic combinations:
A and B
A or B
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, we will analyze the consequences if Troll 1 is a knave. Troll 1's statement has the form A => B, where A is "Troll 1 is a knave" and B is "There are exactly two knights here". If Troll 1 is a knave, his statement is false; what does it mean for A=>B to be false? It can only happen if A is true and B is false, that is, A and ¬B. If Troll 1 is a knave (the A part), then Troll 1's statement is false, so the ¬B part must be true (because A and ¬B is true), and so B must be false; that is "there are exactly two knights" must be false.
We already know there is at least one knight. If Troll 1 is a knave (as we have been supposing), 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.
Figuring out that we should pursue the hypothesis "Troll 1 is a knave", to arrive at a contradiction, is not at all obvious. But it works!
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 (which is true if
S1 is false!) is that C1 is empty and not S2. This is a
contradiction, because we know S2 is true!
So we know S1 is true and S2 is false. The falsity of S2 means that 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.)Other proofs 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 seldom any 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+b (Levin example 0.2.4)
Quantifiers: ∀ (for all) and ∃ (there exists)
Here are 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.
In each game above, who has the winning strategy?
Does every 2-move game have a winning strategy?
Negation of quantifiers
From Levin p 15. Are any of the following equivalent? Do any imply any other?
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:
¬∃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?
start with: n is even if and only if n*n is even.
n is even if ∃k (n=2*k)
Homework 1, due Friday Jan 28, on Sakai