University of Aberdeen, Computing Science CS2013 Predicate Logic 4 Kees van Deemter 01/11/16 Kees van Deemter 1
First-Order Predicate Logic (FOPL) Lecture 4 Making numerical statements: >0, <2, >1,>2,1,2 Prime numbers, Goldberg s conjecture Decidability and PROLOG 01/11/16 Kees van Deemter 2
Lecture IV The expressive power of FOPL (informal treatment) Making numerical statements Remarks about decidability Crash course in PROLOG 01/11/16 Kees van Deemter 3
Topic #3 Predicate Logic Some common shorthands Sometimes the universe of discourse is restricted within the quantification, e.g., x>0 P(x) is shorthand for For all x that are greater than zero, P(x). How would you write this in formal notation? 01/11/16 Kees van Deemter 4
Topic #3 Predicate Logic Some common shorthands Sometimes the universe of discourse is restricted within the quantification, e.g., x>0 P(x) is shorthand for For all x that are greater than zero, P(x). = x (x>0 P(x)) 01/11/16 Kees van Deemter 5
Topic #3 Predicate Logic Some common shorthands Sometimes the universe of discourse is restricted within the quantification, e.g., x>0 P(x) is shorthand for For all x that are greater than zero, P(x). = x (x>0 P(x)) x>0 P(x) is shorthand for There is an x greater than zero such that P(x). = x (x>0 P(x)) 01/11/16 Kees van Deemter 6
Topic #3 Predicate Logic Some common shorthands Consecutive quantifiers of the same type can be combined: xyz P(x,y,z) def x y z P(x,y,z) xyz P(x,y,z) def x y z P(x,y,z) 01/11/16 Kees van Deemter 7
Theorems about logic We are studying logical languages/calculi to allow you to use them (better) Logicians study logical languages/calculi to understand their limitations Meta-theorems can, e.g., say things like cannot be expressed in predicate logic 01/11/16 Kees van Deemter 8
Theorems about logic About propositional logic, we asked What types of things can we express? How many connectives do we need? About predicate logic, logicians ask similar questions. For example, are these two quantifiers enough to be able to say everything? This is a question about the expressive power of predicate logic 01/11/16 Kees van Deemter 9
Example: one As per their name, quantifiers can be used to express that a predicate is true of a given quantity (number) of objects. Example: Can predicate logic say there exists at most one object with property P? 01/11/16 Kees van Deemter 10
Example: at most one Example: Can predicate logic say there exists at most one object with property P? 01/11/16 Kees van Deemter 11
Example: at most one Example: Can predicate logic say there exists at most one object with property P? Yes (provided we have equality): x y ((P(x) P(y)) x= y) 01/11/16 Kees van Deemter 12
Example: one Can predicate logic say there exists exactly one object with property P? 01/11/16 Kees van Deemter 13
Example: one Can predicate logic say there exists exactly one object with property P? xp(x) x y((p(x) P(y)) x= y) There exist x such that P(x) and There exists at most one x such that P(x) Abbreviation:!x P(x) ( there exists exactly one x such that P(x) ) 01/11/16 Kees van Deemter 14
Example: one Another way to write this: x (P(x) y (P(y) y x)) There is an x such that P(x), such that there is no y such that P(y) and y x. x binds x throughout the conjunction: x (P(x) y (P(y) y x)) 01/11/16 Kees van Deemter 15
At least two Can predicate logic say there exist at least two objects with property P? 01/11/16 Kees van Deemter 16
At least two Can predicate logic say there exist at least two objects with property P? Yes: x y ((P(x) P(y)) x y) Incorrect would be xp(x) y(p(y) x y), (where x occurs free, and which therefore does not express a proposition) 01/11/16 Kees van Deemter 17
Exactly two Can predicate logic say there exist exactly two objects with property P? 01/11/16 Kees van Deemter 18
Exactly wo Can predicate logic say there exist exactly two objects with property P? Yes: x y (P(x) P(y) x y z (P(z) (z= x z= y) )) 01/11/16 Kees van Deemter 19
What s wrong with x y (P(x) P(y) x y) z (P(z) (z= x z= y )) as a formalisation of exactly two? 01/11/16 Kees van Deemter 20
What s wrong with x y (P(x) P(y) x y) z (P(z) (z= x z= y )) as a formalisation of exactly two? This is a conjunction of two separate propositions. As a result, x and y are not bound, so this is not even a proposition 01/11/16 Kees van Deemter 21
infinitely many Can predicate logic say there exist finitely many objects with property P? No! [This follows from the so-called Compactness Theorem: An infinite set S of formulas has a model iff every finite subset of S has a model ] (Proof in the next Lecture) 01/11/16 Kees van Deemter 22
finitely many How about infinitely many? 01/11/16 Kees van Deemter 23
finitely many How about infinitely many? Suppose there existed a formula ϕ = there exist only finitely many x such that so and so Then ϕ = there exist infinitely many x such that so and so We know that such a formula does not exist So, also ϕ does not exist 01/11/16 Kees van Deemter 24
(Of course if we allow infinite conjunctions then all this can be expressed:!x P(x) 2!x P(x) 3!x P(x) ) 01/11/16 Kees van Deemter 25
Can predicate logic say most objects have property P? No! [This follows from the Compactness Theorem as well. Again, this is unless we allow infinitely long disjunctions.] Can predicate logic say many objects have property P? No, only precisely defined quantities 01/11/16 Kees van Deemter 26
Topic #3 Predicate Logic Number Theory Examples Let u.d. = the natural numbers 0, 1, 2, What do the following mean? x (E(x) ( y x=2y)) x (P(x) (x>1 yz x=yz y 1 z 1)) 01/11/16 Kees van Deemter 27
Topic #3 Predicate Logic more Number Theory Examples Let u.d. = the natural numbers 0, 1, 2, A number x has the property E if and only if it is equal to 2 times some other number. (even!) x (E(x) ( y x=2y)) A number has P, iff it s greater than 1 and it isn t the product of any non-unity numbers. (prime!) x (P(x) (x>1 yz x=yz y 1 z 1)) 01/11/16 Kees van Deemter 28
Topic #3 Predicate Logic Goldbach s Conjecture (unproven) Using E(x) and P(x) from previous slide, x( [x>2 E(x)] p q P(p) P(q) p+q = x). 01/11/16 Kees van Deemter 29
Topic #3 Predicate Logic Goldbach s Conjecture (unproven) Using E(x) and P(x) from previous slide, x( [x>2 E(x)] p q P(p) P(q) p+q = x). Every even number greater than 2 is the sum of two primes. 01/11/16 Kees van Deemter 30
Decidability We ve shown you two ways of checking propositional-logic equivalencies: 1. Checking truth tables 2. Using equivalence laws You ve seen how (1) can be done algorithmically. This shows that checking propositional logic equivalence is decidable 01/11/16 Kees van Deemter 31
Decidability Checking proplog equivalence is decidable Checking predlog equivalence is not decidable Therefore, theorem proving will always remain an art (for both computers and humans) Some fragments of predlog are decidable. Example 1: Monadic FOPL (i.e., limited to 1- place predicates. No relations). See CS3518. Example 2: PROLOG. 01/11/16 Kees van Deemter 32
Bonus Topic: Logic Programming Some programming languages are based entirely on (a part of) predicate logic The most famous one is called Prolog. A Prolog program is a set of propositions ( facts ) and ( rules ) in predicate logic. The input to the program is a query proposition. Want to know if it is true or false. The Prolog interpreter does some automated deduction to determine whether the query follows from the facts. 01/11/16 Kees van Deemter 33
Facts in Prolog A fact in Prolog represents a simple, noncompound proposition in predicate logic. E.g., likes(john,mary) Lowercase symbols are used for constants and predicates, uppercase is used for variables. 01/11/16 Kees van Deemter 34
Rules in Prolog A rule in Prolog represents a universally quantified proposition of the general form x y (P(x,y) Q(x)), where x and y are variables, P a possibly compound predicate, and Q an atomic proposition. In Prolog: q(x) :- p(x,y). i.e., the, quantifiers are implicit. Example: likable(x) :- likes(y,x). 01/11/16 Kees van Deemter 35
Rules in Prolog Note that x y (P(x,y) Q(x)) is equivalent to x(( y P(x,y) Q(x)) In other words, Q(x) holds if you can find a y such that P(x,y) 01/11/16 Kees van Deemter 36
Conjunction and Disjunction Logical conjunction is encoded using multiple comma-separated terms in a rule. Logical disjunction is encoded using multiple rules. E.g., x ((P(x) Q(x)) R(x)) S(x) can be rendered in Prolog as: s(x) :- p(x),q(x) s(x) :- r(x) 01/11/16 Kees van Deemter 37
Deduction in Prolog When a query is input to the Prolog interpreter, it searches its database to determine if the query can be proven true from the available facts. if so, it returns yes, if not, no (!) If the query contains any variables, all values that make the query true are printed. 01/11/16 Kees van Deemter 38
Simple Prolog Example An example input program: likes(john,mary). likes(mary,fred). likes(fred,mary). likable(x) :- likes(y,x). An example query:? likable(z) returns:... 01/11/16 Kees van Deemter 39
Simple Prolog Example An example input program: likes(john,mary). likes(mary,fred). likes(fred,mary). likable(x) :- likes(y,x). An example query:? likable(z) returns: mary fred 01/11/16 Kees van Deemter 40
Relation between PROLOG and Predicate Logic PROLOG cannot use all predicate logic formulas. (It covers a decidable fragment of predicate logic.) It uses negation as failure Based on these limitations, PROLOG-based deduction is decidable. PROLOG is more than just logic (I/O, cut!), but logic is its hard core. 01/11/16 Kees van Deemter 41
01/11/16 Kees van Deemter 42