First Order Logicperso.univ-mlv.fr/ocure/fol.pdf · FOL : syntax (5) • We say that a variable...
Transcript of First Order Logicperso.univ-mlv.fr/ocure/fol.pdf · FOL : syntax (5) • We say that a variable...
First Order Logic
1
FOL : introduction
• With propositional logic we can not ac-
cess the structure of atomic sentences.
• In First Order logic (FOL), the atomic
formulas are interpreted as statements about
the relationships between objects.
2
FOL : syntax
• Two sorts of symbols coexist in FOL.
• logical symbols, they have a fixed mean-
ing or use in the language :
– punctuation : (,),[,]
– connectives : ¬, ∨, ∧, →, ↔, ∀, ∃, =.
– variables : x,y and z, sometimes with
subscripts and superscripts.
3
FOL : syntax (2)
• nonlogical symbols, they have an application-
dependent meaning or use :
– function symbols which we denote us-
ing g,f and h, sometimes with sub-
scripts and superscripts.
– predicate symbols which we denote P,
Q and R, sometimes with subscripts
and superscripts.
Each non-logical symbols has an arity, a
nonnegative integer indicating how many
”arguments” it takes. Function symbols
and predicate symbols with an arity of
0 are respectively constants and proposi-
tional symbols.
4
FOL : syntax (3)
• Two types of legal syntactic expressions
in FOL.
• terms which are used to refer to some-
thing in the world. The set of terms of
FOL is the least satisfying these condi-
tions :
– every variable is a term;
– if t1, .., tn are terms, and f is a function
symbol of arity n, then f(t1, .., tn) is a
term.
5
FOL : syntax (4)
• formulas which are used to express a
proposition. The set of formulas of FOL
is the least satisfying these constraints :
– Atomic formulas or atoms :
∗ if t1, .., tn are terms,a nd P is a predi-
cate symbol of arity n, then P(t1, .., tn)
is a formula.
∗ if t1 and t2 are terms, then t1 = t2is a formula.
– if α and β are formulas, and x is a
variable, then ¬α, (α∧β), (α∨β), ∀x.α,
∃x.α are formulas.
6
FOL : syntax (5)
• We say that a variable occurence is bound
in a formula if it lies within the scope of
a quantifier, and free otherwise.
• A sentence (or closed formula) of FOL is
any formula without free variables. Sen-
tences are usually used to represent knowl-
edge.
• A ground term is a term that does not
contain any variables.
• A ground atom is an atom that contains
only ground terms.
7
FOL : semantics
• It is hard to specify once and for all what
a sentence of FOL means, because the
nonlogical symbols are application-dependent.
• But we can agree once and for all on how
the meaning of the sentence derives from
the interpretation of the nonlogical sym-
bols involved.
• Meanings are captured in specific inter-
pretations. An interpretation = in FOL
is a pair (∆, I) where :
– ∆ is a nonempty set of objetcs, named
the domain of the interpretation.
– I is a function which assigns elements
of the FOL language to ∆.
8
Interpretation function
• I assigns meaning to the predicate sym-
bols as follows : to every predicate sym-
bol P of arity n : I[P ] is an n-ary relation
over ∆, that is :
I[P ] ∈ [∆n → {false, true}]
• I assigns meaning to the function sym-
bols as follows : to every function symbol
f of arity n, I[f ] is an n-ary function over
∆, that is :
I[f ] ∈ [∆n → ∆]
9
Denotation
• Dealing with terms including variables,
we need to start with a variable assign-
ment over δ : a mapping from the vari-
ables of FOL to the elements of ∆.
• If µ is a variable assignment and x is a
variable, µ[x] is some element of the do-
main.
• Given = and µ, the denotation of term t,
written ‖t‖=,µ, is defined by these rules :
1. if x is a variable, then ‖x‖=,µ = µ[x].
2. if t1, .., tn are terms, and f is a function
symbol of arity n, then :
‖f(t1, .., tn)‖=,µ = I[f ](d1, .., dn) where di =
‖ti‖=,µ.
10
Satisfaction and models
Given an interpretation = and a variable as-
signment µ, we say that the formula α is sat-
isfied in = (=, µ |= α) according to these rules
:
Assume that t1, .., tn are terms, P is a predi-
cate of arity n, α and β are formulas and x is
a variable.
1. =, µ |= P (t1, .., tn) iff 〈d1, .., dn〉 ∈ I[P ] and
di = ‖ti‖=,µ.
2. =, µ |= t1 = t2 iff ‖t1‖=,µ and ‖t2‖=,µ are
the same element in ∆.
3. =, µ |= ¬α iff it is not the case that =, µ |=α.
4. =, µ |= (α ∧ β) iff =, µ |= α and =, µ |= β.
11
5. =, µ |= (α∨ β) iff =, µ |= α or =, µ |= β (or
both).
6. =, µ |= ∃x.α iff =, µ′ |= α, for some vari-
able assignment µ′ that differs from µ on
at most x.
7. =, µ |= ∀x.α iff =, µ′ |= α, for every vari-
able assignment µ′ that differs from µ on
at most x.
Logical consequence
• There are connections among sentences
of FOL that do not depend on the mean-
ing of nonlogical symbols.
• Let S be a set of sentences, and α any
sentence. We say that α is a logical con-
sequence of S, or that S logically entails
α, which we write § modelsα, iff, for ev-
ery interpretation =, if = modelsS then
= |= α. In other words, every model of S
satifies α.
• We can also say that there is no inter-
pretation = where = |= S ∪ {¬α}. In this
case, we say that S∪{¬α} is unsatisfiable.
12
Validity
• We say that a sentence α is logically valid,
which we write |= α, when it is a logical
consequence of the empty set. In other
words, α is valid iff, for every interpreta-
tion =, it is the case that = |= α.
• In still other words, iff the set {¬α} is
unsatisfiable.
13
Automated reasoning with FOL
There are several equivalent ways of formu-
lating the decutive reasoning task : KB |= α
(KB is a finite set of sentences (α1, .., αn)
• iff |= [(α1 ∧ .. ∧ αn) → α]
• iff KB ∪ {¬α} is not satisfiable
So a procedure for testing the validity of sen-
tences, or for testing the satisfiability of sen-
tences can be used to find the entailments of
a finite KB.
The Resolution procedure is a such a pro-
cedure.
14
Prenex Normal form
• A normal form where all quantifiers ap-
pear to the left of a quantifier-free ex-
pression called a matrix.
• Steps :
1. Elimination of → and ↔.
2. Push ¬ inwards.
3. Pull quantifiers outwards
• There is an algorithm that computes for
every formula its prenex normal form.
15
Prenex Normal form - example
∃xA(x) → ∀xB(x)
¬∃xA(x) ∨ ∀xB(x)
∀x¬A(x) ∨ ∀xB(x)
∀x¬A(x) ∨ ∀yB(y)
∀x∀y(¬A(x) ∨B(y))
With renaming of variables on line 4. Let
φ[x/t] be the formula φ where all occurences
of x have been replaced by the term t.
Let y be a variable that does not occur in
φ. Then we have ∀xφ ≡ (∀yφ[x/y] and ∃xφ ≡∃yφ[x/y].
16
Resolution for FOL
• We have studied Resolution for the propo-
sitional case. Now we need to consider
reasoning with variables, terms and quan-
tifiers.
• We need to convert formulas into an equiv-
alent clausal form. For simplicity, we as-
sume that no existential quantifiers re-
main once negations have been moved
inward).
1. eliminate → and ↔.
2. move ¬ inward using the equivalences
: ¬∀x.α ≡ ∃x¬α and ¬∃x.α ≡ ∀x¬α.
3. standardize variables, so that each quan-
tifier is over a distinct variable.
17
4. eliminate all remaing existentials (see
later).
5. move universals outside the scope of
∨ and ∧ using (provided that x does
not occur free in α) :
(α ∧ ∀xβ) ≡ (∀xβ ∧ α) ≡ ∀x(α ∧ β)
(α ∨ ∀xβ) ≡ (∀xβ ∨ α) ≡ ∀x(α ∨ β)
6. distribute ∧ over ∨ as in propositional
case.
7. collect terms as in propositional case.
So we obtain a universally quantified CNF
Resolution for FOL (2)
• All quantifiers are universally so we can
drop them.
• Clauses are understood as in the proposi-
tonal case, except that variables appear-
ing in them are are interpreted universally.
18
Substitution and unification
• A substitution θ is a finite set of pairs
{x1/t1, .., xn/tn} where the xi are distinct
variables and the ti are arbitrary terms.
• If θ is a substitution and ρ is a literal, then
ρθ is the lietarl that results from simulta-
neously replacing each xi in ρ by ti.
• In order to form resolvable literals, we
have to perform subsitutions.
• Substitutions that make occurences of lit-
erals identical are called unifiers.
• Example : The literals A(x,y,f(z)) and
A(a,g(z),w) are unified by θ the follow-
ing {x/a, y/g(a), z/a, w/f(a)}.
19
Resolution example
We consider the following KB :
∀xGradStudent(x) → Student(x)
∀xStudent(x) → HardWorker(x)
GradStudent(sue)
KB |= HardWorker(sue) ?
Resolution derivation :
[¬Student(x), Hardworker(x)] and [¬HardWorker(sue)]
are unified by x/sue and we get [¬Student(sue)]
The this result is unified with
[¬Gradstudent(x), Studentard(x)] by x/sue and
we get [¬GradStudent(sue)]
Which is finally resolved with
GradStudent(sue) to get the empty set.
So KB |= HardWorker(sue) holds.
20
Skolemization
• To handle existential qunatifiers when con-
verting to CNF, we use skolemization.
• Main idea of skolemization : because some
individuals are claimed to exist, we intro-
duce names for them (skolem constants
and skolem functions) and represent facts
using those names.
• Example : ∃xP (x) becomes P (a) with a
a skolem constant.
• Example : ∀x∃yQ(x, y) becomes ∀xQ(x, f(x))
with f a skolem symbol.
• Example : ∃x∀y∃zR(x, y, z) becomes ∀yR(a, y, g(y))
with g and a skolem symbols.
21
Resolution and decidability
We consider the following KB :
∀x∀yLessThan(succ(x), y) → LessThan(x, y)
KB |= LessThan(zero, zero) ?
With Resolution, we never derive the empty
clause. Instead, an infinite sequence is gen-
erated.
There is no way to detect if a branch will
continue indefinitely.
22
Herbrand model
• For the propositional case, resolution runs
to completion, so we never have the non-
termination problem.
• Sometimes resolution in FOL reduces to
a propositional case.
• Given a set S of clauses, the Herbrand
universe of S is the set of all ground
terms formed using just the constants
and function symbols in S.
• Example : S contains the constants a and
b and the unary function f. The Herbrand
universe is the set :
{a, b, f(a), f(b), f(f(a)), f(f(b)), ...}.
23
Herbrand model
• The Herbrand base of S is the set of
all ground clauses cθ where c ∈ S and θ
assigns the variables in c to terms in the
Herbrand base.
• Herbrand’s theorem states that a set of
clauses is satisfiable iff its Herbrand base
is.
• The problem is that the Herbrand base
will typically be an infinite set of propo-
sitional clauses. It will be finite and the
Herbrand universe is finite (no function
symbols and only finitely many constants
appear in S).
24
Semantic tableau in FOL
• The use of semantic tableaux is based on
the strategy of negating the conclusion of
an argument and checking if the result is
inconsistent witht he premises. It is a
refutation strategy.
• Semantic tableaux in FOL are basically
the same as in propositional logic.
• The rules that were used for propositional
logic are used again in FOL, and these are
supplemented by some rules involving the
quantifiers.
25
Quantifier rules for semantic tableau in FOL
Rule for ∀ :
∀xA(x)
A(t)
Rule for ∃:∃xA(x)
A(t), where t is a term which has not been
used in the derivation so far.
Rule for ¬∀ :
¬∀xA(x)
∃x¬A(x)
Rule for ¬∃:¬∃xA(x)
∀x¬A(x)
26
Example 1
Prove ∀xA(x) → ∃yA(y)
¬∀xA(x) → ∃yA(y) ∀xA(x)
¬∃yA(y)
¬∀yA(y)
¬A(a)
A(a)
The tableau is closed so the result is proved.
27
Example 2
Prove ∃x∃yR(x, y) → R(a, a)
(1) ¬∃x∃yR(x, y) → R(a, a)
(2) ∃x∃yR(x, y)
(3) ¬R(a, a)
(4) ∃yR(a, y)
(5) R(a, a)
Closed ?
This demonstration is incorrect, the ∃ rule on
line 5 has been violated : term a has been
used before.
28
Example 3
But it is not a problem to use the same term
with universal quantifiers.
Prove ∀x(A(x) ∧B(x)) → ∀xA(x)
¬∀x(A(x) ∧B(x)) → ∀xA(x)
∀x(A(x) ∧B(x))
¬∀xA(x)
∃x¬A(x)
¬A(a)
A(a) ∧B(a)
A(a)
B(a)
Closed so it is proved.
Heuristic : When developong a semantic
tableau in FOL, use the existential instan-
tiation rule before the universal instantiation
rule.
29
Example 4
Is the following argumnt valid ?
All lecturers are determined
Anyone who is determined and intelligent will
give satisfactory service
Clare is an intelligent lecturer
Therefore Clare will give satisfactory service
Let L(x) stand for ’x is lecturer.’
Let D(x) stand for ’x is determined.’
Let I(x) stand for ’x is intelligent.’
Let S(x) stand for ’x will give satisfactory
service.’
30
Example 4
We want to show :
∀x(L(x) → D(x))∧∀x((D(x)∧I(x)) → S(x))∧L(Clare) ∧ I(Clare) |= S(Clare)
The tableau is :
∀x(L(x) → D(x))
∀x(D(x) ∧ I(x) → S(x)
L(Clare)
I(Clare)
¬S(Clare)
L(Clare) → D(Clare)
D(Clare) ∧ I(Clare) → S(Clare)
D(Clare) ¬L(Clare)
¬(D(Clare)∧ I(Clare)) S(Clare) closed
¬D(Clare) ¬I(Clare) closed
Since the tableau is closed we conclude that
the argument is valid.
31
KR example with FOL
Suppose we have 3 colored blocks stacked on
a table, where the top one is green, the bot-
tom one is not green, and the color of the
middle block is not known.
The question is whether there is a green block
directly on top of a nongreen one.
We formalize this problem in FOL, using a,b
and c as the names of the blocks and pred-
icate symbol G and O to stand for ”green”
and ”on”.
The facts we have in S are :
O(a, b), O(b, c), G(a),¬G(c)
S |= α holds? where α is ∃x∃yG(x)∧¬G(y)∧O(x, y)
To show this, we need to show that any in-
terpretation that satisfies S also satisfies α.
32
Blocks world
So let = be any interpretation, and assume
that = |= S. There are 2 cases to consider.
1. Suppose = |= G(b). Then because ¬G(c)
and O(b, c) are in S,
= |= G(b) ∧ ¬G(c) ∧O(b, c)
It follows from this that
= |= ∃x∃yG(x) ∧ ¬G(y) ∧O(x, y)
2. Suppose that = 6|= G(b). Then it is the
case that = |= ¬G(b), and because G(a) and
O(a,b) are in S,
= |= G(a) ∧ ¬G(b) ∧O(a, b)
It follows from this that
= |= ∃x∃yG(x) ∧ ¬G(y) ∧O(x, y)
Either way, it is the case that = |= α (α is a
logical consequence of S).
33
Conclusion
• No automated reasoning process for FOL
can be both sound and complete in gen-
eral.
• Alan Turing (1936) and Alonzo Church
(1936) both proved, in rather different
ways, that the question of entailment for
FOL is semidecidable, that is, algorithms
exist that say yes to every entailed sen-
tence, but no algorithm exists that also
says no to every nonentailed sentence.
• The computational difficulty of FOL is
one of the factors that leads us to con-
sider various other options to represent
knowledge.
34
Conclusion (2)
• We have seen that a logic is made of a
syntax, a semantics and inference proce-
dures for the reasoning problems. The
syntax describes how to write correct sen-
tences in the language. The semantics
tells us what sentences mean in the ”real
world”. The inference procedure derives
results logically implied by a set of premises.
• Logics differ in terms of their representa-
tion power and computational complex-
ity of inference. The more restrictedthe
representational power, the faster the in-
ference in general.
35
Conclusion (3)
• Propositional logic says things about facts
and whether or not they are true. In the
worst case, we can use the truth table
method to do inference. Proof methods
such are resolution and tableaux are gen-
erally more efficient, easier to implement
and understand.
• FOL talks about objects and relations be-
tween them. Good for representing most
interesting domains, but inference is not
only expensive, but may not terminate.
36