Logic and Proof

Download Report

Transcript Logic and Proof

Lecture 4
Logic and Proof
Plan of lecture
• Predicate logic
• Relations between quantifiers
• Proof
2
Introduction
• Propositional Logic focussed on the syntax and
semantics of the logical connectives
• Looked at some equivalences
• Propositional Logic is abstract and limited
• Predicate Logic less abstract, more expressive, and
more like natural language
• After Predicate Logic, will discuss proof in
Propositional Logic
3
Propositional Logic has Limitations
• Examples:
– P stands for “a car is red”
– Q stands for “a book is red”
– Every new red object would need a different
proposition, e.g. “a cat is red”
– There is no “formal connection” between propositions
– Similarly, “a cat is fat” and “a cat is striped”
– Similarly, “Bill loves Jill”, “Will loves Jill”, “Jill loves Phil”
– What about representing quantifiers? “Someone loves
Jill” and “Every cat is red”
• Generally, articulating the logic to reason about
more sorts of sentences
4
Introduce Elements of the Language
•
•
•
•
Introduce predicates (one and two place)
Introduce entities and variables
Introduce quantifiers
Predicates allow us to parameterise statements:
– R(x) stands for “x bears/has property R”
– In our example, if we assume R is “red” then
• R(car) captures “the car is red”
• R(book) captures “the book is red”
– N.B.: truth of a predicate depends on its parameters
• Parameters (variables) allows us to use quantifiers
– Some objects are red
– All objects are red
5
FOL Syntax
• Predicate logic or First-order logic
• Syntax:
– Capital letters P, Q, R, S, ... are predicate symbols
• Predicate symbols have a number of parameters (“arity”)
• May use more “informative” symbols such as “Red” or “Blue”
– An atomic formula is
•
•
•
•
Attention - Number of
parameters must match the
"arity" of the predicate.
A predicate symbol
Followed by a “(“
Followed by 1 or more parameters separated by “,”
Followed by a “)”
– Examples:
P(x) Q(x, y)
Father(andrew, bill)
Likes(john,x)
6
Parameters and Connectives
• Notice that parameters can be
– Variables x, y, z, ... or
Constants are
– Constants a, b, bill, john, 2, 34, and so on fixed in meaning.
– Examples:
Lives(elizabeth, x) Even(2) Divisible(10,2) Prime(8)
• Connectives and, or, not,  can be used too
– Examples:
• not(P(x) and Q(x, y))  not(P(a))
• Q(x,a) or (not(Q (x, b)))
– Attention! Look at brackets, look at what is connected
to what....
7
Truth and Parameters
• When is a Predicate Logic statement true (false)?
• Informally, when the predicate and its parameters
correspond to what holds in the "real world" or in
the "model"
informal model talk,
• Model: Bill loves Jill, The car is red. not natural language.
• Logical Formulation: Loves(bill, jill), Black(car)
8
Quantifiers
• Quantifiers, formally (Attention to different xs)
– x P(x) – “for all values of x, P holds”
– x Q(x) – “for some values of x, Q holds”
• We can add quantifiers to any formula
– If  is a predicate formula then x() is a formula
– If  is a predicate formula then x() is a formula
• Examples:
– x (P(x) and Q(x, x))
– x (Q(x)  Q(y))
– x (y (R(x, y)))
– x (R(bill, jill)))
9
Quantifiers Evaluated
• Quantifiers calculation. When is a quantified
expression true?
– x P(x) – “for all values x can have wrt domain, P holds”
– x Q(x) – “for some value x can have wrt domain, Q
holds”
• Domain of Discourse (things we talk about): Phil,
Bill, Will, Jill
• Model: Bill loves Jill, Will loves Jill, Jill loves Phil
• Everyone loves Jill? x Loves(x,jill). For every thing
in the domain, it loves Jill.
• Jill loves someone? x Loves(jill, x). For some thing
in the domain, Jill loves it.
10
Quantifier Interactions
• Nesting of quantifiers is allowed
– x (y (R(x, y)))
• Not all variables may have quantifiers
– x (Q(x)  Q(y)) (y is not bound. Like a pronoun)
• Scope of quantifier
– Quantifier “binds” to nearest formula
– “x (P(x)) and Q(x)” (x of Q(x) is not bound to the
quantifier; it is free)
• “Clash” of variable names
– (x P(x))  (x Q(x)) (x of P(x) and x of Q(x) distinct)
– Renaming clarifies dependency: (x P(x))  (y Q(y))
11
Relation between Quantifiers
• Quantifiers are duals of one another
• Let  be a formula. The following holds:
not(x())  x(not())
not(x ())  x(not())
• Proof using a model:
Domain = Bill, Jill
Model = Bill is happy.
It is not the case that everyone is happy ?=?
Someone is not happy
It is not the case that someone is happy ?=?
Everyone is not happy
12
Relation between Quantifiers
• Nested quantifiers can be handled similarly:
not(x(y (P(x,y)))) 
x(not(y (P(x,y)))) 
x(not(y (P(x,y)))) 
x(y(not(P(x,y))))
13
Reading (meaning of) Predicate Logic
If Loves(x,y) stands for “x loves y”
• The meaning of x (Loves(x,x))) is
– For all x, Loves(x,x) holds
– “Everyone loves him/herself”
• The meaning of x (y (Loves(x,y))) is
– For all x, there is a y for which Loves(x,y) holds
– “Everyone loves someone” ??NL and logic correlated??
• The meaning of y(x (not (Loves(x,y))) is
– There is a y such that for all x, Loves(x,y) does not hold
– “There is someone whom no-one loves”
14
Writing (meaning of) Predicate Logic
If Loves(x,y) stands for “x loves y”
• Write a formula for “someone is loved by everyone”
y(x (Loves(x,y))
• Write a formula for “no-one is loved by everyone”
– It is not true that there is someone who is loved by
everyone
not(y(x (Loves(x,y)))) 
y(not(x (Loves(x,y)))) 
y(x (not(Loves(x,y))))
15
Summary About Logic
You should now know:
• Why logic is important to computing
• Propositional logic: syntax and meaning
• How to write truth tables
• Predicate logic: syntax and meaning
• Attention: translating from natural language to
logical formalisations is an active research area.
There are very powerful automated tools doing this
lately:
http://gmb.let.rug.nl/explorer/explore.php
16
Proof Section
• Motivation: why proof is important to computing
• Methods of proof
• Return to Propositional Logic for this.
Complications working with Predicate Logic.
1
Why proof is important to Computing
• Suppose you write a specification of the knowledge of some
domain, e.g. who loves whom, who makes whom happy, rules
about happiness, and rules about what follows from being
happy.
• We must demonstrate that our specification does not give
rise to contradiction (someone loves and does not loves Jill).
• We must demonstrate that our specification does not draw
the wrong inferences.
• We must demonstrate that what we claim holds in the
specification does hold.
• The demonstration should be given as a proof, which is a
systematic way to reason about the specification.
• Not yet about programs (about actions), but getting there.
18
Basic idea
• Deducing statements relative to assumptions and rules.
• Start with some logical formulas that you want to use in
your proof (assumptions).
• Identify what you want to prove (a conclusion).
• Look at your rules.
• Use the templates for reasoning and the equivalences
to transform formulas from your start formulas till you
get what you want to prove. Logical steps.
• Skill in knowing the templates and equivalences.
• Skill in strategy (what templates and equivalences to
use when).
• Symbolic computing. Same idea as what you may have
done with transformations of expressions with
numbers or in geometry.
19
Simple example
• Assume: if today is Friday then I am wearing a green shirt
• Assume: Today is Friday
• Infer: I am wearing a green shirt
• If P, then Q
• P
• Therefore, Q
• P -> Q
• P
• Therefore, Q
This is a reasoning template called:
Modus Ponens
Latin for "mode that affirms"
20
Other examples
• Assume: Today is Friday and I am wearing a green shirt
• Infer: I am wearing a green shirt
• P and Q; Therefore, Q
• Assume: Today is Friday or I am wearing a green shirt
• Assume: I am not wearing a green shirt
• Infer: Today is Friday
• P or Q, Not Q; Therefore, P
21
A variety of reasoning templates
• Double negative elimination
– From ¬ ¬ φ, we infer φ
• Conjunction introduction
– From φ and ψ, we infer ( φ ∧ ψ ).
• Conjunction elimination
– From ( φ ∧ ψ ), we infer φ and ψ
• Disjunction introduction
– From φ, we infer (φ ∨ ψ) and (ψ ∨ φ).
Check your intuitions
22
A variety of reasoning templates
• Disjunction elimination
– From ¬ φ and (φ ∨ ψ), we infer ψ.
• Modus ponens
– From φ and ( φ  ψ ), we infer ψ.
• Modus tollens (denies by denying)
– From ¬ ψ and ( φ  ψ ), we infer ¬ φ.
• Others
23
How to prove
1. Write down premises.
2. Apply natural deduction rule to one (or more)
premise.
3. Write down the result of applying the rule to the
premise(s). Make a note of what rule is applied
and what premises are used.
4. Reapply 2 and 3 until the result in 3 is the intended
conclusion.
24
Sample proof
Problem: Prove that p implies p V q
1. p
Premise
2. p V q
Disjunction Introduction on 1
Conclusion
Easy and obvious
25
Sample proof
Problem: Prove that p and p V q  s imply s
1. p
Premise
2. p V q
Disjunction Introduction on 1
3. p V q  s
Premise
4. s
Modus Ponens on 2 and 3
Conclusion
Still pretty easy, but not so obvious
Have to start to think about what rules to
apply that will eventually yield your
conclusion
The longer the chains of reasoning, the
trickier this can be
26
Sample proof
(1) It is not sunny this afternoon (¬ p) and it is colder
than yesterday (q). (2) We will go swimming (r) only if
it is sunny (p). (3) If we do not go swimming (¬ r),
then we will take a canoe trip (s). (4) If we take a
canoe trip (s), then we will be home by sunset (t).
Therefore, we will be home by sunset (t).
(1) ¬ p ∧ q
Attention – tricky "only if". Why isn't
(2) r  p
(2) p  r? "r only if p" says that r
cannot be true when p is not true.
(3) ¬ r  s
The statement "r only if p" is false
(4) s  t
where r is true, but p is false. Where
r is true, then so is p.
27
Sample proof
1.
2.
3.
4.
5.
6.
7.
8.
¬p∧q
¬p
rp
¬r
¬rs
s
st
t
Premise
Simplification using 1
Premise
Modus tollens using 2 and 3
Premise
Modus ponens using 4 and 5
Premise
Modus ponens using 6 and 7
Conclusion
28
Methods of proof (1)
• Logical arguments as proofs of theorems
• Common proof: establish the truth of (P  Q)
– If P is true then Q follows
– Every situation in which P is true, Q is also true
• There are standard methods of proof:
– Direct argument
– Contrapositive argument
– Proof by contradiction
29
Direct Argument (1)
• Assume P is true and show that Q is true
– This rules out situations where P is true and Q is false
P
Q (P  Q)
– Remember truth table of (P  Q)
T
T
T
T
F
F
F
T
T
F
F
T
– “in all those situations where P is true, Q is also true”
30
Direct Argument (2)
Example: show that if x and y are odd integers then xy
is also an odd integer
Solution
– If x is an odd integer then it can be written as x = 2m + 1,
for some integer m
– Likewise, y = 2n + 1, for some integer n
– Then xy = (2m + 1)(2n + 1) = 4mn + 2m + 2n + 1 =
2(2mn + m + n) + 1 = 2p + 1
– 2p + 1 is an odd integer
31
Contrapositive Argument (1)
• Assume Q is false and show that P is false
– It shows that ((not Q)  (not P)) is true
– This is the same as showing that (P  Q) is true
((not Q)  (not P))  (P  Q)
P
T
T
F
F
Q not P not Q (not Q)  (not P) P  Q
T
F
F
T
T
F
F
T
F
F
T
T
F
T
T
F
T
T
T
T
32
Contrapositive Argument (2)
Example: Let n be a positive integer. Using the
contrapositive argument, prove that if n2 is odd,
then n is odd, e.g. 32 is odd, then 3 is odd.
Solution
• “n2 is odd” is P; “n is odd” is Q
– not P (negation of “n2 is odd”) is “n2 is even”
– not Q (negation of “n is odd”) is “n is even”
• Prove “if not Q then not P”, that is, ((not Q)  (not
P)) or “if n is even then n2 is even”
• Since n is even, then n = 2m for some integer m
• Then n2 = (2m)2 = 4m2 = 2(2m2) which is even
33
Proof by Contradiction (1)
• Assume P is true and Q is false and derive a
contradiction
– This rules out the situation where P is true and Q is false
which is the only case where (P  Q) is false
P
T
T
F
F
Q (P  Q)
T
T
F
F
T
T
F
T
34
Proof by Contradiction (2)
Example: prove that if p2 is even (Q), then p is even (S)
Solution
– Assume Q is true (p2 is even) and S is false (p is not even)
– If p is not even, then it is odd, that is, p = 2n + 1, and we
have p2 = (2n + 1)2 = 4n2 + 4n + 1.
– But 4n2 + 4n = 2 (2n2 + 2n) = 2m is even, so 4n2 + 4n + 1
is odd.
– This means p2 is not even, that is, (not P) is true – a
contradiction since we assumed P is true
– Therefore our assumption that p is not even must be
wrong, i.e. p is even
35
Further Reading
• R. Haggarty. “Discrete Mathematics for
Computing”. Pearson Education Ltd.
2002. (Chapter 2)
• Wikipedia article
(http://en.wikipedia.org/wiki/Propositi
onal_calculus)
• Chapter of a book
(http://www.cis.upenn.edu/~cis510/tcl
/chap3.pdf)
36