Logic for Computer Science Handout Week 8 DERIVED RULE MODUS TOLLENS We have last week completed the introduction of a calculus, which is sound and complete. That is, we can syntactically establish the validity of a sequent H X by a natural deduction proof using the calculus rules if and only if the corresponding consequence relation H = X can be established by truth tables. Since the calculus is complete, derived rules are not necessary to prove something, but sometimes proofs can be made easier/shorter using derived rules. The first derived rule we will consider is called modus tollens. X Y Y X MT (modus tollens) This rule can derived by showing that the sequent X Y, Y X is valid. 1. X Y premise 2. Y premise 3. X assumption 4. Y e 1, 3 5. e 4, 2 6. X i 3 5 DERIVED RULE RAA RAA stands for reductio ad absurdum and means you prove a statement by assuming the opposite and bring that to a contradiction. It is a standard proof technique in mathematics. It is also called indirect proof or proof by contradiction. And can be derived by: The rule is: X. X RAA 1. X assumption.. 100. e?,? 101. X i 1 100 102. X e 101 DERIVED RULE TND The Latin name of TND is tertium non datur and in English it is called law of excluded middle. It corresponds to the semantical property that any formula X must be interpreted to either T or F, hence X X is always T. X X TND The law of the excluded middle can be proved by showing that the sequent X X is valid. c Manfred Kerber 49 Logic for Computer Science, 2005
1. (X X) assumption 2. X assumption 3. X X i 1 2 4. e 3, 1 5. X i 2 4 6. X X i 2 5 7. e 6, 1 8. (X X) i 1 7 9. X X e 8 APPLICATION OF A DERIVED RULE Prove that the sequent A B A B is valid. 1. A B premise 2. A A TND 3. A assumption 4. A B i 1 3 5. A assumption 6. B e 1, 5 7. A B i 2 6 8. A B e 2, 3 4, 5 7 SUMMARY PROPOSITIONAL LOGIC REMEMBER: Syntax, semantics, proof rules for propositional logic Expressiveness: formulae composed by connectives from atomic formulae. Concept of tautology, satisfiability, and unsatisfiability Concept of consequence relation established by truthtables. Concept of theorem as syntactic equivalent to tautology validity of sequents as syntactic equivalent to consequence relation, established by natural deduction proofs. The proof rules form a sound and complete calculus EXAMPLE HOARE LOGIC Let P be the program if (x = 0 x = 1) x = x x x else x = 0. c Manfred Kerber 50 Logic for Computer Science, 2005
( ) P ( x = 0 ) How can we establish its correctness? 1. 0 = 0 GF 2. x = 0 x x x = 0 GF 3. x = 1 x x x = 0 GF 4. x = 0 x = 1 assumption 5. x = 0 assumption 6. x x x = 0 e 5, 2 7. x = 1 assumption 8. x x x = 0 e 7, 3 9. x x x = 0 e 4, 5 6, 7 8 10. x = 0 x = 1 x x x = 0 i 4 9 11. ( x x x = 0 ) x = x x x ( x = 0 ) Assign 12. ( x = 0 x = 1 ) x = x x x ( x = 0 ) Implied 10, 11 13. (x = 0 x = 1) assumption 14. 0 = 0 weaken1 15. (x = 0 x = 1) 0 = 0 i 13 14 16. ( 0 = 0 ) x = 0 ( x = 0 ) Assign 17. ( (x = 0 x = 1) ) x = 0 ( x = 0 ) Implied16, 15 18. ( ) if (x = 0 x = 1) x = x x x else x = 0 ( x = 0 ) If 12, 17 PART III FIRST-ORDER LOGIC (ADD QUANTIFICATION ) With propositional logic we can express facts such as 0 = 0, which we needed in the proof of the validity of the Hoare triple ( ) if (x = 0 x = 1) x = x x x else x = 0 ( x = 0 ). Similarly we may need facts such as 1 = 1, 2 = 2, 3 = 3 and so on. In order to be able to be more concise we would like to say: Every number is equal to itself. Likewise we want to be able to express facts such as Every human being is mortal If the input is any pair a, b of numbers and b is not zero, then the program P computes the remainder of the division of a by b., or There is an entry x in the data base with salary(x) 50, 000. Forall x is x 0 = 0. How can we express that every member of the School of Computer Science has an e-mail address? Has email(m.kerber, M.Kerber@cs.bham.ac.uk)... c Manfred Kerber 51 Logic for Computer Science, 2005
How to express that these are all and no one is forgotten? Write: xmember(x, school of CS) ( yhas email(x,y))) Read: For every x if x is a member of the School of CS then there is a y so that x has e-mail address y. ALTERNATIVE MOTIVATION KNOWLEDGE REPRESEN- TATION How to express Everybody loves somebody? Write: x y Loves(x, y) Read: For every x there is a y such that x loves y. How to express Somebody loves everybody? Write: x y Loves(x, y) Read: There is an x such that for every y, x loves y. How to express Somebody loves somebody? Write: x y Loves(x, y) Read: There is an x such that there is a y with x loves y. How to express Everybody loves everybody? Write: x y Loves(x, y) Read: For all x and for all y holds that x loves y. SYNTAX OF FIRST-ORDER LOGIC Recall, primitive terms are variables or constant symbols. We typically denote variables by x, y, and z (or x 1, x 2, x 3,... and so on). That is we assume for the definition of a concrete logical language (pairwise disjoint sets): a set of constant symbols C (normally C non-empty) a set of variables var (this set is assumed to be infinite, since we don t want to run out of variables) a set of function symbols F a set of predicate symbols P (P non-empty) TERMS Terms are defined as follows: Any constant symbol in C is a term. Any variable in var is a term. If t 1,..., t n are terms and f F has arity n, then f(t 1,..., t n ) is a term. Nothing else is a term. Example Given: c Manfred Kerber 52 Logic for Computer Science, 2005
C = {john, mary, 1, 2, 3} F = P = {, Loves} var = {x 1, x 2, x 3, x 4,...} The only terms are john, mary, 1, 2, 3, x 1, x 2, x 3,... ATOMIC FORMULAE Atomic Formulae are defined as before: If P is a predicate symbol in P taking n arguments and t 1, t 2,..., t n are terms (generated from (C, var, F)) then P (t 1, t 2,..., t n ) is an atomic formula. Nothing else is an atomic formula. Example Loves(john, mary), Loves(x, mary), Loves(john, y),loves(x, y), Loves(father(x), mother(y)),... FORMULAE OF FIRST-ORDER LOGIC Formulae are defined as follows: Every atomic formula is a formula. (called bottom ) and (call top ) are formulae. If X and Y are formulae then ( X), (X Y), (X Y), and (X Y) are formulae. If X is a formula and z a variable then ( z X) and ( z X) are formulae. Nothing else is a formula. Example Loves(john, mary), x(loves(john, x) ( y Loves(x, y))), x y(loves(x, y) Loves(y, x)) EXAMPLES FOR FIRST-ORDER FORMULA Let be C = {john, mary}, var = {x, x 0, y,...}, F = {,, }, and P = {Loves, Human, Mortal, <}. Some formulae are: Loves(john, john) x(human(x) Mortal(x)) x y(loves(x, y) Loves(y, x)) c Manfred Kerber 53 Logic for Computer Science, 2005
x(loves(x, john) ( y Loves(y, x))) x yloves(x, y) x y z ((Loves(x, y) Loves(y, z)) ( Loves(x, z))) x1 x = x ɛ δ x x x 0 < δ f(x) f(x 0 ) < ɛ QUESTION: How do these formulae translate into English? TRANSLATE TO FIRST-ORDER LOGIC [Howard Pospesel: Arguments: 279, 291, and 293] If Sam loves everybody then Sam loves himself. If God was not created by anything then it is false that God created everything. If only doctors and hospital administrators are eligible and Mrs Miller is eligible then Mrs Miller is a doctor or a hospital administrator. You may fool all the people some of the time; you can even fool some of the people all the time; but you can t fool all of the people all the time. [Abraham Lincoln] Use P (x) standing for x is a person, T (y) for y is a moment of time, and Fool(x, y) for x can be fooled at y. Note there is an ambiguity in the sentence: You may fool all the people some of the time. There are two possible ways to interpret it: There are times when you may fool all the people. You may fool any person some of the time. What is the difference? REMEMBER: We have introduced the syntax of first-order logic and translations from natural language into first-order logic. New concept quantifiers to bind variables: (for for all, for every ) and (for there is, there is at least one, exists ) Next unit: semantics and calculus. c Manfred Kerber 54 Logic for Computer Science, 2005