Download PPT - UBC Computer Science

Document related concepts

Computational complexity theory wikipedia , lookup

Transcript
snick

snack
CPSC 121: Models of Computation
2011 Winter Term 1
Proof (First Visit)
Steve Wolfman, based on notes by Patrice
Belleville, Meghan Allen and others
1
Outline
• Prereqs, Learning Goals, and Quiz Notes
• Prelude: What Is Proof?
• Problems and Discussion
– “Prove Your Own Adventure”
– Why rules of inference? (advantages + tradeoffs)
– Onnagata, Explore and Critique
• Next Lecture Notes
2
Learning Goals: Pre-Class
By the start of class, you should be able to:
– Use truth tables to establish or refute the
validity of a rule of inference.
– Given a rule of inference and propositional
logic statements that correspond to the rule’s
premises, apply the rule to infer a new
statement implied by the original statements.
3
Learning Goals: In-Class
By the end of this unit, you should be able to:
– Explore the consequences of a set of
propositional logic statements by application of
equivalence and inference rules, especially in
order to massage statements into a desired form.
– Critique a propositional logic proof; that is,
determine whether or not is valid (and explain
why) and judge the applicability of its result to a
specific context.
– Devise and attempt multiple different, appropriate
strategies for proving a propositional logic
statement follows from a list of premises.
4
NOT a Quiz Note
~p
~(p v q)
a. This is valid by generalization (p  p v q).
b. This is valid because anytime ~p is true, ~(p
v q) is also true.
c. This is invalid by generalization (p  p v q).
d. This is invalid because when p = F and q =
T, ~p is true but ~(p v q) is false.
e. None of these.
8
What does this mean?
We can always substitute something
equivalent for a “complete” part of a logical
statement.
We cannot always apply a rule of inference to
just a part of a logical statement.
Therefore, we will only apply rules of
inference to complete statements!
9
Outline
• Prereqs, Learning Goals, and Quiz Notes
• Prelude: What Is Proof?
• Problems and Discussion
– “Prove Your Own Adventure”
– Why rules of inference? (advantages + tradeoffs)
– Onnagata, Explore and Critique
• Next Lecture Notes
10
What is Proof?
A rigorous formal argument that
unequivocally demonstrates the
truth of a proposition, given the truth
of the proof’s premises.
Adapted from MathWorld: http://mathworld.wolfram.com/Proof.html
11
What is Proof?
A rigorous formal argument that
unequivocally demonstrates the
truth of a proposition (conclusion),
given the truth of the proof’s
premises.
Adapted from MathWorld: http://mathworld.wolfram.com/Proof.html
12
Problem: Meaning of Proof
Let’s say you prove the following:
Premise 1
Premise 2
⁞
Premise n
Conclusion
What does this mean?
a. Premises 1 to n are true
b. Conclusion is true
c. Premises 1 to n can be true
d. Conclusion can be true
e. None of the above
13
Tasting Powerful Proof:
Some Things We Might Prove
• We can build a “three-way switch” system with any
number of switches. 
• We can build a combinational circuit matching any
truth table. 
• We can build any digital logic circuit using nothing but
NAND gates.
• We can sort a list by breaking it in half, and then
sorting and merging the halves.
• We can find the GCD of two numbers by finding the
GCD of the 2nd and the remainder when dividing the
1st by the 2nd.
• There’s (sort of) no fair way to run elections.
• There are problems no program can solve.
14
Meanwhile...
What Is a Propositional Logic
Proof?
An argument in which (1) each line is a
propositional logic statement, (2) each
statement is a premise or follows unequivocally
by a previously established rule of inference
from the truth of previous statements, and (3)
the last statement is the conclusion.
A very constrained form of proof, but a good starting point.
Interesting proofs will usually come in less structured
15
packages than propositional logic proofs.
Outline
• Prereqs, Learning Goals, and Quiz Notes
• Prelude: What Is Proof?
• Problems and Discussion
– “Prove Your Own Adventure”
– Why rules of inference? (advantages + tradeoffs)
– Onnagata, Explore and Critique
• Next Lecture Notes
16
Prop Logic Proof Problem
To prove:
~(q  r)
(u  q)  s
~s  ~p___
 ~p
