Module 1 Logic University of Aberdeen Computing Science
Module #1 - Logic University of Aberdeen, Computing Science CS 2013 Predicate Logic 4 Kees van Deemter 10/09/2021 Kees van Deemter 1
Module #1 - Logic First-Order Predicate Logic (FOPL) Lecture 4 Making numerical statements: >0, <2, >1, >2, 1, 2 Prime numbers, Goldberg’s conjecture Decidability and PROLOG 10/09/2021 Kees van Deemter 2
Module #1 - Logic Lecture IV The expressive power of FOPL (informal treatment) • Making numerical statements • Remarks about decidability • Crash course in PROLOG 10/09/2021 Kees van Deemter 3
Module #1 - Logic 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? 10/09/2021 Kees van Deemter 4
Module #1 - Logic 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)) 10/09/2021 Kees van Deemter 5
Module #1 - Logic 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)) 10/09/2021 Kees van Deemter 6
Module #1 - Logic 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) 10/09/2021 Kees van Deemter 7
Module #1 - Logic 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” 10/09/2021 Kees van Deemter 8
Module #1 - Logic 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 10/09/2021 Kees van Deemter 9
Module #1 - Logic 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”? 10/09/2021 Kees van Deemter 10
Module #1 - Logic Example: at most one • Example: Can predicate logic say “there exists at most one object with property P”? 10/09/2021 Kees van Deemter 11
Module #1 - Logic 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) 10/09/2021 Kees van Deemter 12
Module #1 - Logic Example: one • Can predicate logic say “there exists exactly one object with property P”? 10/09/2021 Kees van Deemter 13
Module #1 - Logic Example: one • Can predicate logic say “there exists exactly one object with property P”? x. P(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)”) 10/09/2021 Kees van Deemter 14
Module #1 - Logic 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)) 10/09/2021 Kees van Deemter 15
Module #1 - Logic At least two • Can predicate logic say “there exist at least two objects with property P”? 10/09/2021 Kees van Deemter 16
Module #1 - Logic 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 x. P(x) y(P(y) x y), (where x occurs free, and which therefore does not express a proposition) 10/09/2021 Kees van Deemter 17
Module #1 - Logic Exactly two • Can predicate logic say “there exist exactly two objects with property P”? 10/09/2021 Kees van Deemter 18
Module #1 - Logic 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) )) 10/09/2021 Kees van Deemter 19
Module #1 - Logic 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’? 10/09/2021 Kees van Deemter 20
Module #1 - Logic 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 10/09/2021 Kees van Deemter 21
Module #1 - Logic 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) 10/09/2021 Kees van Deemter 22
Module #1 - Logic finitely many • How about infinitely many? 10/09/2021 Kees van Deemter 23
Module #1 - Logic 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 10/09/2021 Kees van Deemter 24
Module #1 - Logic (Of course if we allow infinite conjunctions then all this can be expressed: !x P(x) 2!x P(x) 3!x P(x) … 10/09/2021 Kees van Deemter ) 25
Module #1 - Logic • 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 10/09/2021 Kees van Deemter 26
Module #1 - Logic 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=2 y)) • x (P (x ) (x>1 yz x=yz y 1 z 1)) 10/09/2021 Kees van Deemter 27
Module #1 - Logic 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=2 y)) • “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)) 10/09/2021 Kees van Deemter 28
Module #1 - Logic 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). 10/09/2021 Kees van Deemter 29
Module #1 - Logic 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. ” 10/09/2021 Kees van Deemter 30
Module #1 - Logic 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 10/09/2021 Kees van Deemter 31
Module #1 - Logic 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 CS 3518. • Example 2: PROLOG. 10/09/2021 Kees van Deemter 32
Module #1 - Logic 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. 10/09/2021 Kees van Deemter 33
Module #1 - Logic 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. 10/09/2021 Kees van Deemter 34
Module #1 - Logic 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). 10/09/2021 Kees van Deemter 35
Module #1 - Logic 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) 10/09/2021 Kees van Deemter 36
Module #1 - Logic 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) 10/09/2021 Kees van Deemter 37
Module #1 - Logic 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. 10/09/2021 Kees van Deemter 38
Module #1 - Logic 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: . . . 10/09/2021 Kees van Deemter 39
Module #1 - Logic 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 10/09/2021 Kees van Deemter 40
Module #1 - Logic 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. 10/09/2021 Kees van Deemter 41
Module #1 - Logic 10/09/2021 Kees van Deemter 42
- Slides: 42