ldk r logics for data and knowledge representation exercises: first order logics (fol) originally by...

34
L Logics for D Data and K Knowledge R Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified by Fausto Giunchiglia, Rui Zhang and Vincenzo Maltese

Upload: connor-ramirez

Post on 27-Mar-2015

217 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

LLogics for DData and KKnowledgeRRepresentation

Exercises: First Order Logics (FOL)

Originally by Alessandro Agostini and Fausto GiunchigliaModified by Fausto Giunchiglia, Rui Zhang and Vincenzo Maltese

Page 2: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

2

Logical Modeling

2

Modeling

Realization

World

LanguageL

TheoryT

DomainD

ModelM

DataKnowledge

Meaning

MentalModel

SEMANTICGAP

Inte

rpre

tatio

n

I

En

tailm

en

t⊨

Page 3: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

The need for greater expressive power We need FOL for a greater expressive power. In FOL we

have: constants/individuals (e.g. 2) variables (e.g. x) Unary predicates (e.g. Man) N-ary predicates (eg. Near) functions (e.g. Sum, Exp) quantifiers (∀, ∃) equality symbol = (optional)

3

Page 4: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

4

Syntax

Page 5: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

Alphabet of symbols in FOL Variables x1, x2, …, y, z

Constants a1, a2, …, b, c

Predicate symbols A11, A1

2, …, Anm

Function symbols f11, f1

2, …, fnm

Logical symbols ∧, ∨, , , ∀, ∃ Auxiliary symbols ( )

Indexes on top are used to denote the number of arguments, called arity, in predicates and functions.

Indexes on the bottom are used to disambiguate between symbols having the same name.

Predicates of arity =1 correspond to properties or concepts

5

Page 6: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

Terms Terms can be defined using the following BNF grammar:

<term> ::= <variable> | <constant> | <function> (<term> {,<term>}*)

A term is called a closed term iff it does not contain variables

6

x, 2, SQRT(x), Sum(2, 3), Sum(2, x), Average(x1, x2, x3)

Sum(2, 3)

Page 7: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

Well formed formulas Well formed formulas (wff) can be defined in BNF as follows:

<atomic formula> ::= <predicate> (<term> {,<term>}*) | <term> = <term>

<wff> ::= <atomic formula> | ¬<wff> | <wff> ∧ <wff> | <wff> ∨ <wff> |

<wff> <wff> | ∀ <variable> <wff> | ∃ <variable> <wff>

NOTE: We can also write ∃x.P(x) or ∃x:P(x) as notation (with ‘.’ or “:”)

7

Man(x)

Odd(3)∀x (Odd(x) Even(x))∃x (Dog(x) White(x))∃x ∃y (Dog(x) Dog(y) (x = y))∀x (Even(x) GreaterThan(x,2) ∃y∃z (Prime(y) Prime(z) x = Sum(y,z)))

Page 8: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

Write in FOL the following NL sentences “Einstein is a scientist”

Scientist(einstein)

“There is a monkey”

∃x Monkey(x)

“There exists a dog which is black”

∃x (Dog(x) Black(x))

“All persons have a name”

∀x (Person(x) ∃y Name(x, y))

8

Page 9: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

Write in FOL the following NL sentences “The sum of two odd numbers is even”

∀x ∀y ( Odd(x) Odd(y) Even(Sum(x,y)) )

“A father is a male person having at least one child”

∀x ( Father(x) Person(x) Male(x) ∃y hasChilden(x, y) )

“There is exactly one dog”

∃x Dog(x) ∀x ∀y ( Dog(x) Dog(y) x = y )

“There are at least two dogs”

∃x ∃y ( Dog(x) Dog(y) (x = y) )

9

Page 10: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

The use of FOL in mathematics

10

Express in FOL the fact that every natural number x multiplied by 1 returns x (identity):

∀x ( Natural(x) (Mult(x, 1) = x) )

Express in FOL the fact that the multiplication of two natural numbers is commutative:

∀x ∀y ( Natural(x) Natural(y) (Mult(x, y) = Mult(y, x)) )

Page 11: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

The use of FOL in mathematics

11

FOL has being introduced to express mathematical properties

The set of axioms describing the properties of equality between natural numbers (by Peano):

Axioms about equality1. ∀x1 (x1 = x1) reflexivity

2. ∀x1 ∀x2 (x1 = x2 x2 = x1) symmetricity

3. ∀x1 ∀x2 ∀x3 (x1 = x2 x2 = x3 x1 = x3) transitivity

4. ∀x1 ∀x2 (x1 = x2 S(x1) = S(x2)) successor

NOTE: Other axioms can be given for the properties of the successor, the addition (+) and the multiplication (x).

Page 12: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

Modeling the club of married problem

12

L = {tom, sue, mary, Club, Married}

Club(tom) Club(sue) Club(mary) ∀x (Club(x) (x = tom x = sue x = mary))

