3: Logic
Why logic? Logic about inference or argument Start from assumptions or axioms Make deductions according to rules of reasoning Logic 3-1
Why logic? (continued) If I don t buy a lottery ticket on Saturday I won t win the jackpot. If I win the lottery jackpot on Saturday then I must have bought a ticket. If I don t buy a lottery ticket on Saturday I won t win the jackpot. So, if I buy a ticket I will win the jackpot. If it is raining then there are clouds in the sky. Today is cloudy, so it must be raining. If I don t work on this course I won t pass the exams. I m not doing a thing, I wonder what will happen? Logic 3-2
Why logic? (continued) If I don t buy a lottery ticket on Saturday I won t win the jackpot. If I win the lottery jackpot on Saturday then I must have bought a ticket. If I don t buy a lottery ticket on Saturday I won t win the jackpot. So, if I buy a ticket I will win the jackpot. If it is raining then there are clouds in the sky. Today is cloudy, so it must be raining. If I don t work on this course I won t pass the exams. I m not doing a thing, I wonder what will happen? Logic 3-2
Why logic? (continued) If I don t buy a lottery ticket on Saturday I won t win the jackpot. If I win the lottery jackpot on Saturday then I must have bought a ticket. If I don t buy a lottery ticket on Saturday I won t win the jackpot. So, if I buy a ticket I will win the jackpot. If it is raining then there are clouds in the sky. Today is cloudy, so it must be raining. If I don t work on this course I won t pass the exams. I m not doing a thing, I wonder what will happen? Logic 3-2
Why logic? (continued) If I don t buy a lottery ticket on Saturday I won t win the jackpot. If I win the lottery jackpot on Saturday then I must have bought a ticket. If I don t buy a lottery ticket on Saturday I won t win the jackpot. So, if I buy a ticket I will win the jackpot. If it is raining then there are clouds in the sky. Today is cloudy, so it must be raining. If I don t work on this course I won t pass the exams. I m not doing a thing, I wonder what will happen? Logic 3-2
Why logic? (continued) If I don t buy a lottery ticket on Saturday I won t win the jackpot. If I win the lottery jackpot on Saturday then I must have bought a ticket. If I don t buy a lottery ticket on Saturday I won t win the jackpot. So, if I buy a ticket I will win the jackpot. If it is raining then there are clouds in the sky. Today is cloudy, so it must be raining. If I don t work on this course I won t pass the exams. I m not doing a thing, I wonder what will happen? Logic 3-2
Why logic? (continued) If I don t buy a lottery ticket on Saturday I won t win the jackpot. If I win the lottery jackpot on Saturday then I must have bought a ticket. If I don t buy a lottery ticket on Saturday I won t win the jackpot. So, if I buy a ticket I will win the jackpot. If it is raining then there are clouds in the sky. Today is cloudy, so it must be raining. If I don t work on this course I won t pass the exams. I m not doing a thing, I wonder what will happen? Logic 3-2
Why logic? (continued) Can formalize the rules of reasoning used symbolic logic Helps to clarify the process of reasoning Gives possibility of mechanizing reasoning process Logic 3-3
Applications of Logic in Computer Science Programming statements like if...then...else use Boolean expressions Computer Design Logic gates used as basis of all hardware design Program Specification piece of mathematics that describes precisely the desired behaviour of a piece of software Program Verification proving that a program satisfies its specification Automated theorem proving proving that a mathematical theorem is the consequence of a number of assumptions Logic 3-4
Applications of Logic in Computer Science Programming statements like if...then...else use Boolean expressions Computer Design Logic gates used as basis of all hardware design Program Specification piece of mathematics that describes precisely the desired behaviour of a piece of software Program Verification proving that a program satisfies its specification Automated theorem proving proving that a mathematical theorem is the consequence of a number of assumptions Logic 3-4
Applications of Logic in Computer Science Programming statements like if...then...else use Boolean expressions Computer Design Logic gates used as basis of all hardware design Program Specification piece of mathematics that describes precisely the desired behaviour of a piece of software Program Verification proving that a program satisfies its specification Automated theorem proving proving that a mathematical theorem is the consequence of a number of assumptions Logic 3-4
Applications of Logic in Computer Science Programming statements like if...then...else use Boolean expressions Computer Design Logic gates used as basis of all hardware design Program Specification piece of mathematics that describes precisely the desired behaviour of a piece of software Program Verification proving that a program satisfies its specification Automated theorem proving proving that a mathematical theorem is the consequence of a number of assumptions Logic 3-4
Applications of Logic in Computer Science Programming statements like if...then...else use Boolean expressions Computer Design Logic gates used as basis of all hardware design Program Specification piece of mathematics that describes precisely the desired behaviour of a piece of software Program Verification proving that a program satisfies its specification Automated theorem proving proving that a mathematical theorem is the consequence of a number of assumptions Logic 3-4
Applications of Logic in Computer Science Data Bases need to be able to structure and efficiently execute queries Knowledge bases need to be able to make deductions from existing body of facts Semantic Web searches need to be able to search for web content by knowing something about the meaning of the content, rather than just the syntax. Logic programming can use particular forms of logic as programming languages in their own right Logic 3-5
Applications of Logic in Computer Science Data Bases need to be able to structure and efficiently execute queries Knowledge bases need to be able to make deductions from existing body of facts Semantic Web searches need to be able to search for web content by knowing something about the meaning of the content, rather than just the syntax. Logic programming can use particular forms of logic as programming languages in their own right Logic 3-5
Applications of Logic in Computer Science Data Bases need to be able to structure and efficiently execute queries Knowledge bases need to be able to make deductions from existing body of facts Semantic Web searches need to be able to search for web content by knowing something about the meaning of the content, rather than just the syntax. Logic programming can use particular forms of logic as programming languages in their own right Logic 3-5
Applications of Logic in Computer Science Data Bases need to be able to structure and efficiently execute queries Knowledge bases need to be able to make deductions from existing body of facts Semantic Web searches need to be able to search for web content by knowing something about the meaning of the content, rather than just the syntax. Logic programming can use particular forms of logic as programming languages in their own right Logic 3-5
Symbolic logic Simplest form is concerned with propositions Statements that can take value true or false Blue is a colour 1 + 1 = 2 2 + 2 = 22 All computer scientists have beards Logic 3-6
Symbolic logic Simplest form is concerned with propositions Statements that can take value true or false Blue is a colour 1 + 1 = 2 2 + 2 = 22 All computer scientists have beards Logic 3-6
Symbolic logic Simplest form is concerned with propositions Statements that can take value true or false Blue is a colour 1 + 1 = 2 2 + 2 = 22 All computer scientists have beards Logic 3-6
Symbolic logic Simplest form is concerned with propositions Statements that can take value true or false Blue is a colour 1 + 1 = 2 2 + 2 = 22 All computer scientists have beards Logic 3-6
Symbolic logic (continued) The following are not propositions 42 Is it raining? Manchester United Logic 3-7
Symbolic logic (continued) The following are not propositions 42 Is it raining? Manchester United Logic 3-7
Symbolic logic (continued) The following are not propositions 42 Is it raining? Manchester United Logic 3-7
Symbolic logic (continued) Can form compound propositions using logical connectives (or operators) Today is Wednesday and it s raining Either this is Manchester or I m a Dutchman If it s Wednesday at 11 this must be CS1021 Logic 3-8
Symbolic logic (continued) Can form compound propositions using logical connectives (or operators) Today is Wednesday and it s raining Either this is Manchester or I m a Dutchman If it s Wednesday at 11 this must be CS1021 Logic 3-8
Symbolic logic (continued) Can form compound propositions using logical connectives (or operators) Today is Wednesday and it s raining Either this is Manchester or I m a Dutchman If it s Wednesday at 11 this must be CS1021 Logic 3-8
Symbolic logic (continued) Can form compound propositions using logical connectives (or operators) Today is Wednesday and it s raining Either this is Manchester or I m a Dutchman If it s Wednesday at 11 this must be CS1021 Will introduce the full range of logical connectives and study their properties. Logic 3-9
The Logical Connectives name symbol translation negation not conjunction and disjunction or implication implies bi-implication iff and are often used instead of and. - unary - prefix p, q others - binary - infix (p q) Logic 3-10
The Logical Connectives (continued) - and, but - inclusive or some English translations of A B. A implies B If A then B A only if B B if A A is a sufficient case for B B is necessary for A - if and only if, abbreviated to iff. Logic 3-11
The Logical Connectives (continued) - and, but - inclusive or some English translations of A B. A implies B If A then B A only if B B if A A is a sufficient case for B B is necessary for A - if and only if, abbreviated to iff. Logic 3-11
The Logical Connectives (continued) - and, but - inclusive or some English translations of A B. A implies B If A then B A only if B B if A A is a sufficient case for B B is necessary for A - if and only if, abbreviated to iff. Logic 3-11
The Logical Connectives (continued) - and, but - inclusive or some English translations of A B. A implies B If A then B A only if B B if A A is a sufficient case for B B is necessary for A - if and only if, abbreviated to iff. Logic 3-11
The Logical Connectives (continued) - and, but - inclusive or some English translations of A B. A implies B If A then B A only if B B if A A is a sufficient case for B B is necessary for A - if and only if, abbreviated to iff. Logic 3-11
Truth Tables Negation p p T F F T Logic 3-12
Truth Tables (continued) p 1 p 2 p 1 p 2 p 1 p 2 p 1 p 2 p 1 p 2 T T T T T T T F F T F F F T F T T F F F F F T T Logic 3-13
Why the table for? x > 3 implies x > 1 where x is an integer variable. Surely this sentence is universally true; i.e. it is true whatever integer value x may have. Now let us give x the values 4,2,0 in turn x x > 3 x > 1 x > 3 x > 1 4 T T T 2 F T T 0 F F T Logic 3-14
Some properties p 1 p 2 p 1 p 2 p 1 p 2 p 2 p 1 p 2 p 1 T T T T T T T F F T F T F T F T F T F F F F F F Both and are commutative They are also associative (p 1 p 2 ) p 3 = p 1 (p 2 p 3 ) Logic 3-15
Formulae Propositions denoted by names such as p,q, p 3,r 7 1. Every proposition is a formula (in fact an atomic formula). 2. If A is a formula then so is A. 3. If A,B are formulae then so are (A B),(A B),(A B) and (A B). Another formal language. Language PL of Propositional Logic Logic 3-16
Formulae (continued) ((p 1 p 2 ) ( p 3 p 4 )) has parse tree p 1 (p 1 p 2 ) p 2 ( ) p 3 ( ) p 3 p 4 ( ) ( p 3 p 4 ) ( ) ((p 1 p 2 ) ( p 3 p 4 )) ( ) ((p 1 p 2 ) ( p 3 p 4 )) Logic 3-17
Formulae (continued) or p 1. p 2 ( ).. p 3 ( ). p 4 ( ) ( ). ( ) Logic 3-18
Some syntactic conventions 1. When using formulae it is standard practice to leave off the outermost parentheses. 2. Leave out internal parentheses from repeated use of and repeated use of. e.g. p q abbreviates (p q) (p q (q r)) p abbreviates (((p q) (q r)) p). Logic 3-19
Truth Valuations Let p 1,..., p n be a list of n distinct atomic formulae. A truth valuation for the list is an allocation of a truth value x i to each p i in the list. (p 1 = x 1,..., p n = x n ) e.g. (p = T,q = F,r = F) is a truth valuation for p,q,r. Logic 3-20
Truth Valuations (continued) Can also think of a truth valuation as a function {p 1, p 2,... p n } {T,F} If all the atomic formulae occurring in a formula A are in the list p 1,... p n. Then given a truth valuation for the list, A can be evaluated. Logic 3-21
Truth Valuations (continued) This truth value is determined following the way the formula has been built up, using the truth tables for the connectives that are involved. If the formula is atomic then the truth valuation itself determines its truth value. For a compound (i.e. non-atomic) formula the truth value can be found using the truth tables for the connectives. Logic 3-22
Truth Valuations (continued) e.g. at the valuation (p = T,q = F,r = F) p q is F, (p q) r is T, ((p q) r) is F. Logic 3-23
Truth Valuations (continued) Instead of the truth tables truth schemes can be used. In each scheme the compound formula gets the truth value false if it is not true. Truth scheme just a description of the corresponding truth table. Logic 3-24
The Truth Schemes Negation Conjunction Disjunction Implication A is true iff A is false. A 1 A 2 is true iff both A 1,A 2 are true. A 1 A 2 is true iff at least one of A 1,A 2 are true. A 1 A 2 is true iff either A 1 is false or A 2 is true (or both). Bi-implication A 1 A 2 is true iff A 1,A 2 have the same truth value. Logic 3-25
Tautologies and Contradictions Let A be a formula and let p 1,..., p n be a list of atomic formulae that include all those occurring in A. Then A is a tautology if it evaluates to T in every truth valuation for the list. A is contradictory if it is always false; i.e. it gets the truth value F at every truth valuation for the list p 1,..., p n. Logic 3-26
Tautologies and Contradictions Let A be a formula and let p 1,..., p n be a list of atomic formulae that include all those occurring in A. Then A is a tautology if it evaluates to T in every truth valuation for the list. A is contradictory if it is always false; i.e. it gets the truth value F at every truth valuation for the list p 1,..., p n. Logic 3-26
Tautologies and Contradictions (continued) e.g. let p be an atomic formula. Then p p is a tautology. p p is contradictory. p p p p p p T F F T F T F T Logic 3-27
Tautologies and Contradictions (continued) If a formula is not contradictory then that means that it must be true at some truth valuations. We then sometimes write that the formula is satisfiable. For example p q is satisfiable Logic 3-28
Truth Tables p 1 p 2 p 3 p 1 p 2 p 3 p 1 (p 2 p 3 ) T T T F T T T T F F F F T F T F F F T F F F F F F T T T T T F T F T F T F F T T F T F F F T F T p 1 (p 2 p 3 ) is not a tautology. It is satisfiable. Logic 3-29
Logical Equivalence Two formulae, A,B, are logically equivalent if they have the same truth value at every truth valuation for any list of atomic formulae that includes those occurring in either A or B; i.e. A,B have the same truth tables. Logic 3-30
Logical Equivalence (continued) For example: p 1 p 2 p 1 p 1 p 2 p 1 p 2 T T F T T T F F F F F T T T T F F T T T So p 1 p 2 is logically equivalent to p 1 p 2. Logic 3-31
Notation: Write = A for A is a tautology. A is contradictory iff = A. A is satisfiable iff = A. Write A == B for A is logically equivalent to B. A == B iff = A B. Logic 3-32
Commutativity Logical Equivalence Laws A 1 A 2 == A 2 A 1 Associativity A 1 A 2 == A 2 A 1 A 1 (A 2 A 3 ) == (A 1 A 2 ) A 3 Distributivity A 1 (A 2 A 3 ) == (A 1 A 2 ) A 3 A (B 1 B 2 ) == (A B 1 ) (A B 2 ) A (B 1 B 2 ) == (A B 1 ) (A B 2 ) (B 1 B 2 ) A == (B 1 A) (B 2 A) Logic 3-33
Idempotency (B 1 B 2 ) A == (B 1 A) (B 2 A) A A == A Absorbtion A A == A Double Negation (Involution) A (A B) == A A (A B) == A A == A Logic 3-34
De Morgan (A 1 A 2 ) == A 1 A 2 (A 1 A 2 ) == A 1 A 2 A 1 A 2 == ( A 1 A 2 ) Redundancy If = B and = C then A 1 A 2 == ( A 1 A 2 ) A B == A A C == A Logic 3-35
Implication A B == A B (A B) == A B A B == B A A B == B A Logic 3-36
Bi-implication A B == (A B) (B A) A B == ( A B) ( B A) A B == (A B) ( A B) (A B) == (A B) (B A) (A B) == (A B) (A B) Logic 3-37
Logical Equivalence Laws (continued) Any of the above can be checked using truth tables. For example A (B 1 B 2 ) == (A B 1 ) (A B 2 ) A B 1 B 2 B 1 B 2 A (B 1 B 2 ) A B 1 A B 2 (A B 1 ) (A B 2 ) T T T T T F T F T T F F F T T F T F F F T F F F Logic 3-38
Implication A B == B A This equivalence is one we use often in everyday reasoning If we know that a implies b, and we also know that b is false, then we can deduce the fact that a must be false as well B A is called the contrapositive of A B Logic 3-39
Normal Forms Can simplify a formula to produce an equivalent formula in some standard (or normal form) There are three useful kinds of normal form for propositional logic, NNF, CNF and DNF. We will describe algorithms which, for any formula A, find a formula A, in the normal form, such that A == A. Logic 3-40
Negation Normal Form (NNF) A formula that is either atomic or is the negation of an atomic formula is called a literal; e.g. if p is an atomic formula (proposition) then both p and p are literals. A formula is in Negation Normal Form, abbreviated NNF, if it is built up from literals using only conjunction and disjunction. So (( p 1 p 2 ) p 3 ) p 2 is in NNF, (p 1 p 2 ) p 3 is NOT in NNF Logic 3-41
Negation Normal Form (NNF) (continued) Every formula of PL is logically equivalent to a formula in NNF. To produce the NNF formula carry out the following procedures:- 1. Eliminate connectives, from the formula, using the two laws A B == A B, A B == ( A B) ( B A). Logic 3-42
Negation Normal Form (NNF) (continued) 2. The resulting formula will be built up using only,,. May still not be in NNF because negation may be applied to a non-literal; i.e. there may be occurrences of formulae having one of the forms A, (A 1 A 2 ), (A 1 A 2 ). In the first case the double negation can be eliminated using the double negation law A == A In other two cases the negation can be driven inside the binary connective using the two De Morgan Laws (A 1 A 2 ) == A 1 A 2, (A 1 A 2 ) == A 1 A 2. Repeat these steps until we have a formula in NNF. Logic 3-43
1. Examples == == == ((p 1 p 2 ) p 3 }{{} ) ( (p 1 p 2 ) p 3 ) (p 1 p 2 ) }{{} p 3 (p 1 p 2 ) p 3 Logic 3-44
2. == == == == ((p 2 p 1 ) }{{} p 3) (( p 2 p 1 ) p 3 ) ( p 2 p 1 ) }{{} p 3 }{{} ( p 2 }{{} p 1) p 3 (p 2 p 1 ) p 3 Logic 3-45
Conjunctive Normal Form (CNF) A (disjunctive) clause is a disjunction of one or more literals. For example p p q p q p 1 p 2 p 3 p 4 A formula is in Conjunctive Normal Form, abbreviated CNF, if it is a conjunction of clauses; Logic 3-46
Examples 1. p 1 p 2 2. (p 2 p 3 ) ( p 1 p 3 ) 3. (p 1 p 2 p 1 ) (p 2 p 3 p 1 ) 4. p 1 p 2 p 3 Logic 3-47
Examples (continued) Every formula of PL is logically equivalent to a formula in CNF. First put the formula in NNF. If the resulting formula is not in CNF then repeatedly use the following procedures until a formula in CNF is eventually obtained:- 1. Get rid of inner parentheses from repeated conjunctions and disjunctions, using the laws (A 1 A n ) A == A 1 A n A, A (A 1 A n ) == A A 1 A n, (A 1 A n ) A == A 1 A n A, A (A 1 A n ) == A A 1 A n, Logic 3-48
Examples (continued) 2. Bring disjunctions inside conjunctions using the distributivity laws (A 1 A n ) A == (A 1 A) (A n A), A (A 1 A n ) == (A A 1 ) (A A n ), where n 2. Logic 3-49
Example Put ((p 2 p 1 ) p 3 ) in CNF. ((p 2 p 1 ) }{{} p 3) == (by example 2 of 3.1) (p 2 p 1 ) p 3 == (by distributivity) (p 2 p 3 ) ( p 1 p 3 ) Logic 3-50
CNF test for tautologies The only way that a clause can be a tautology is if one of the literals in the clause is the negation of another literal in the clause. So, for example, p 1 p 2 p 1 p 3 is a clause that is a tautology, but p 1 p 2 p 3 is not a tautology because it is false at the valuation (p 1 = T, p 2 = F, p 3 = F). Also, a conjunction is a tautology exactly when all the conjuncts are tautologies. Logic 3-51
CNF test for tautologies (continued) For example (p 1 p 3 p 4 p 3 ) ( p 4 p 3 p 1 ) (p 2 p 1 p 2 p 1 ) is not a tautology because the second clause p 4 p 3 p 1 does not have a literal and its negation. Logic 3-52
Disjunctive Normal Form (DNF) Disjunctive Normal Form (DNF) is defined just like CNF except that the roles of conjunction and disjunction are interchanged. A formula is a conjunctive clause if it is a conjunction of one or more literals A formula is in disjunctive normal form (DNF) if it is a disjunction of one or more conjunctive clauses. The method we have described for putting a formula in CNF also applies for putting a formula in DNF, provided that we interchange the roles of and. Logic 3-53
Disjunctive Normal Form (DNF) (continued) Corresponding to the CNF test for tautologies we get the following DNF test for contradictions:- To test a formula in DNF for being contradictory check that for each conjunctive clause in the formula there is an occurrence of a literal and its negation. For example the DNF formula is easily seen to be contradictory. (p 3 p 4 p 3 ) (p 1 p 1 ) Logic 3-54
Functional Completeness In this section we discuss the possibility of other connectives than the particular connectives we have been considering. Perhaps there are missing connectives that could be added to Propositional Logic to get a more expressive Logic. (What does expressive mean?) We will show that in a precise sense that is not the case - Propositional Logic is Functionally Complete. Logic 3-55
Functional Completeness (continued) A connective can be specified by giving a truth table that spells out how the truth value of a formula built with the connective depends on the truth values of its components. For example consider a new binary connective #. We specify the connective using a truth table. For example:- So we have the truth scheme:- p 1 p 2 p 1 # p 2 T T F T F T F T T F F F A 1 # A 2 is true iff exactly one of A 1,A 2 is true and the other is false. Logic 3-56
Functional Completeness (continued) You may already have noticed that the formula (p 1 p 2 ) has the same truth table as the above table for p 1 # p 2 ; So the two formulae are logically equivalent This means that # is redundant - the occurrences of # in a formula can be systematically eliminated using the logical equivalence. Logic 3-57
Functional Completeness (continued) There is a systematic way to find, given any truth table, a formula in DNF having that truth table. Suppose the truth table involves the atomic formulae p 1,..., p n We may associate a conjunctive clause l 1 l n with any row of the truth table, where l i is p i if p i is T in that row and p i if p i is F in that row. Now let A be the disjunction of those conjunctive clauses corresponding to the rows where the truth table gives the value T in the right hand column. It should be obvious that the truth table of A is exactly the truth table we started with. In the case of the truth table for # we would get the DNF formula (p 1 p 2 ) ( p 1 p 2 ). Logic 3-58
Example Find a formula A in DNF whose truth table is:- p 1 p 2 p 3 A T T T F T T F T T F T T T F F F F T T F F T F F F F T F F F F T Logic 3-59
Example Find a formula A in DNF whose truth table is:- p 1 p 2 p 3 A T T T F T T F T p 1 p 2 p 3 T F T T T F F F F T T F F T F F F F T F F F F T Logic 3-59
Example Find a formula A in DNF whose truth table is:- p 1 p 2 p 3 A T T T F T T F T p 1 p 2 p 3 T F T T p 1 p 2 p 3 T F F F F T T F F T F F F F T F F F F T Logic 3-59
Example Find a formula A in DNF whose truth table is:- p 1 p 2 p 3 A T T T F T T F T p 1 p 2 p 3 T F T T p 1 p 2 p 3 T F F F F T T F F T F F F F T F F F F T p 1 p 2 p 3 Logic 3-59
Example (continued) There are three rows of this table which have T under A and these determine the conjunctive clauses p 1 p 2 p 3, p 1 p 2 p 3 and p 1 p 2 p 3. The formula A that we want is their disjunction:- (p 1 p 2 p 3 ) (p 1 p 2 p 3 ) ( p 1 p 2 p 3 ). Logic 3-60
Example (continued) So, for every possible truth table there is a formula having that truth table. Moreover that formula can be in DNF So it only involves the connectives,,. We say that {,, } is a functionally complete set of connectives. There is no truth table which can not be expressed as a formula involving only these connectives. Logic 3-61
Example (continued) In fact there is still some redundancy because only one of, is needed together with. This is because the De Morgan Laws allow one of them to be defined in terms of the other. For example, because of the law A B == ( A B), all the occurrences of in a formula in DNF can be systematically eliminated so as to get a logically equivalent formula involving only the connectives,. Logic 3-62
Example (continued) For example we have:- == (p 1 p 2 ) }{{} ( p 1 p 2 ) }{{} ( p 1 p 2 ) (p 1 p 2 ) Logic 3-63
Predicates and Quantifiers One of the limitations of propositional calculus is that it has no way of handling arguments such as the following All computer science students are witty and intelligent. Eve is a computer science student. Therefore Eve is witty and intelligent. Logic 3-64
Predicates and Quantifiers (continued) We can identify the three propositions here p q r All computer science students are witty and intelligent Eve is a computer science student Eve is witty and intelligent. We want to argue that p q r, but have no way of formalising the fact that q and r are both statements about the same individual. Logic 3-65
Predicates and Quantifiers (continued) To do this we need to introduce the notion of a predicate. A predicate is just a boolean valued function. In the above example we have two such predicates CS(x) W(x) x is a computer science student x is witty and intelligent The above argument can then be recast as For all x CS(x) W(x) CS(Eve) Therefore W(Eve) Logic 3-66
Quantifiers Given a predicate P, there are two ways of obtaining a truth value, Can apply predicate to a a particular individual (for example CS(Eve) above) Can also quantify it. Logic 3-67
Quantifiers (continued) Given a predicate P, we can assert that P(x) is true whatever the value of x. For all x, I(x). This statement has one of the values true or false, and does not depend on a particular value of x. The predicate has been universally quantified, by the use of the word For all. Logic 3-68
Quantifiers (continued) The universal quantifier is denoted symbolically by the symbol, Write things like x, P(x). The argument regarding CS students becomes x,cs(x) W(x) CS(Eve) Therefore W(Eve) Logic 3-69
Quantifiers (continued) Can also use existential quantification In English usually done using phrases such as there exists or for some. Write this symbolically as, x,p(x), read as there exists a value for x such that P(x) is true. Logic 3-70
Quantifiers (continued) If CS and W are the predicates as above, note the difference between the following statements. x CS(x) W(x) x CS(x) W(x) x CS(x) W(x) x W(x) CS(x) Logic 3-71
Quantifiers (continued) Predicates can involve more than one variable, and statements can be built using more than one quantifier, for example Every dog has its day can be written x Dog(x) d HasDay(x, d) Logic 3-72
Quantifiers (continued) and There is someone in this room who is at least as tall as anyone else in the room x InRoom(x) ( y InRoom(y) AsTallAs(x, y)) Logic 3-73
Quantifiers (continued) What about the following? x InRoom(x) ( y InRoom(y) AsTallAs(x, y)) Logic 3-74
Quantifiers (continued) The predicates F and O are defined by F(x) iff x is a Unix file O(x,y) iff x is the owner of y Explain in English the meaning of the following statements i) x (F(x) y O(y,x)) ii) x ( y (F(y) O(x,y))) iii) x (F(x) ( y z (O(y,x) O(z,x) y = z))) Which, if any, of these statements do you think are true? Give reasons Logic 3-75
Quantifiers (continued) In the design specification for a library system, B(p, b) denotes the predicate person p has borrowed book b and O(b) denotes the book b is overdue. Write the following sentences in symbolic form:- Person p 1 has borrowed at least one book. Logic 3-76
Quantifiers (continued) In the design specification for a library system, B(p, b) denotes the predicate person p has borrowed book b and O(b) denotes the book b is overdue. Write the following sentences in symbolic form:- Person p 1 has borrowed at least one book. b B(p 1,b) Logic 3-76
Quantifiers (continued) In the design specification for a library system, B(p, b) denotes the predicate person p has borrowed book b and O(b) denotes the book b is overdue. Write the following sentences in symbolic form:- Person p 1 has borrowed at least one book. b B(p 1,b) Book b 1 has been borrowed. Logic 3-76
Quantifiers (continued) In the design specification for a library system, B(p, b) denotes the predicate person p has borrowed book b and O(b) denotes the book b is overdue. Write the following sentences in symbolic form:- Person p 1 has borrowed at least one book. b B(p 1,b) Book b 1 has been borrowed. p B(p,b 1 ) Logic 3-76
Quantifiers (continued) In the design specification for a library system, B(p, b) denotes the predicate person p has borrowed book b and O(b) denotes the book b is overdue. Write the following sentences in symbolic form:- Person p 1 has borrowed at least one book. b B(p 1,b) Book b 1 has been borrowed. p B(p,b 1 ) Person p 2 has borrowed at least two books. Logic 3-76
Quantifiers (continued) In the design specification for a library system, B(p, b) denotes the predicate person p has borrowed book b and O(b) denotes the book b is overdue. Write the following sentences in symbolic form:- Person p 1 has borrowed at least one book. b B(p 1,b) Book b 1 has been borrowed. p B(p,b 1 ) Person p 2 has borrowed at least two books. b 1,b 2 (B(p 2,b 1 ) B(p 2,b 2 ) b 1 b 2 ) Logic 3-76
Quantifiers (continued) In the design specification for a library system, B(p, b) denotes the predicate person p has borrowed book b and O(b) denotes the book b is overdue. Write the following sentences in symbolic form:- Person p 1 has borrowed at least one book. b B(p 1,b) Book b 1 has been borrowed. p B(p,b 1 ) Person p 2 has borrowed at least two books. b 1,b 2 (B(p 2,b 1 ) B(p 2,b 2 ) b 1 b 2 ) No book has been borrowed by more than one person. Logic 3-76
Quantifiers (continued) In the design specification for a library system, B(p, b) denotes the predicate person p has borrowed book b and O(b) denotes the book b is overdue. Write the following sentences in symbolic form:- Person p 1 has borrowed at least one book. b B(p 1,b) Book b 1 has been borrowed. p B(p,b 1 ) Person p 2 has borrowed at least two books. b 1,b 2 (B(p 2,b 1 ) B(p 2,b 2 ) b 1 b 2 ) No book has been borrowed by more than one person. b p 1, p 2 (B(p 1,b) B(p 2,b) p 1 p 2 ) Logic 3-76
Quantifiers (continued) In the design specification for a library system, B(p, b) denotes the predicate person p has borrowed book b and O(b) denotes the book b is overdue. Write the following sentences in symbolic form:- Person p 1 has borrowed at least one book. b B(p 1,b) Book b 1 has been borrowed. p B(p,b 1 ) Person p 2 has borrowed at least two books. b 1,b 2 (B(p 2,b 1 ) B(p 2,b 2 ) b 1 b 2 ) No book has been borrowed by more than one person. b p 1, p 2 (B(p 1,b) B(p 2,b) p 1 p 2 ) If a book is overdue, then it must have been borrowed. Logic 3-76
Quantifiers (continued) In the design specification for a library system, B(p, b) denotes the predicate person p has borrowed book b and O(b) denotes the book b is overdue. Write the following sentences in symbolic form:- Person p 1 has borrowed at least one book. b B(p 1,b) Book b 1 has been borrowed. p B(p,b 1 ) Person p 2 has borrowed at least two books. b 1,b 2 (B(p 2,b 1 ) B(p 2,b 2 ) b 1 b 2 ) No book has been borrowed by more than one person. b p 1, p 2 (B(p 1,b) B(p 2,b) p 1 p 2 ) If a book is overdue, then it must have been borrowed. b O(b) ( p B(p, b)) Logic 3-76
Negation of quantified statements If P is some predicate, then the expression x P(x), says that it is not the case that all x have the property described by P. This means that there must be at least one individual a, say, for which it is the case that P(a), is true. In other words x P(x). So negation turns the universal quantifier into the existential, and we have ( x P(x)) == ( x P(x)) Logic 3-77
Negation of quantified statements (continued) Similarly we have ( x P(x)) == ( x P(x)) If there is no x for which P(x) is true, it must be the case that, for all x, P(x) is true. Logic 3-78
Negation of quantified statements (continued) These rules of negation are an extension of the de Morgan Laws of propositional logic. How? Logic 3-79
Negation of quantified statements (continued) If X is a finite set {x 1,x 2,...x n } the statement x X p(x) can be rewritten as and can be rewritten as p(x 1 ) p(x 2 )... p(x n ) x X p(x) p(x 1 ) p(x 2 )... p(x n ) Logic 3-80
Some examples If CS and W are the predicates as above, x CS(x) W(x) All CS students are witty and intelligent x CS(x) W(x) There is a witty and intelligent CS student x W(x) CS(x) All witty and intelligent people are CS students We will construct the negations of these Logic 3-81
Some examples (continued) x CS(x) W(x) = x (CS(x) W(x)) = x CS(x) W(x)) Logic 3-82
Some examples (continued) x CS(x) W(x) = x (CS(x) W(x)) = x CS(x) W(x)) There is a CS student who is not witty and intlligent Logic 3-83
Some examples (continued) x CS(x) W(x) = x (CS(x) W(x)) = x CS(x) W(x) = x CS(x) W(x) = x CS(x) W(x) Logic 3-84
Some examples (continued) x CS(x) W(x) = x (CS(x) W(x)) = x CS(x) W(x) = x CS(x) W(x) = x CS(x) W(x) All CS students are not witty and intelligent Logic 3-85
Some examples (continued) x W(x) CS(x) = x (W(x) CS(x)) = x (W(x) CS(x)) Logic 3-86
Some examples (continued) x W(x) CS(x) = x (W(x) CS(x)) = x (W(x) CS(x)) There is someone who is not a CS student who is witty and intelligent Logic 3-87
Some examples (continued) The statement No book has been borrowed by more than one person can be rewritten as b p 1, p 2 (B(p 1,b) B(p 2,b) p 1 p 2 ) b p 1, p 2 (B(p 1,b) B(p 2,b) p 1 p 2 ) = b p 1, p 2 (B(p 1,b) B(p 2,b) p 1 p 2 ) = b p 1, p 2 ( B(p 1,b) B(p 2,b) p 1 = p 2 ) = b p 1, p 2 ((B(p 1,b) B(p 2,b)) p 1 = p 2 ) Logic 3-88
The statement No book has been borrowed by more than one person Some examples (continued) can be rewritten as b p 1, p 2 (B(p 1,b) B(p 2,b) p 1 p 2 ) b p 1, p 2 (B(p 1,b) B(p 2,b) p 1 p 2 ) = b p 1, p 2 (B(p 1,b) B(p 2,b) p 1 p 2 ) = b p 1, p 2 ( B(p 1,b) B(p 2,b) p 1 = p 2 ) = b p 1, p 2 ((B(p 1,b) B(p 2,b)) p 1 = p 2 ) If two people have borrowed the same book, then they must have been the same person Logic 3-89
Some examples (continued) There is someone in this room who is at least as tall as anyone else in the room if we negate this statement, we get There is not someone in this room who is at least as tall as anyone else in the room Symbolically this becomes ( x InRoom(x) ( y InRoom(y) AsTallAs(x, y))) which can be rewritten as Logic 3-90
Some examples (continued) x (InRoom(x) ( y InRoom(y) AsTallAs(x, y))) = x (InRoom(x) ( y InRoom(y) AsTallAs(x, y))) = x( InRoom(x) ( y InRoom(y) AsTallAs(x, y))) = x( InRoom(x) ( y (InRoom(y) AsTallAs(x, y)))) = x( InRoom(x) ( y InRoom(y) AsTallAs(x, y))) = x(inroom(x) ( y InRoom(y) AsTallAs(x, y))) which in English is For everyone in the room there is someone in the room who they are not as tall as. Logic 3-91