Predicate Logic Predicate Logic (Rosen, Chapter 1.4-1.6) TOPICS Predicate Logic Quantifiers Logical Equivalence Predicate Proofs Some statements cannot be expressed in propositional logic, such as: All men are mortal. Some trees have needles. X > 3. Predicate logic can express these statements and make inferences on them. 10/1/12 CS160 Fall Semester 2012 2 P(x,y) Statements in Predicate Logic Two parts: Predicate P describes a relation or property, Variables (x,y) can take arbitrary values from some domain. Still have two truth values for statements (T and F) When we assign values to x and y, then P has a truth value. 10/1/12 CS160 Fall Semester 2012 3 Example Let Q(x,y) denote x=y+3. What are truth values of: Q(1,2) Q(3,0) Let R(x,y) denote x beats y in Rock/Paper/Scissors with 2 players with following rules: Rock smashes scissors, Scissors cuts paper, Paper covers rock. What are the truth values of: R(rock, paper) R(scissors, paper) false true false 10/1/12 CS160 Fall Semester 2012 4 true 1
Why is Predicate Logic Useful? Verifying Program Correctness Given if (x<0) x = -x; What is true before? (called precondition) x has some value What is true after? (called postcondition) greaterthan(x,0) Systems Specifications E.g., Every mail message larger than one megabyte will be compressed. Check Let Q(x,y) denote the statement x is the capital of y What are the truth values of the following Q(Denver, Colorado) A True, B - False Q(Detroit, Michigan) A True, B False Q(Los Angeles, California) A True, B - False 10/1/12 CS160 Fall Semester 2012 5 10/1/12 CS160 Fall Semester 2012 6 Quantifiers Quantification expresses the extent to which a predicate is true over a set of elements. Two forms: Universal Existential Universal Quantifier P(x) is true for all values in the domain x D, P(x) For every x in D, P(x) is true. An element x for which P(x) is false is called a counterexample. Given P(x) as x+1>x and the domain of R, what is the truth value of: x P(x) true 10/1/12 CS160 Fall Semester 2012 7 10/1/12 CS160 Fall Semester 2012 8 2
Check Let C(x) denote x is a comedian. Let F(x) denote x is funny. The domain of x is all people Given x(c(x) -> F(x)) A. There exists an x such that x is a comedian and x is funny B. Every person is a funny comedian Example Let P(x) be that x>0 and x is in domain of R. Give a counterexample for: x P(x) x = -5 10/1/12 CS160 Fall Semester 2012 9 10/1/12 CS160 Fall Semester 2012 10 Existential Quantifier P(x) is true for at least one value in the domain. x D, P(x) For some x in D, P(x) is true. Let the domain of x be animals, M(x) be x is a mammal and E(x) be x lays eggs, what is the truth value of: x (M(x) E(x)) true Platypuses echidnas English to Logic Some person in this class has visited the Grand Canyon. Domain of x is the set of all persons C(x): x is a person in this class V(x): x has visited the Grand Canyon x(c(x) V(x)) 10/1/12 CS160 Fall Semester 2012 11 10/1/12 CS160 Fall Semester 2012 12 3
Hmm. 10/1/12 CS160 Fall Semester 2012 13 English to Logic For every one there is someone to love. Domain of x and y is the set of all persons L(x, y): x loves y x y L(x,y) Is it necessary to explicitly include that x and y must be different people (i.e. x y)? Just because x and y are different variable names doesn t mean that they can t take the same values 10/1/12 CS160 Fall Semester 2012 14 English to Logic No one in this class is wearing shorts and a ski parka. Domain of x is persons in this class S(x): x is wearing shorts P(x): x is wearing a ski parka x(s(x) P(x)) Domain of x is all persons C(x): x belongs to the class x(c(x) S(x) P(x)) 10/1/12 CS160 Fall Semester 2012 15 Check Let P(x) denote x can speak French. Let Q(x) denote x can speak German. The domain of x is the students in this class There is a student in this class that can speak French and German A. x (P(x) v Q(x)) B. x(p(x) ^ Q(x)) C. x (P(x) ^ Q(x)) 10/1/12 CS160 Fall Semester 2012 16 4
Evaluating Expressions: Precedence and Variable Bindings Precedence: Quantifiers and negation are evaluated before operators Otherwise left to right Bound: Variables can be given specific values or Can be constrained by quantifiers How about Predicate Proofs? How do we formally prove a theorem about quantified predicates? The canonical example: All people are mortal. Socrates is a person. Prove that Socrates is mortal 10/1/12 CS160 Fall Semester 2012 17 10/1/12 CS160 Fall Semester 2012 18 Inference over Predicates A predicate applied to constants is equivalent to a Proposition Let the domain of discourse be tree types Let P(x) x has needles Then P(pine) is T Then P(palm) is T Therefore, all the propositional inference rules apply to predicates of constants! 10/1/12 CS160 Fall Semester 2012 19 What about quantifiers? Unfortunately, many predicate statements involve quantified variables In English: All people are mortal In predicate logic: x, P(x) M(x) We introduce four new rules to handle quantified variables: Universal instantiation (UI) Universal generalization (UG) Existential instantiation (EI) Existential generalization (EG) We will take these one at a time 10/1/12 CS160 Fall Semester 2012 20 5
Universal Instantiation x P(x) P(c) Rationale: if something is true for every element in the domain, then it is true for any element (use a constant for the element). Use: we can substitute any constant for any universally quantified variable in any propositional statement. 10/1/12 CS160 Fall Semester 2012 21 UI Example All people are mortal; Sue is a person; Show that Sue is mortal 1 x P(x) M(x) Premise 2 P(Sue) Premise 3 P(Sue) M(Sue) UI (1) 4 M(Sue) Modus Ponens, (2) & (3) 10/1/12 CS160 Fall Semester 2012 22 Existential Generalization (EG) P(c) x P(x) Rationale: if something is true for one thing (the constant), then it is true for something Use: we can replace constants with existentially quantified variables. EG Example Everyone is mortal. Show that someone is mortal 1 x M(x) Premise 2 M(sue) UI (1) 3 x M(x) EG (2) 10/1/12 CS160 Fall Semester 2012 23 10/1/12 CS160 Fall Semester 2012 24 6
Existential Instantiation (EI) x P(x) P(c) Rationale: if a statement is true for something, then call that something c. The constant c must be new (never before used). Use: we can replace existentially quantified variables with constants (even though we don t know their names). 10/1/12 CS160 Fall Semester 2012 25 EI Example All people are mortal. People (a person) exist. Show that something is mortal. 1 x P(x) M(x) Premise 2 xp(x) Premise 3 P(c) EI(2) 4 P(c) M(c) UI(1) 5 M(c) Modus ponens (3),(4) 6 xm(x) EG(5) 10/1/12 CS160 Fall Semester 2012 26 Universal Generalization (UG) P(c) x P(x) Restrictions on UG UG is only truth-preserving under certain circumstances: Rationale: if a statement is true for an arbitrary thing, it must be true for all things. Really? Are you sure? All the time? 10/1/12 CS160 Fall Semester 2012 27 UG may not be applied to any constant that appears in a premise, assumption, or any line derived by Existential Instantiation (EI) 10/1/12 CS160 Fall Semester 2012 28 7
1 x M(x) Premise 2 M(sue) EI (1) Fallacy! Fallacy! Some people are mortal, therefore all people are mortal. 3 x M(x) UG (2) Violates rules! Predicate Logic Equivalences Statements are logically equivalent iff they have the same truth value under all possible bindings. For example: x(p(x) Q(x)) xp(x) xq(x) In English, given domain of students in CS160, all students have passed MCC124 course (P) and are registered at CSU (Q); hence, all students have passed MCC124 and all students are registered at CSU. 10/1/12 CS160 Fall Semester 2012 29 10/1/12 CS160 Fall Semester 2012 30 Other Equivalences x(p(x) Q(x)) xp(x) xq(x) Someone likes skiing (P) or likes swimming (Q); hence, there exists someone who likes skiing or there exists someone who likes swimming. Note that on the right side, it may not be the same person who likes skiing and who likes swimming. x P(x) x P(x) Not everyone likes to go to the dentist; hence there is someone who does not like to go to the dentist. x P(x) x P(x) There is not anyone who likes to go to the dentist; hence everyone does not like to go to the dentist. 10/1/12 CS160 Fall Semester 2012 31 Why Another Version is not Equivalence xp(x) xp(x) The left and right hand sides are not equivalent because universal quantification requires P to hold for all possible x s, while existential quantification requires it to hold for at least one. However xp(x) xp(x) 10/1/12 CS160 Fall Semester 2012 32 8
Stepping Back What should you be able to do? Given assumptions as propositions, formally prove a conclusion Given assumptions in the form of predicates, formally prove a conclusion 10/1/12 CS160 Fall Semester 2012 33 9