Married(tom, sue)

∀x ∀y ((Club(x) Married(x, y)) Club(y))

∃x Married(mary, x)

There are exactly three people in the club, Tom, Sue and Mary. Tom and Sue are married. If a member of the club is married, their spouse is also in the club. Mary is not married.

Page 13: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

Modeling the club of married problem (II)

13

L = {tom, sue, mary, Club, Married}

S1: Club(tom) Club(sue) Club(mary) ∀x (Club(x) (x = tom x = sue x = mary))

S2: Married(tom, sue)

S3: ∀x ∀y ((Club(x) Married(x, y)) Club(y))

S4: ∃x Married(mary, x)

There are exactly three people in the club, Tom, Sue and Mary. Tom and Sue are married. If a member of the club is married, their spouse is also in the club.

Add enough common sense FOL statements (e.g. everyone has at most one spouse, nobody can be married to himself or herself, Tom, Sue and Mary are different people) to make it entail that Mary is not married in FOL.

Page 14: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

Modeling the club of married problem (III)

14

We need to add the following:

S5: ∀x ∀y ((Married(x, y) Married(y, x)) simmetry

S6: ∀x ∀y ∀z ((Married(x, y) Married(x, z) y = z) at most one wife

S7: ∃x Married(x, x) nobody is married with

himself/herself

S8: (tom=sue) (tom=mary) (mary=sue) unique name assumption

There are exactly three people in the club, Tom, Sue and Mary. Tom and Sue are married. If a member of the club is married, their spouse is also in the club.

Add enough common sense FOL statements (e.g. everyone has at most one spouse, nobody can be married to himself or herself, Tom, Sue and Mary are different people) to make it entail that Mary is not married in FOL.

Page 15: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

Analogy with Databases

“List name, position and manager of the employees”γ = Employee(x, y, z)

Qγ = All the tuples in the Relation

“List managers of the employees named Enzo”γ = ∃y Employee(Enzo, y, z)

Qγ = {(Fausto)}

15

NAME POSITION MANAGER

Enzo PhD Fausto

Fausto Professor Bassi

Feroz PhD Enzo

EMPLOYEE

Page 16: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

SELECT

“List name and position of the employees having a manager”

γ = ∃z Employee(x, y, z)Qγ = {(Enzo, PhD), (Fausto, Professor), (Feroz, PhD)}

16

NAME POSITION MANAGER

Enzo PhD Fausto

Fausto Professor Bassi

Feroz PhD Enzo

EMPLOYEE

Page 17: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

FILTER

“List name and position of the employees with Fausto as manager”

γ = ∃z Employee(x, y, Fausto, z)Qγ = {(Enzo, PhD)}

“List name and position of the employees with age > 28”

γ = ∃w ∃z (Employee(x, y, z, w) ∧ (w > 28))Qγ = {(Enzo, PhD), (Fausto, Professor)}

17

NAME POSITION MANAGER AGE

Enzo PhD Fausto 35

Fausto Professor Bassi 40

Feroz PhD Enzo 20

EMPLOYEE

Page 18: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

JOIN

“List name of faculty members and their department”

γ = ∃y ∃z ( Faculty(x, y, z) ∧ Dept(x, w) )Qγ = {(Enzo, DISI), (Fausto, DISI), (Feroz, MATH)}

“List name of faculty members who belong to all departments”

γ = ∀w (∃x Dept(x, w) ∃y ∃z (Faculty(x, y, z) ∧ Dept(x, w)))

18

NAME POSITION MANAGER

Enzo PhD Fausto

Fausto Professor Bassi

Feroz PhD Enzo

NAME DEPT

Enzo DISI

Fausto DISI

Feroz MATH

FACULTY DEPT

Page 19: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

19

Semantics

Page 20: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

Interpretation

20

Page 21: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

Example of Interpretation

21

∆ = {tom, sue, mary, club, married, age, sum}

Constants:

I(tom) = Tom, I(sue) = Sue, I(mary) = Mary

Unary predicates:

Club(tom), Club(sue), Club(Mary)

Binary predicates:

Married(tom, sue)

Functions:

age(tom) = 40, age(sue) = 35, age(mary) =18

sum(3, 5) = 8

MARRIED

Tom Sue

Robert Mary

CLUB

Tom

Sue

Mary

∆1

Tom

Sue

Mary

40

35

18

age

∆2

3 5

8

sum

Page 22: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

Interpretation of terms

22

Page 23: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

Interpretation of terms

23

Constants

I(tom)[a] = I(tom) = Tom

I(sue)[a] = I(sue) = Sue

Variables

I(x) [a] = a(x) = tom

I(y) [a] = a(y) = sue

I(z) [a] = a(z) = 3

Functions

I(age(x))) [a] = I(age) (I(x)[a]) = age(a(x)) = age(tom) = 40

I(sum(z, 5))[a] = I(sum) I(I(z)[a], I(5)[a]) = sum(a(z), 5) = sum(3,5) = 8

Page 24: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

Satisfiability of a formula

24

Page 25: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

Satisfiability of simple formulas (I)

25

Satisfiability is given w.r.t an assignment a. Verify the following:

I ⊨ tom = sue [a] verify whether: I(tom) [a] = I(sue) [a]

I ⊨ Married(tom, sue) [a] verify whether: <I(tom) [a], I(sue) [a]> Married

I ⊨ Married(tom, y) [a] verify whether: <I(tom) [a], I(y) [a]> Married

I ⊨ Married(tom, y) [a] verify whether: <I(tom) [a], I(y) [a]> Married

I ⊨ ∃x Married(mary, x) [a] verify whether there exist any d such that

<Mary, d> Married

I ⊨ ∀x Married(mary, x) [a] verify whether for all d <Mary, d> Married

Page 26: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

Satisfiability of simple formulas (II) ∆ = {0, 1, 2, 3}

constants = {zero} variables = {x}

predicate symbols = {even, odd} functions = {succ}

γ1 : ∀x (even(x) odd(succ(x)))

γ2 : even(zero)

γ3 : odd(zero)

Is there any I and a such that I ⊨ γ1 γ2 [a]?

I(zero)[a] = I(zero) = 0

I(succ(x))[a] = I(succ)(I(x)[a]) = S(n) = {0 if n=3, n+1 otherwise}

I(even) = {0, 2}

I(odd) = {1, 3}

Is there any I and a such that I ⊨ γ1 γ3 [a]?

Yes! Just invert the interpretation of even and odd.

26

Page 27: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

Modeling “blocks world”

27

Page 28: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

Satisfiability of the problem of blocks

28

Express the following problem in FOL: “There are 3 blocks A, B, C in a stack. Each block can be either black or white. We know that the block A is on the bottom. A block is on the top if there are no blocks above it. It is possible to be on top if and only if the block is black”.

ABC

Constants = {a, b, c} Predicates = {Black, White, Top} Relations = {Above}

γ1 : ∃x Above(a,x)

γ2 : Top(y) Black(y) ∃z Above(z,y)

Page 29: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

Constants = {a, b, c} Predicates = {Black, White, Top} Relations = {Above}

γ1 : ∃x Above(a,x)

γ2 : Top(y) Black(y) ∃z Above(z,y)

Is Γ = {γ1, γ2} satisfiable? Is there any I and an assignment a such that I ⊨ γ1 [a] and I ⊨ γ2 [a]?

∆ = {A, B, C}

I(a) = A I(b) = B I(c) = C I(Black) = {A, C} I(White) = {B}

I(Top) = {C} I(Above) = {<B,A>, <C,B>}

I(y)[a] = a(y) = C

NOTE: we can assign a different color to A and B. y is free.

Satisfiability of the problem of blocks (II)

29

ABC

Page 30: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

Entailment (logical consequence) Given:

α : ∀x ∀y ∃z (p(x, y) (p(x, z) p(z, y)))

β : ∀x ∀y (p(x, y) ∃z (p(x, z) p(z, y)))

Does α ⊨ β?

Yes, because in α we can put ∃z inside:

∀x ∀y (∃z p(x, y) ∃z (p(x, z) p(z, y)))

z is not in the scope of ∃z p(x, y) and therefore we obtain β

30

Page 31: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

Entailment (logical consequence) For all formulas of the form p(x, y):

1. Is ∃x∃y p(x, y) ⊨ ∃y∃x p(x, y)?2. Is ∃x∀y p(x, y) ⊨ ∀y∃x p(x, y)? 3. Is ∀x∃y p(x, y) ⊨ ∃y∀x p(x, y)? If no provide a counterexample.

Assume p(x, y) is x y. (1) Yes. The two formulas both says that there are at least two objects which are related via p.(2) Yes. The first formula says that there is an x such that for all y we have x y. We can take x = 0. The second formula says that for all y there exist an x such that x y. x = 0 is fine again.(3) In this case is No. The first formula says that for all x there exist a y such that x y. We can take y = Succ(x). The second formula says that there exists a y such that for all x we have x y. We should take y = +.

31

Page 32: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

32

Reasoning

Page 33: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

Model checking

33

Page 34: LDK R Logics for Data and Knowledge Representation Exercises: First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified

How to prove validity in finite domains Is it possible to prove that:

⊨ ∀x (Person(x) Male(x)) [a] where D = {a, b, c}

We have only 3 possible assignments a(x) = a, a(x) = b, a(x) = c

We can translate it as follows:P: (Person(a) Male(a)) (Person(b) Male(b)) (Person(c) Male(c))

P: (Person(a) Male(a)) (Person(b) Male(b)) (Person(c) Male(c))

P: (Person-a Male-a) (Person-b Male-b) (Person-c Male-c)

We check that DPLL(P) returns false.

34