Upload
connor-ramirez
View
217
Download
1
Tags:
Embed Size (px)
Citation preview
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
2
Logical Modeling
2
Modeling
Realization
World
LanguageL
TheoryT
DomainD
ModelM
DataKnowledge
Meaning
MentalModel
SEMANTICGAP
Inte
rpre
tatio
n
I
En
tailm
en
t⊨
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
4
Syntax
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
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)
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)))
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
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
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)) )
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).
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.
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.
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.
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
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
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
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
19
Semantics
Interpretation
20
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
Interpretation of terms
22
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
Satisfiability of a formula
24
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
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
Modeling “blocks world”
27
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)
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
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
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
32
Reasoning
Model checking
33
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