University of Aberdeen, Computing Science...

42
Module #1 - Logic 01/11/16 Kees van Deemter 1 University of Aberdeen, Computing Science CS2013 Predicate Logic 4 Kees van Deemter

Transcript of University of Aberdeen, Computing Science...

Module #1 - Logic

01/11/16 Kees van Deemter 1

University of Aberdeen, Computing Science CS2013

Predicate Logic 4 Kees van Deemter

Module #1 - Logic

01/11/16 Kees van Deemter 2

First-Order Predicate Logic (FOPL) Lecture 4

Making numerical statements: >0, <2, >1,>2,1,2 Prime numbers, Goldberg’s conjecture

Decidability and PROLOG

Module #1 - Logic 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

Module #1 - Logic

01/11/16 Kees van Deemter 4

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?

Topic #3 – Predicate Logic

Module #1 - Logic

01/11/16 Kees van Deemter 5

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))

Topic #3 – Predicate Logic

Module #1 - Logic

01/11/16 Kees van Deemter 6

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))

Topic #3 – Predicate Logic

Module #1 - Logic

01/11/16 Kees van Deemter 7

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)

Topic #3 – Predicate Logic

Module #1 - Logic

01/11/16 Kees van Deemter 8

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”

Module #1 - Logic

01/11/16 Kees van Deemter 9

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

Module #1 - Logic

01/11/16 Kees van Deemter 10

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”?

Module #1 - Logic

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”?

Module #1 - Logic

01/11/16 Kees van Deemter 12

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)

Module #1 - Logic

01/11/16 Kees van Deemter 13

Example: one

•  Can predicate logic say “there exists exactly one object with property P”?

Module #1 - Logic

01/11/16 Kees van Deemter 14

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)”)

Module #1 - Logic

01/11/16 Kees van Deemter 15

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))

Module #1 - Logic

01/11/16 Kees van Deemter 16

At least two

•  Can predicate logic say “there exist at least two objects with property P”?

Module #1 - Logic

01/11/16 Kees van Deemter 17

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)

Module #1 - Logic

01/11/16 Kees van Deemter 18

Exactly two

•  Can predicate logic say “there exist exactly two objects with property P”?

Module #1 - Logic

01/11/16 Kees van Deemter 19

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) ))

Module #1 - Logic

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’?

Module #1 - Logic

01/11/16 Kees van Deemter 21

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

Module #1 - Logic

01/11/16 Kees van Deemter 22

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)

Module #1 - Logic

01/11/16 Kees van Deemter 23

finitely many

•  How about infinitely many?

Module #1 - Logic

01/11/16 Kees van Deemter 24

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

Module #1 - Logic

01/11/16 Kees van Deemter 25

(Of course if we allow infinite conjunctions then all this can be expressed: ∃!x P(x) ∨ ∃2!x P(x) ∨ ∃3!x P(x) ∨ … )

Module #1 - Logic

01/11/16 Kees van Deemter 26

•  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

Module #1 - Logic

01/11/16 Kees van Deemter 27

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))

Topic #3 – Predicate Logic

Module #1 - Logic

01/11/16 Kees van Deemter 28

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))

Topic #3 – Predicate Logic

Module #1 - Logic

01/11/16 Kees van Deemter 29

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).

Topic #3 – Predicate Logic

Module #1 - Logic

01/11/16 Kees van Deemter 30

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.”

Topic #3 – Predicate Logic

Module #1 - Logic

01/11/16 Kees van Deemter 31

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

Module #1 - Logic

01/11/16 Kees van Deemter 32

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.

Module #1 - Logic

01/11/16 Kees van Deemter 33

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.

Module #1 - Logic

01/11/16 Kees van Deemter 34

Facts in Prolog

•  A fact in Prolog represents a simple, non-compound proposition in predicate logic. – E.g., likes(john,mary) – Lowercase symbols are used for constants and

predicates, uppercase is used for variables.

Module #1 - Logic

01/11/16 Kees van Deemter 35

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).

Module #1 - Logic

01/11/16 Kees van Deemter 36

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)

Module #1 - Logic

01/11/16 Kees van Deemter 37

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)

Module #1 - Logic

01/11/16 Kees van Deemter 38

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.

Module #1 - Logic

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: ...

Module #1 - Logic

01/11/16 Kees van Deemter 40

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

Module #1 - Logic

01/11/16 Kees van Deemter 41

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.

Module #1 - Logic

01/11/16 Kees van Deemter 42