17
“Prove Your Own Adventure”
To prove:
~(q  r)
(u  q)  s
~s  ~p___
 ~p
Which step is the easiest to fill in?
1. ~(q  r)
Premise
2. (u  q)  s
Premise
3. ~s  ~p
Premise
[STEP A: near the start]
[STEP B: in the middle]
[STEP C: near the end]
[STEP D: last step]
18
D: Last Step
To prove:
~(q  r)
(u  q)  s
~s  ~p___
 ~p
1. ~(q  r)
2. (u  q)  s
3. ~s  ~p
...
~q  ~r
Why do we want to put ~p at the end?
~q
...
a. ~p is the proof’s conclusion
((u  q)  s) 
b. ~p is the end of the last premise
(s  (u  q))
c. every proof ends with ~p
d. None of these but some other reason
...
e.
None of these because we don’t
want it there
Premise
Premise
Premise
De Morgan’s (1)
Specialization (?)
Bicond (2)
~s
~p
Modus ponens (3,?)
19
C: Near the End
To prove:
~(q  r)
(u  q)  s
~s  ~p___
 ~p
Why do we want to put the blue
line/justification at the end?
a.
b.
c.
d.
e.
1. ~(q  r)
2. (u  q)  s
3. ~s  ~p
...
~q  ~r
~q
...
((u  q)  s) 
(s  (u  q))
...
~s  ~p is the last premise
~s  ~p is the only premise that
mentions ~s
~s  ~p is the only premise that
~s
mentions p
~p
None of these but some other reason
None of these b/c we don’t want it there
Premise
Premise
Premise
De Morgan’s (1)
Specialization (?)
Bicond (2)
Modus ponens (3,?)
20
A: Near the Start
To prove:
~(q  r)
(u  q)  s
~s  ~p___
 ~p
1. ~(q  r)
2. (u  q)  s
3. ~s  ~p
...
~q  ~r
Why do we want the blue
~q
lines/justifications?
...
((u  q)  s) 
a. ~(q  r) is the first premise
(s  (u  q))
b. ~(q  r) is a useless premise
c. We can’t work directly with a premise
...
d.
e.
with a negation “on the outside”
Neither the conclusion nor another
premise mentions r
None of these
Premise
Premise
Premise
De Morgan’s (1)
Specialization (?)
Bicond (2)
~s
~p
Modus ponens (3,?)
21
B: In the Middle
To prove:
~(q  r)
(u  q)  s
~s  ~p___
 ~p
1. ~(q  r)
2. (u  q)  s
3. ~s  ~p
...
~q  ~r
Why do we want the blue
~q
line/justification?
...
a. (u  q)  s is the only premise left ((u  q)  s) 
b. (u  q)  s is the only premise that
(s  (u  q))
mentions u
...
c. (u  q)  s is the only premise that
d.
e.
~s
mentions s without a negation
We have no rule to get directly from ~p
one side of a biconditional to the other
None of these
Premise
Premise
Premise
De Morgan’s (1)
Specialization (?)
Bicond (2)
Modus ponens (3,?)
22
Prop Logic Proof Strategies
•
•
•
•
•
Work backwards from the end
Play with alternate forms of premises
Identify and eliminate irrelevant information
Identify and focus on critical information
Alter statements’ forms so they’re easier to
work with
• “Step back” from the problem frequently to
think about assumptions you might have
wrong or other approaches you could take
And, if you don’t know that what you’re trying to prove follows...
31
switch from proving to disproving and back now and then.
Continuing From There
To prove:
~(q  r)
(u  q)  s
~s  ~p___
 ~p
