Intro Fol
Intro Fol
knowledge representation
Part 1 - Introduction to Logic
Chiara Ghidini and Luciano Serafini
FBK-IRST, Trento, Italy
What is Logic?
The main objective of a logic (there is not a unique logic but
many) is to express by means of a formal language the
knowledge about a he certain phenomena or a certain portion
of the world.
encode with a precise set of deterministic rules, called
inference rules, the basic reasoning steps which are
considered to be correct by everybody.
a correct reasoning allows to show that a certain knowledge is
a logical consequence of a given set of facts, and in logic
correct reasoning chains are constructed by concatenating
applications of simple inference rules, that allow to transform
the initial knowledge into the conclusion one wants to derive.
What is Logic?
The main objective of a logic (there is not a unique logic but
many) is to express by means of a formal language the
knowledge about a he certain phenomena or a certain portion
of the world.
encode with a precise set of deterministic rules, called
inference rules, the basic reasoning steps which are
considered to be correct by everybody.
a correct reasoning allows to show that a certain knowledge is
a logical consequence of a given set of facts, and in logic
correct reasoning chains are constructed by concatenating
applications of simple inference rules, that allow to transform
the initial knowledge into the conclusion one wants to derive.
What is Logic?
The main objective of a logic (there is not a unique logic but
many) is to express by means of a formal language the
knowledge about a he certain phenomena or a certain portion
of the world.
encode with a precise set of deterministic rules, called
inference rules, the basic reasoning steps which are
considered to be correct by everybody.
a correct reasoning allows to show that a certain knowledge is
a logical consequence of a given set of facts, and in logic
correct reasoning chains are constructed by concatenating
applications of simple inference rules, that allow to transform
the initial knowledge into the conclusion one wants to derive.
Re
al
wo
rld
Language
al
tic
ma
t h e ure
M a t ruct
s
Abstraction
Is the link that connects the real world with its matematical and abstract representation into a mathematical
structure. If a certain situation is supposed to be abstractly described by a given structure, then the abstraction
connects the elements that participats to the situation, with the components of the mathematical structure, and
the properties that holds in the situation with the mathematical properties that holds in the structure.
Logic
Logic is a special case of the framework we have seen before,
where the following important component are defined
The language is a Logical language
The formal interpretation allows to define a notion of truth
It is possibel to define a notion of logical consequence between
formulas I.e., if a set of formulas are true then also is true
Formal language
Formal language
Given a non empty set of symbols called alphabet a formal
language is a subset L , i.e., a set of finite strings of symbols
in . The elements of L are called well formed phrases. Formal
languages can be specified by means of a grammar, i.e., a set of
formation rules that allow to build complex well formed phrases.
starting from simpler ones.
Logical language
Logical languages
A language of a logic, i.e., a logical language is a formal language, which has
the following characteristics:
The alphabet of a logical languages typically contains basic symbols that
are used to indicate the basic (atomic) components of the (part of the)
world the logic is supposed to describe. The alphabet is composed of two
subsets: the logical symbols and the non logical symbols. Examples of
such atomic objects are, individuals, functions, operators, truth-values,
propositions, . . .
The grammar of logical language define all the possible ways to construct
complex phrases starting from simpler one. Logical grammar always
define a grammar for building formulas which are phrases that denotes
propositions, i.e., objects that can assume some truth value (as e.g., true,
false, true in certain situation, true with probability of 3%, true/false in a
period of time . . . ) . Another important family of phrases which are
usually defined in logic are terms which usually denotes objects of the
world (e.g., cats, dogs, time points, quantities,
Alphabet
Alphabet
The alphabet of a logical language is composed of two classes
of symbols:
logical constants, whose formal interpretation is constant and
fixed by the logic (e.g., , , =, . . .
non logical symbols, whose formal interpretation is not fixed
and can vary within a given range. They are not fixed by the
logic and they must be defined by the user.
Alphabet - example
Logical Constant
Propositional logic: , , , , and , that stand for
conjunction, disjunction, negation, implication, equivalence,
and falsity. They are usually called propositional connectives
Predicate logic (or first order logic): in addition to the
propositional connectives we have and , that stand for,
every object is such that . . . , and there is some object
such that . . . . They are usually called universal and
existential quantifier
Modal logic: in addition to the propositional connectives, we
have ! and that stand for it is necessarily true that . . .
and it is possibly true that . . . . They are usually called
modal operators
Alphabet - example
Non logical symbols
In propositional logic, non logical symbols are called
propositional variables which represent (= has intuitive
interpretation) proposition. The proposition associated to
each propositional variable is not fixed by the logic.
In predicate logic. there are four families of non logical
symbols
Variable symbols which represent any object
Constant symbols which represent specific objects
Function symbols which represent transformations on objects
Predicate symbols which represent relations between objects
symbol
rain
Moby Dick
Color (x)
Friends(x, y )
intuitive interpretation
its raining
The whale of a novel by Melville
the color of the object x
x and y are friends
Grammar - Example
Propositional logic
The grammar of propositional logic allow to define the unique class of phrases, called
formulas (or well formed formulas), which denotes propositions.
FORMULA
:=
P
|
|
|
|
(P is a propositional variable)
"("FORMULA "" FORMULA")"
"("FORMULA "" FORMULA")"
"("FORMULA "" FORMULA")"
"(" "" FORMULA ")"
(P (Q R)) P
The above formulas are well formed, because there is a sequence of application of
grammar rules that allow to generate them. (Exercise: list the rules that allow to
generate the above formulas).
Example (Non well formed formulas)
P(Q R)
Chiara Ghidini and Luciano Serafini
(P P)
Introduction to first order logic for knowledge representation
Grammar - Example
Language of first order logic
TERM
FORMULA
:=
|
|
:=
|
|
|
|
|
|
x (x is a variable symbol)
c (c is a constant symbol)
f (TERM . . . TERM) (f is a function symbol)
P(TERM . . . TERMINE) (P is a predicate symbol)
FORMULA FORMULA
FORMULA FORMULA
FORMULA FORMULA
FORMULA
x FORMULA (x is a variable symbol)
x FORMULA (x is a variable symbol)
The rules defines two types of phrases, the terms and the formulas. Terms denote
object (they are like noun phrases in natural language) while formulas denote
propositions (they are like sentences in natural language).
Exercise
Give some examples of terms and formulas, and some examples of phrases which are
neither terms nor formulas
Chiara Ghidini and Luciano Serafini
Grammar - Example
The grammar for Description logics ALC
FORMULA
CONCEPT
ROLE
INDIVIDUAL
:=
|
|
:=
|
|
|
|
|
:=
:=
Example
The intuitive interpretation of the propositional formula
(raining snowing ) go to the beach
is obtained by composing the intuitive interpretations of the symbols that occurs in this formula. If the intuitive
interpretation of the symbols are:
symbol
intuitive meaning
raining
snowing
go to the beach
it is raining
it is snowing
we go to the beach
either it is the case of . . . or . . .
if . . . then . . .
it is not the case that . . .
Formal model
Class of models: The models in which a logic is formally interpreted are
the member of a class of algebraic structures each of which is an abstract
representation of the relevant aspects of the (portion of the) world we
want to formalize with this logic.
What do models represent? Models represent only the components and
aspects of the worlds with are relevant to a certain analysis, and abstract
away from irrelecant facts. For instance, if we are interested in the
everage temperature of each day, we can represent time with the natural
numbers and a function that associates to each natural number a floating
point number (the average temperature of the day corresponding to the
point)
Applicability of a model Since the (real) world is quite complex, in the
construction of the formal model, we usually make a number of
simplifying assumptions that bound the usability of the logic to the cases
in which these assumptions are verified. For instance if we take integers
as a formal model of time, then we cannot use this model to represent
continuos change.
What represents a single model Each element of the class represent a
single possible (or impossible) state of the world. The class of models of
a logic will represent all the (im)possible states of the world.
Chiara Ghidini and Luciano Serafini
Formal interpretation
Given a structure S, the formal interpretation of a logical
language in S is a function that associates an element of S to
any non logical symbol of the alphabet.
the formal interpretation on the algebraic structure is the
parallel (or better is the formalization) of the intuitive
interpretation in the real world.
The formal interpretation is specified only for the non logical
symbols, while the formal interpretation of the logical symbols
is fixed by the logic.
The formal interpretation of complex expressions e obtained
by a combination of the sub-expressions e1 , . . . en ) is
unequivocally determined as a function of the formal
interpretations of the sub-components e1 , . . . , en .
Model
|=
Formula
Logical consequence
The notion of logical consequence is defined on the basis of the
notion of truth in a model. Intuitively, a formula is a logical
consequence of a set of formulas (sometime called assumptions)
if such a formula is true under this set of assumptions.
|=
Set of
formulas
formula
x.(x)
(c)
x.(x)
(d)
(1)
(2)
(3)
(5)
(MP)
r
r s
(r s) b
b
(OR intro)
Belongs to
by applying (OR-intro) to (1)
Belongs to
By applying (MP) to (2) and (3)
Formulas contd
Example ((non) formulas)
Formulas
PQ
P (Q R)
P Q R
Non formulas
PQ
(P ((Q R)
P Q R
Problem
The formula P Q R can be read in two ways:
1
(P Q) R
P (Q R)
Symbol priority
has higher priority, then , , and . Parenthesis can be used
around formulas to stress or change the priority.
Chiara Ghidini and Luciano Serafini
Formulas as trees
Tree form of a formula
A formula can be seen as a tree. Leaf nodes are associated to
propositional variables, while intermediate (non-leaf) nodes are
associated to connectives.
For instance the formula (A B) (B C ) can be represented
as the tree
Subformulas
Definition
(Proper) Subformula
A is a subformula of itself
A and B are subformulas of A B, A B A B, e A B
A is a subformula of A
if A is a subformula of B and B is a subformula of C , then A
is a subformula of C .
A is a proper subformula of B if A is a subformula of B and A
is different from B.
Remark
The subformulas of a formula represented as a tree correspond to
all the different subtrees of the tree associated to the formula, one
for each node.
Chiara Ghidini and Luciano Serafini
Subformulas
Example
The subformulas of (p (q r )) (p p) are
(p (q r )) (p p)
(p (q r ))
p p
p
p
qr
q
r
p
q
p
r
Proposition
Every formula has a finite number of subformulas
p
True
True
True
True
False
False
False
False
q
True
True
False
False
True
True
False
False
r
Set theoretic representation
True
{p, q, r }
False
{p, q}
True
{p, r }
False
{p}
True
{q, r }
False
{q}
True
{r }
False
{}
(1)
False True
(2)
True
(3)
then A is
Unsatisfiable
not Valid
Satisfiable
Valid
B
true
true
false
false
true
true
false
false
C
true
false
true
false
true
false
true
false
A (B C )
true
true
false
true
true
true
true
true
Introduction to first order logic for knowledge representation
AA
Valid
(A A)
AB A
Satisfiable
AB
(A
B)
A
Non Valid
(A A)
Uatisfiable
(A A)
Chiara Ghidini and Luciano Serafini
I2 = {Y } corrisponding to
I3 = {R} corrisponding to
I4 = {G } corrisponding to
Logical consequence
Definition (Logical consequence)
A formula A is a logical consequence of a set of formulas , in
symbols
|= A
Iff for any interpretation I that satisfies all the formulas in , I
satisfies A,
Example (Logical consequence)
p |= p q
q p |= p q
p q, p r , q r |= r
p q, p |= q
p, p |= q
Chiara Ghidini and Luciano Serafini
Logical consequence
Example
Proof of p |= p q Suppose that I |= p, then by definition I |= p q.
Proof of q p |= p q Suppose that I |= q p, then either I |= q or
I |= p. In both cases we have that I |= p q.
Proof of p q, p r , q r |= r Suppose that I |= p q and
I |= p r and I |= q r . Then either I |= p or I |= q.
In the first case, since I |= p r , then I |= r , In the
second case, since I |= q r , then I |= r .
Proof of p, p |= q Suppose that I |= p, then not I |= p, which
implies that there is no I such that I |= p and I |= p.
This implies that all the interpretations that satisfy p and
p (actually none) satisfy also p.
Proof of (p q) (p q) |= p q) Left by exercise
Proof of (p q) |= p q Left by exercise
Chiara Ghidini and Luciano Serafini
Outline
Why First Order Logic (FOL)?
Syntax and Semantics of FOL;
First Order Theories;
Fun with sentences...
michele-is-father-of-luca michele-is-italian
...
michele-is-father-of-luca michele-is-italian
...
Mary is a person;
John is a person;
Mary is mortal;
Mary is a person;
John is a person;
Mary is mortal;
and also to infer the third one from the first one and the fifth one.
Functions
The father of Luca is Italian.
In FOL it is possible to build propositions by applying a function to
a constant, and then a predicate to the resulting object.
Italian(fatherOf (Mario))
Syntax of FOL
Logical symbols
the logical constant
functions (arity)
mark (2)
best-friend (1)
Predicate (arity)
attend (2)
friend (2)
student (1)
course (1)
less-than (2)
Example (Terms)
Intuitive meaning
an individual named Aldo
the mark 1
Brunos best friend
anything
Brunos mark in MathLogic
somebodys mark in DataBase
Brunos best friend mark in MathLogic
functions (arity)
mark (2)
best-friend (1)
Predicate (arity)
attend (2)
friend (2)
student (1)
course (1)
less-than (2)
Example (Terms)
Intuitive meaning
an individual named Aldo
the mark 1
Brunos best friend
anything
Brunos mark in MathLogic
somebodys mark in DataBase
Brunos best friend mark in MathLogic
term
Aldo
1
best-friend(Bruno)
x
mark(Bruno,MathLogic)
mark(x,DataBase)
mark(best-friend(Bruno),MathLogic)
Intuitive meaning
Aldo and Bruno are the same person
Carlo is a person and MathLogic is a course
Aldo attends MathLogic
Courses are attended only by students
every course is attended by somebody
every student attends something
a student who attends all the courses
every course has at least two attenders
Aldos best friend attend the same courses
attended by Aldo
best-friend is symmetric
Aldo and his best friend have the same mark
in MathLogic
A student can attend at most two courses
Intuitive meaning
Formula
Aldo = Bruno
person(Carlo) course(MathLogic)
attend(Aldo, MathLogic)
x(attend(x, y ) course(y ) student(x))
x(course(x) y attend(y , x))
x(student(x) y attend(x, y ))
x(student(x) y (course(y ) attend(x, y )))
x(course(x) y z(attend(y , x) attend(z, x) y = z))
x(attend(Aldo, x) attend(best-friend(Aldo), x))
x(best-friend(best-friend(x)) = x)
mark(best-friend(Aldo), MathLogic) = mark(Aldo, MathLogic)
xy zw (attend(x, y ) attend(x, z) attend(x, w )
(y = z z = w y = w ))
Common Mistakes
Use of with
x (WorksAt(FBK , x) Smart(x))
Common Mistakes
Use of with
x (WorksAt(FBK , x) Smart(x)) means Everyone works at
FBK and everyone is smart
Common Mistakes
Use of with
x (WorksAt(FBK , x) Smart(x)) means Everyone works at
FBK and everyone is smart
Everyone working at FBK is smart is formalized as
x (WorksAt(FBK , x) Smart(x))
Common Mistakes
Use of with
x (WorksAt(FBK , x) Smart(x)) means Everyone works at
FBK and everyone is smart
Everyone working at FBK is smart is formalized as
x (WorksAt(FBK , x) Smart(x))
Use of with
x (WorksAt(FBK , x) Smart(x))
Common Mistakes
Use of with
x (WorksAt(FBK , x) Smart(x)) means Everyone works at
FBK and everyone is smart
Everyone working at FBK is smart is formalized as
x (WorksAt(FBK , x) Smart(x))
Use of with
Common Mistakes
Use of with
x (WorksAt(FBK , x) Smart(x)) means Everyone works at
FBK and everyone is smart
Everyone working at FBK is smart is formalized as
x (WorksAt(FBK , x) Smart(x))
Use of with
x1 . . . xn+1
n+1
i=1
(xi )
n+1
i=j=1
xi = xj
x1 . . . xn
i=1
(xi )
i=j=1
xi = xj
Semantics of FOL
FOL interpretation for a language L
A first order interpretation for the language
L = c1 , c2 , . . . , f1 , f2 , . . . , P1 , P2 , . . . is a pair , I where
is a non empty set called interpretation domain
I is is a function, called interpretation function
I(ci ) (elements of the domain)
I(fi ) : n (n-ary function on the domain)
I(Pi ) n (n-ary relation on the domain)
Example of interpretation
Example (Of interpretation)
Symbols
Domain
= {1, 2, 3, 4, . . . }
Interpretation
4, 1 , 1, 4 , 4, 4
Example (contd)
Alice
Bob
Carol
Mother
Robert
Friend
Syntax
Semantics
M
F
M
1
M
M
F
F
2
F
4
Interpretation of terms
Definition (Assignment)
An assignment a is a function from the set of variables to .
a[x/d] denotes the assignment that coincides with a on all the
variables but x, which is associated to d.
Definition (Interpretation of terms)
The interpretation of a term t w.r.t. the assignment a, in symbols
I(t)[a] is recursively defined as follows:
I(xi )[a] = a(xi )
Example (contd)
Exercise
Check the satisfiability of the following statements, considering the
interpretation defined few slides ago:
1
2
3
I |= Alice = Bob[a]
I |= Robert = Bob[a]
I |= x = Bob[a[x/2]
Example (cont.).
I(mother-of(alice))[a]
I(mother-of(x))[a[x/4]]
I(friends(x, y ))
x :=
1
2
4
1
4
2
4
3
4
y :=
2
1
1
4
2
4
3
4
4
I(friends(x, x))
x :=
4
I(friends(x, y ) x = y )
x :=
4
I(xfriends(x, y ))
y :=
2
1
4
3
I(xfriends(x, y ))
y :=
4
y :=
4
I |= [a]
bought(Frank, dvd)
x.bought(Frank, x)
3
4
5
6
bought(Frank, dvd)
x.bought(Frank, x)
3
4
5
6
Bill is a student.
10
11
x.(Student(x) Smart(x))
x.Student(x)
x.(Student(x) Smart(x))
I |= for all I C
0 = s(x)
s(x) = s(y ) x = y
x +0=x
x + s(y ) = s(x + y )
x 0=0
6
7
x s(y ) = (x y ) + x
the Induction axiom schema: (0) x.((x) (s(x))) x.(x), for every
formula (x) with at least one free variable
K. G
odel 1931 Its false that I |= PA if and only if I is isomorphic to the standard
models for natural numbers.