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
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 Propositional Logic has Limitations 4
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 Introduce Elements of the Language 5
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 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) FOL Syntax 6 Attention - Number of parameters must match the "arity" of the predicate.
Notice that parameters can be – Variables x, y, z,... or – Constants a, b, bill, john, 2, 34, and so on – 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.... Parameters and Connectives 7 Constants are fixed in meaning.
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" Model: Bill loves Jill, The car is red. Logical Formulation: Loves(bill, jill), Black(car) Truth and Parameters 8 informal model talk, not natural language.
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))) Quantifiers 9
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. Quantifiers Evaluated 10
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)) Quantifier Interactions 11
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 Relation between Quantifiers 12
Nested quantifiers can be handled similarly: not( x( y (P(x,y)))) x(not( y (P(x,y)))) x( y(not(P(x,y)))) Relation between Quantifiers 13
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” 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” Reading (meaning of) Predicate Logic 14 ??NL and logic correlated??
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)))) Writing (meaning of) Predicate Logic 15
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: Summary About Logic 16
Proof Section Motivation: why proof is important to computing Methods of proof Return to Propositional Logic for this. Complications working with Predicate Logic. 17
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 20 This is a reasoning template called: Modus Ponens Latin for "mode that affirms"
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 22 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
A variety of reasoning templates 23 Disjunction elimination – From ¬ φ and (φ ∨ ψ), we infer ψ. Modus ponens – From φ and ( φ ψ ), we infer ψ. Modus tollens (denies by denying) – From ¬ ψ and ( φ ψ ), we infer ¬ φ. Others
How to prove 24 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.
Sample proof 25 Problem: Prove that p implies p V q 1.pPremise 2.p V qDisjunction Introduction on 1 Conclusion Easy and obvious
Sample proof 26 Problem: Prove that p and p V q s imply s 1.pPremise 2.p V qDisjunction Introduction on 1 3.p V q sPremise 4.sModus 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
Sample proof 27 (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 (2) r p (3) ¬ r s (4) s t Attention – tricky "only if". Why isn't (2) p r? "r only if p" says that r cannot be true when p is not true. The statement "r only if p" is false where r is true, but p is false. Where r is true, then so is p.
Sample proof 28 1.¬ p ∧ qPremise 2.¬ pSimplification using 1 3.r pPremise 4.¬ rModus tollens using 2 and 3 5.¬ r sPremise 6.sModus ponens using 4 and 5 7.s tPremise 8.tModus ponens using 6 and 7 Conclusion
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 – Remember truth table of (P Q) – “in all those situations where P is true, Q is also true” 30 PQ (P Q) TTT TFF FTT FFT
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 Direct Argument (2) 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) 32 PQnot Pnot Q (not Q) (not P)P Q TTFFTT TFFTFF FTTFTT FFTTTT
Example: Let n be a positive integer. Using the contrapositive argument, prove that if n 2 is odd, then n is odd, e.g. 3 2 is odd, then 3 is odd. Solution “n 2 is odd” is P; “n is odd” is Q – not P (negation of “n 2 is odd”) is “n 2 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 n 2 is even” Since n is even, then n = 2m for some integer m Then n 2 = (2m) 2 = 4m 2 = 2(2m 2 ) which is even Contrapositive Argument (2) 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 34 PQ (P Q) TTT TFF FTT FFT
Example: prove that if p 2 is even (Q), then p is even (S) Solution – Assume Q is true (p 2 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 p 2 = (2n + 1) 2 = 4n 2 + 4n + 1. – But 4n 2 + 4n = 2 (2n 2 + 2n) = 2m is even, so 4n 2 + 4n + 1 is odd. – This means p 2 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 Proof by Contradiction (2) 35
Further Reading R. Haggarty. “Discrete Mathematics for Computing”. Pearson Education Ltd (Chapter 2) Wikipedia article ( onal_calculus) onal_calculus Chapter of a book ( /chap3.pdf) /chap3.pdf 36