Which direction of  goes in step 7?
a.
b.
c.
d.
e.
1. ~(q  r)
Premise
2. (u  q)  s Premise
3. ~s  ~p
Premise
4. ~q  ~r
De Morgan’s (1)
5. ~q
Specialization (4)
6. ((u  q)  s)  Bicond (2)
(s  (u  q))
7. ??????
Specialization (6)
(u  q)  s because the simple part
is on the right
~s
(u  q)  s because the other
~p
direction can’t establish ~s
s  (u  q) because the simple part
is on the left
s  (u  q) because the other
direction can’t establish ~s
None of these
...
Modus ponens (3,?)
32
Aside: What does it mean to
“work backward”?
Take the conclusion of the proof.
Use a rule in reverse to generate something
closer to a statement you already have (like
a premise).
35
Finishing Up (1 of 3)
To prove:
~(q  r)
(u  q)  s
~s  ~p___
 ~p
We know we needed ~(u  q) on
line 9 because that’s what we
created line 7 for!
Side Note: Can we work directly
with a statement with a negation
“on the outside”?
1. ~(q  r)
Premise
2. (u  q)  s Premise
3. ~s  ~p
Premise
4. ~q  ~r
De Morgan’s (1)
5. ~q
Specialization (4)
6. ((u  q)  s)  Bicond (2)
(s  (u  q))
7. s  (u  q) Specialization (6)
8. ????
????
9. ~(u  q)
10. ~s
????
Modus tollens (7, 9)
11. ~p
Modus ponens (3,10)
36
Finishing Up (1 of 3)
To prove:
~(q  r)
(u  q)  s
~s  ~p___
 ~p
We know we needed ~(u  q) on
line 9 because that’s what we
created line 7 for!
Now, how do we get ~(u  q)?
Working forward is tricky. Let’s
work backward. What is ~(u  q)
equivalent to?
1. ~(q  r)
Premise
2. (u  q)  s Premise
3. ~s  ~p
Premise
4. ~q  ~r
De Morgan’s (1)
5. ~q
Specialization (4)
6. ((u  q)  s)  Bicond (2)
(s  (u  q))
7. s  (u  q) Specialization (6)
8. ????
????
9. ~(u  q)
10. ~s
????
Modus tollens (7, 9)
11. ~p
Modus ponens (3,10)
37
Finishing Up (2 of 3)
To prove:
~(q  r)
(u  q)  s
~s  ~p___
 ~p
All that’s left is to get to ~u  ~q.
How do we do it?
1. ~(q  r)
Premise
2. (u  q)  s Premise
3. ~s  ~p
Premise
4. ~q  ~r
De Morgan’s (1)
5. ~q
Specialization (4)
6. ((u  q)  s)  Bicond (2)
(s  (u  q))
7. s  (u  q) Specialization (6)
8. ~u  ~q
????
9. ~(u  q)
10. ~s
De Morgan’s (8)
Modus tollens (7, 9)
11. ~p
Modus ponens (3,10)
38
Finishing Up (3 of 3)
To prove:
~(q  r)
(u  q)  s
~s  ~p___
 ~p
As usual in our slides, we made no
mistakes and reached no dead
ends. That’s not the way things
really go on difficult proofs!
Mistakes and dead ends are part of
the discovery process! So, step
back now and then and reconsider
your assumptions and approach!
1. ~(q  r)
Premise
2. (u  q)  s Premise
3. ~s  ~p
Premise
4. ~q  ~r
De Morgan’s (1)
5. ~q
Specialization (4)
6. ((u  q)  s)  Bicond (2)
(s  (u  q))
7. s  (u  q) Specialization (6)
8. ~u  ~q
Generalization (5)
9. ~(u  q)
10. ~s
De Morgan’s (8)
Modus tollens (7, 9)
11. ~p
Modus ponens (3,10)
39
Outline
• Prereqs, Learning Goals, and Quiz Notes
• Prelude: What Is Proof?
• Problems and Discussion
– “Prove Your Own Adventure”
– Why rules of inference? (advantages + tradeoffs)
– Onnagata, Explore and Critique
• Next Lecture Notes
40
Limitations of Truth Tables
Why not just use truth tables to prove
propositional logic theorems?
a. No reason; truth tables are enough.
b. Truth tables scale poorly to large problems.
c. Rules of inference and equivalence rules
can prove theorems that cannot be proven
with truth tables.
d. Truth tables require insight to use, while
rules of inference can be applied
mechanically.
41
Limitations of
Logical Equivalences
Why not use logical equivalences to prove that
the conclusions follow from the premises?
a. No reason; logical equivalences are enough.
b. Logical equivalences scale poorly to large
problems.
c. Rules of inference and truth tables can
prove theorems that cannot be proven with
logical equivalences.
d. Logical equivalences require insight to use,
while rules of inference can be applied
mechanically.
42
Outline
• Prereqs, Learning Goals, and Quiz Notes
• Prelude: What Is Proof?
• Problems and Discussion
– “Prove Your Own Adventure”
– Why rules of inference? (advantages + tradeoffs)
– Onnagata: Explore and Critique
• Next Lecture Notes
43
Problem: Onnagata
Problem: Critique the following argument.
Premise 1: If women are too close to femininity to portray
women then men must be too close to masculinity to
play men, and vice versa.
Premise 2: And yet, if the onnagata are correct, women are
too close to femininity to portray women and yet men
are not too close to masculinity to play men.
Conclusion: Therefore, the
onnagata are incorrect, and
women are not too close to
femininity to portray women.
44
Contradictory Premises?
Do premises #1 and #2 contradict each other (i.e., is
(premise1  premise2) logically equivalent to F)?
a. Yes
b. No
c. Not enough information to tell.
46
Defining the Problem
Which definitions should we use?
a. w = women, m = men, f = femininity, m = masculinity, o =
onnagata, c = correct
b. w = women are too close to femininity, m = men are too
close to masculinity, pw = women portray women, pm =
men portray men, o = onnagata are correct
c. w = women are too close to femininity to portray women,
m = men are too close to masculinity to portray men,
o = onnagata are correct
d. None of these, but another set of definitions works well.
e. None of these, and this problem cannot be modeled well
with propositional logic.
47
Translating the Statements
Which of these is not an accurate translation
of one of the statements?
a. w  m
b. (w  m)  (m  w)
c. o  (w  ~m)
d. ~o  ~w
e. All of these are accurate translations.
48
Contradictory Premises?
So premises #1 and #2 are w  m and o  (w  ~m).
Do premises #1 and #2 contradict each other (i.e., is
(premise1  premise2) logically equivalent to F)?
a. Yes
b. No
c. Not enough information to tell.
49
Problem: Now, Explore!
Critique the argument by either:
(1) Proving it correct (and commenting on how
good the propositional logic model’s fit to the
context is).
How do we prove prop logic statements?
(2) Showing that it is an invalid argument.
How do we show an argument is invalid?
(Remember the quiz!)
50
Outline
• Prereqs, Learning Goals, and Quiz Notes
• Prelude: What Is Proof?
• Problems and Discussion
– “Prove Your Own Adventure”
– Why rules of inference? (advantages + tradeoffs)
– Onnagata, Explore and Critique
• Next Lecture Notes
51
Next Lecture Learning Goals:
Pre-Class
By the start of class, you should be able to:
– Evaluate the truth of statements that include
predicates applied to particular values.
– Show predicate logic statements are true by
enumerating examples (i.e., all examples in the
domain for a universal or one for an existential).
– Show predicate logic statements are false by
enumerating counterexamples (i.e., one
counterexample for universals or all in the domain
for existentials).
– Translate between statements in formal predicate
logic notation and equivalent statements in
closely matching informal language (i.e., informal
statements with clear and explicitly stated
quantifiers).
52
Next Lecture Prerequisites
Review (Epp 4th ed) Chapter 2 and be able
to solve any Chapter 2 exercise.
Read Sections 3.1 and 3.3 (skipping the
“Negation” sections in 3.3)
Complete the open-book, untimed quiz on
Vista.
53
snick

snack
More problems to solve...
(on your own or if we have time)
54
Problem:
Who put the cat in the piano?
Hercule Poirot has been asked by Lord Martin to find out who closed
the lid of his piano after dumping the cat inside. Poirot interrogates
two of the servants, Akilna and Eiluj. One and only one of them put
the cat in the piano. Plus, one always lies and one never lies.
Akilna says:
– Eiluj did it.
– Urquhart paid her $50 to help him study.
Eiluj says:
– I did not put the cat in the piano.
– Urquhart gave me less than $60 to help him study.
Problem: Whodunit?
55
Problem: Automating Proof
Given:
pq
p  ~q  r
(r  ~p)  s  ~p
~r
Problem: What’s everything you can prove?
56
Problem: Canonical Form
A common form for propositional logic
expressions, called “disjunctive normal
form” or “sum of products form”, looks like
this:
(a  ~b  d)  (~c)  (~a  ~d)  (b  c  d
 e)  ...
In other words, each clause is built up of
simple propositions or their negations,
ANDed together, and all the clauses are
57
ORed together.
Problem: Canonical Form
Problem: Prove that any propositional logic
statement can be expressed in disjunctive
normal form.
58
Mystery #1
Theorem:
p  q
q  (r  s)
~r  (~t  u)
p  t
 u
Is this argument valid or invalid?
59
Is whatever u means true?
Mystery #2
Theorem:
p
p  r
p  (q  ~r)
~q  ~s
 s
Is this argument valid or invalid?
60
Is whatever s means true?
Mystery #3
Theorem:
q
p  m
q  (r  m)
m  q
 p
Is this argument valid or invalid?
61
Is whatever p means true?
Practice Problem (for you!)
Prove (with truth tables) that hypothetical
syllogism is a valid rule of inference:
p  q
q  r
 p  r
62
Practice Problem (for you!)
Prove (with truth tables) whether this is a
valid rule of inference:
q
p  q
 p
63
Practice Problem (for you!)
Are the following arguments valid?
This apple is green.
If an apple is green, it is sour.
 This apple is sour.
Sam is not barking.
If Sam is barking, then Sam is a dog.
 Sam is not a dog.
64
Practice Problem (for you!)
Are the following arguments valid?
This shirt is comfortable.
If a shirt is comfortable, it’s chartreuse.
 This shirt is chartreuse.
It’s not cold.
If it’s January, it’s cold.
 It’s not January.
65
Is valid (as a term) the same as true or correct (as English ideas)?
More Practice
Meghan is rich.
If Meghan is rich, she will pay your tuition.
 Meghan will pay your tuition.
Is this argument valid?
Should you bother sending in a check for your
66
tuition, or is Meghan going to do it?
Problem:
Equivalent Java Programs
Problem: How many valid Java programs
are there that do exactly the same thing?
67
Resources: Statements
From the Java language
specification, a
standard statement is
one that can be:
68
http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.5
Resources: Statements
From the Java language
specification, a
standard statement is
one that can be:
69
http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.5
What’s a “Block”?
Back to the Java Language Specification:
70
http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.2
What’s a “Block”?
A block is a sequence of statements, local
class declarations and local variable
declaration statements within braces.
…
A block is executed by executing each of the
local variable declaration statements and
other statements in order from first to last
(left to right).
71
What’s an “EmptyStatement”
Back to the Java Language Specification:
http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.6
72
Problem: Validity of Arguments
Problem: If an argument is valid, does that
mean its conclusion is true? If an
argument is invalid, does that mean its
conclusion is false?
73
Problem: Proofs and
Contradiction
Problem: Imagine I assume premises x, y,
and z and prove F. What can I conclude
(besides “false is true if x, y, and z are
true”)?
74
Proof Critique
Theorem: √2 is irrational
Proof: Assume √2 is rational, then...
There’s some integers p and q such that √2 = p/q, and
p and q share no factors.
2 = (p/q)2 = p2/q2 and p2 = 2q2
p2 is divisible by 2; so p is divisible by 2.
There’s some integer k such that p = 2k.
q2 = p2/2 = (2k)2/2 = 2k2; so q2 and q are divisible by 2.
p and q do share the factor 2, a contradiction!
√2 is irrational. QED
75
Problem: Comparing Deduction
and Equivalence Rules
Problem: How are logical equivalence rules
and deduction rules similar and different,
in form, function, and the means by which
we establish their truth?
76
Problem: Evens and Integers
Problem: Which are there more of, (a)
positive even integers, (b) positive
integers, or (c) neither?
77