Course contents• Introduction to declarative programming
• Clausal logic
• Logic programming in Prolog
• Search
• Natural language processing
• Reasoning using incomplete information
• Inductive logic programming
4
Clausal logicA logic system consists of:
1. Syntax: which “sentences” are legal
2. Semantics: what is the truth value of a sentence
3. Proof theory: how to derive new sentences (theorems) from assumed ones (axioms) by means of inference rules
A logic system should be
1. Sound: anything you can prove is true
2. Complete: anything true, can be proven
5
Prolog is neither!
propositional
relational
full
definite
propositions that are true or false
contains constants, variables and their relations
contains function symbols & compound terms
true prolog: clauses only have one true literal
Different clausal logic systems
6
Expr
essi
vene
ss married;bachelor :- man,adult
likes(peter,S) :- student_of(peter,S)
loves(X,person_loved_by(X)).
A :- B1, B2,..., Bn.
6
SyntaxConnectives:! :-! “if”! ;! “or”! ,! “and”
Example:
Someone is married or a bachelor if he is a man and an adult
7
Propositional clausal logic
clause : head [:- body]head : [proposition [; proposition]* ]body : [proposition [, proposition]* ]proposition: atomatom : single word starting with lowercase
married; bachelor :- man, adult
Logic programPropositions are denoted as atoms, f.i. married denotes that someone is married.
Combining atoms result in clauses: married;bachelor :- man,adultmeaning ‘somebody is married or a bachelor if he is a man and an adult’
Combining clauses, results in a program:
8
Propositional clausal logic
woman;man :- human.human :- man.human :- woman.
(human ⇒ (woman ∨ man))∧ (man ⇒ human)∧ (woman ⇒ human)
is equivalent to
(¬human ∨ woman ∨ man) ∧ (¬man ∨ human)∧ (¬woman ∨ human)
B ⇒ H ≡ ¬B ∨ H
ClausesIn general a clause
H1 ; ... ; Hn :" B1 , ... , Bm
is equivalent with
H1 ∨ ... ∨Hn ∨ ¬B1 ∨ ... ∨ ¬Bm
A clause can also be defined asL1 ∨ L2 ∨ ... ∨ Ln
where each Li is a literal, i.e. Li = Ai or Li = ¬Ai , with Ai a proposition.
9
Propositional clausal logic
Special clausesEmpty body stands for true
Empty head stands for false
Entire program in standard logic:
(true ⇒ man) ∧ (impossible ⇒ false)
man ∧ ¬ impossible
10
Propositional clausal logic
man :- . % usually written as man.
:- impossible
true ⇒ man
impossible ⇒ false
i.e.
SemanticsThe Herbrand base βP is the set of all atoms occurring in P
A Herbrand interpretation i is a mapping of all atoms in βP to a truth value
An interpretation is a model for a clause if the clause is true under the interpretation
An interpretation is a model for a program if it is a model for each clause in the program.
11
Propositional clausal logic
woman;man :- human.human :- man.human :- woman.
βP = {woman, man, human}i = {(woman, true), (man, false), (human, true)}I = {woman, human}
Semantics: example
12
Propositional clausal logic
woman;man :- human.human :- man.human :- woman.
βP = {woman, man, human}
I1 = {woman} I2 = {man}I3 = {human} I4 = {woman, human}
I5 = {man, human} I6 = {woman, man}I7 = {woman, man, human} I8 = {}
Semantics: example
12
Propositional clausal logic
woman;man :- human.human :- man.human :- woman.
βP = {woman, man, human}
I1 = {woman} I2 = {man}I3 = {human} I4 = {woman, human}
I5 = {man, human} I6 = {woman, man}I7 = {woman, man, human} I8 = {}
Logical ConsequenceA clause C is a logical consequence of a program P, denoted
P ⊨ C
if every model of P is also a model of C.
models of P:
P ⊨ human
I1 is preferred since it does not assume anything that does not have to be true.
13
Propositional clausal logic
woman.woman;man :- human.human :- man.human :- woman.
I1 = {woman, human} I2 = {woman, man, human}
Best model = minimal model, obtained by taking the intersection of all models.
However...
M1 ∩ M2 ∩ M3 = {human} which is not a model of the first clause...
A definite clausal logic program has a unique minimal model
Minimal models
14
Propositional clausal logic
I1 = {woman, human} I2 = {woman, man, human}
woman;man :- human.human.
M1 = {woman, human} M2 = {man, human}M3 = {woman, man, human}
Proof theoryChecking every model of a program to compute the logical consequences is in general unfeasible.
Use resolution as an inference rule
15
Propositional clausal logic
married;bachelor :- man,adult.has_wife :- man,married.
If someone is a man and an adult, then he is a bachelor or married; but if he is married, he has a wife; therefore, if someone is a man and an adult, the he is a bachelor or he has a wife
¬man ∨ ¬adult ∨ married ∨ bachelor¬man ∨ ¬married ∨ has_wife
either married and then ¬man ∨ has_wifeor ¬married and then ¬man ∨ ¬adult ∨ bachelor
thus ¬man ∨ has_wife ∨ ¬man ∨ ¬adult ∨ bachelor
B ⇒ H ≡ ¬B ∨ H
Proof theory (2)
A proof of derivation of a clause C from a program P, is a sequence of clauses such that each clause is either in the program, or the resolvent of two previous clauses, and the last clause is C.
If a proof exists, it is denoted as P ⊦ C16
Propositional clausal logic
square :- rectangle, equal_sides.rectangle :- parallelogram, right_angles.
square :- rectangle,equal_sides. rectangle :- parallelogram,right_angles.
square :- equal_sides, parallelogram, right_angles.
has_wife :- man,married. married;bachelor :- man,adult.
has_wife;bachelor :- man,adult.
married;bachelor :- man,adult.has_wife :- man,married.
Resolution in traditional notation
17
Propositional clausal logic
E1 ∨ E2 ¬E2 ∨ E3
E1 ∨ E3
A ¬A ∨ B
B
AA ⇒ B
B
Modus Ponens
¬A ∨ B¬B
¬A
A ⇒ B
¬B
¬A
Modus Tollens
Meta-theory: soundnessResolution is sound if anything you can prove is true
IF P ⊦ C THEN P ⊧ C
Every model of the input clauses is also a model of the resolvent!
Every model of
is also a model of
Proven by validating the options for the literal resolved upon
18
Propositional clausal logic
married;bachelor :- man,adult.has_wife :- man,married.
has_wife;bachelor :- man,adult.
Meta-theory: completenessResolution is incomplete!!!
Take for instance the tautology
It is true under any interpretation, so P ⊧ a:-a, since every model of P will be a model of a tautology. Even if a does not occur in P!
This can not be established with resolution.
This is not what resolution is used for...
→ ‘is C a logical consequence of P?’, rather than ‘What are the logical consequences of P?’
19
Propositional clausal logic
a :- a
Meta-theory: proof by refutationIf P set of clauses is inconsistent, it is always possible to derive ��by resolution.
Suppose we want to know if P ⊧ a
→ An interpretation I of P is a model of a iff I is not a model of :-a.
→ Check if P ∪ {:-a} are inconsistent
inconsistent set has no model → every model is a model of another clause, in particular �
IF P ⊧ a THEN P ∪ {:-a} ⊦ �
20
Propositional clausal logic
Meta-theory: exampleProof by refutation:
⊧ P ⊧ C
⊦ �
P ∪ ¬ C
21
Propositional clausal logic
happy :- has_friends.friendly :- happy. friendly :- has_friends
happy :- has_friends.friendly :- happy.has_friends.:- friendly
:- friendly friendly :- happy
:- happy happy :- has_friends
:- has_friends has_friends
�
Meta-theory: refutation complete
22
Propositional clausal logic
P ⊧ C ⇔ each model of P is also a model of C
⇔ no model of P is a model of ¬C
⇔ P∪¬C has no model
P∪¬C is inconsistent
entailment reformulated
it can be shown that:
if Q is inconsistent then Q ⊦ �if P ⊧ C then P∪¬C ⊦ �
refutation-complete
it derives the empty clause from any inconsistent set of
clauses
C = L1∨L2∨...∨Ln
¬C = ¬L1∧¬L2...∧¬Ln
= {¬L1,¬L2...,¬Ln} = set of clauses itself
empty clause false :- true for which no model exists
Meta-theory: completenessResolution is refutation complete
IF P ⊧ C THEN P ∪ ¬C ⊢ �
where Q ⊢ � means Q is inconsistent
i.e. C is a logical consequence of P if and only if one can derive, using resolution, the empty clause (�) from P ∪ ¬C
23
Propositional clausal logic
Relational clausal logic
propositional
relational
full
definite
propositions that are true or false
contains constants, variables and their relations
contains function symbols & compound terms
true prolog: clauses only have one true literal
Different clausal logic systems
28
Expr
essi
vene
ss married;bachelor :- man,adult
likes(peter,S) :- student_of(peter,S)
loves(X,person_loved_by(X)).
A :- B1, B2,..., Bn.
28
Relational clausal logic
Syntax
- same connectives as propositional clausal logic
- introduces constants and variables
For any S, if S is a student of peter, the peter likes S
29
Relational clausal logic
constant : single word starting with lowercasevariable : single word starting with uppercaseterm : constant | variablepredicate : single word starting with lowercase atom : predicate[(term[,term]*)]clause : head [:- body]head : [atom [; atom]* ]body : atom [, atom]*
likes(peter,S) :- student_of(S,peter).student_of(maria,peter).
Relational clausal logic
SemanticsThe Herbrand universe of a program P is the set of all ground terms occurring in it
The Herbrand base βP of P is the set of all ground atoms that can be constructed using predicates in P and arguments in the Herbrand universe of P
A Herbrand interpretation I of P is a subset of βP, consisting of ground atoms that are true
30
βP = { likes(peter,peter), likes(peter,maria), likes(maria,peter), likes(maria,maria), student_of(peter,peter), student_of(peter,maria), student_of(maria,peter), student_of(maria,maria) }I = {likes(peter,maria), student_of(maria,peter)}
likes(peter,S) :- student_of(S,peter).student_of(maria,peter).
Relational clausal logic
Substitutions & grounding
31
Relational clausal logic
Substitutions & grounding
if σ={S/maria}, then Cσ is
ground instances :likes(peter,peter):-student_of(peter,peter).likes(peter,maria):-student_of(maria,peter).student_of(maria,peter).
31
A substitution is a mapping σ : Var → Term.For a clause C, the result of σ on C, denoted Cσ is obtained by replacing all occurrences of X ∈ Var in C by σ(X). Cσ is an instance of C.
likes(peter,maria) :- student_of(maria,peter).
A ground instance of a clause C is the result of some substitution such that Cσ contains but ground atoms.
Relational clausal logic
ModelsAn interpretation I is a model of a clause C iff it is a model of every ground instance of C. An interpretation is a model of a program P iff it is a model of each clause C ∈ P.
I = {likes(peter,maria), student_of(maria, peter)}
is a model of all ground instances of clauses in P
32
likes(peter,S) :- student_of(S,peter).student_of(maria,peter).
likes(peter,peter):-student_of(peter,peter).likes(peter,maria):-student_of(maria,peter).student_of(maria,peter).
Relational clausal logic
Proof theory: ResolutionNaive version: propositional resolution with all ground instances of clauses in P.
Herbrand universe = {peter, maria}
⇒ already 8 different grounding substitutions
⇒ exponential in the number of constants and variables
Relational clausal logic contains variables, allowing atoms to be made equal
33
likes(peter,S) :- student_of(S,peter).student_of(maria,T) :- follows(maria,C),teaches(T,C).
Relational clausal logic
UnificationA substitution σ is a unifier of two atoms a1 and a2 ! a1σ = a2σ. If such a σ exists, a1 and a2 are called unifiable.
A substitution σ1 is more general than σ2 if σ2 = σ1θ for some substitution θ.
A unifier θ of a1 and a2 is a most general unifier (mgu) of a1 and a2 ! it is more general than any other unifier of a1 and a2.
If two atoms are unifiable then they their mgu is unique up to renaming.
34
Relational clausal logic
Unification: examples
35
p(X, b) and p(a, Y) are unifiablewith most general unifier {X/a,Y/b}
q(a) and q(b) are not unifiable
q(X) and q(Y) are unifiable:
{X/Y} (or{Y/X}) is the most general unifier
{X/a, Y/a} is a less general unifier
Relational clausal logic
Unification: example
student_of(maria,T) and student_of(S,peter) can be made equal:{S→maria,T→peter} resulting in:
Now consider:
{S→maria, X→maria, T→peter} OR {X→S, T→peter}
more general
36
likes(peter,S) :- student_of(S,peter).student_of(maria,T) :- follows(maria,C),teaches(T,C).
likes(peter,maria) :- student_of(maria,peter).student_of(maria,peter) :- follows(maria,C),teaches(peter,C).
likes(peter,S) :- student_of(S,peter).student_of(X,T) :- follows(X,C),teaches(T,C).
Relational clausal logic
Proof theory: mguApply resolution on many clause-instances at once
37
if
Clausal logic
proof theory using mgu
“Do resolution on many clause-instances at once.”
If
C1 = L11 ∨ . . . L1
n1
C2 = L21 ∨ . . . L2
n2
L1i θ = ¬L2
j θ for some 1 ≤ i ≤ n1, 1 ≤ j ≤ n2
where θ = mgu(L1i , L2
j ), then
L11θ∨ . . .∨L1
i−1θ∨L1i+1θ∨ . . .∨L1
n1θ∨L2
1θ∨ . . .∨L2j−1θ∨L2
j+1θ∨ . . .∨L2n2
θ
44 / 259
Clausal logic
proof theory using mgu
“Do resolution on many clause-instances at once.”
If
C1 = L11 ∨ . . . L1
n1
C2 = L21 ∨ . . . L2
n2
L1i θ = ¬L2
j θ for some 1 ≤ i ≤ n1, 1 ≤ j ≤ n2
where θ = mgu(L1i , L2
j ), then
L11θ∨ . . .∨L1
i−1θ∨L1i+1θ∨ . . .∨L1
n1θ∨L2
1θ∨ . . .∨L2j−1θ∨L2
j+1θ∨ . . .∨L2n2
θ
44 / 259
then
Clausal logic
proof theory using mgu
“Do resolution on many clause-instances at once.”
If
C1 = L11 ∨ . . . L1
n1
C2 = L21 ∨ . . . L2
n2
L1i θ = ¬L2
j θ for some 1 ≤ i ≤ n1, 1 ≤ j ≤ n2
where θ = mgu(L1i , L2
j ), then
L11θ∨ . . .∨L1
i−1θ∨L1i+1θ∨ . . .∨L1
n1θ∨L2
1θ∨ . . .∨L2j−1θ∨L2
j+1θ∨ . . .∨L2n2
θ
44 / 259
Clausal logic
proof theory using mgu
“Do resolution on many clause-instances at once.”
If
C1 = L11 ∨ . . . L1
n1
C2 = L21 ∨ . . . L2
n2
L1i θ = ¬L2
j θ for some 1 ≤ i ≤ n1, 1 ≤ j ≤ n2
where θ = mgu(L1i , L2
j ), then
L11θ∨ . . .∨L1
i−1θ∨L1i+1θ∨ . . .∨L1
n1θ∨L2
1θ∨ . . .∨L2j−1θ∨L2
j+1θ∨ . . .∨L2n2
θ
44 / 259
Relational clausal logic
Proof theory: example
:-likes(peter,N){N→maria} ∪ P ⊢ � Hence P ⊧ likes(peter,maria)
38
likes(peter,S) :- student_of(S,peter).student_of(S,T) :- follows(S,C),teaches(T,C).teaches(peter,decprog).follows(maria,decprog).
:- likes(peter,N) likes(peter,S) :- student_of(S,peter).
:- student_of(N,peter) student_of(S,T) :- follows(S,C),teaches(T,C).
:- follows(N,C),teaches(peter,C) follows(maria,decprog)
:- teaches(peter,decprog) teaches(peter,decprog).
�
{S→N}
{S→N, T→peter}
{N→maria, C→decprog}
Relational clausal logic
Meta-theory: sound & completeRelational clausal logic is sound
IF P ⊢ C THEN P ⊧ C
Relational clausal logic is refutation complete
IF P ∪ {C} inconsistent THEN P ∪ {C} ⊢ �
different formulation because::- p(X).≡∀X·¬p(X)
while ¬(p(X).)≡¬(∀X·p(X))≡∃X·¬p(X)
39
Relational clausal logic
Meta-theory: decidability
P ⊧ C is decidable for relational clausal logic
Because the Herbrand universe is finite,
hence there is a finite number of models,
hence we could check all models of P to verify if they are a model of C
40
Full clausal logic
propositional
relational
full
definite
propositions that are true or false
contains constants, variables and their relations
contains function symbols & compound terms
true prolog: clauses only have one true literal
Different clausal logic systems
45
Expr
essi
vene
ss married;bachelor :- man,adult
likes(peter,S) :- student_of(peter,S)
loves(X,person_loved_by(X)).
A :- B1, B2,..., Bn.
45
Full clausal logic
Syntax
- introduces function symbols (functors), with an arity, constants are 0-ary functors
46
functor : single word starting with lowercasevariable : single word starting with uppercaseterm : variable | functor[(term[,term]*)]predicate : single word starting with lowercase atom : predicate[(term[,term]*)]clause : head [:- body]head : [atom [; atom]* ]body : atom [, atom]*
plus(0,X,X).plus(s(X),Y,s(Z)) :- plus(X,Y,Z).
read s(X) as “successor of X”
loves(X,person_loved_by(X)).
Everybody loves somebody
Full clausal logic
SemanticsThe Herbrand universe of a program P is the set of ground terms that can be constructed from constants and functors.!! can be infinite !!{0, s(0), ...}
The Herbrand base βP of P is the set of all ground atoms that can be constructed using predicates in P and the ground terms in the Herbrand universe of P!! can be infinite !!
A Herbrand interpretation I of P is a subset of βP, consisting of ground atoms that are true
47
Full clausal logic
48
according to first ground clause, plus(0,0,0) has to be in any modelbut then the second clause requires the same of plus(s(0),0,s(0)) and the third clause of plus(s(s(0)),0,s(s(0)))...
An interpretation is a model for a program if it is a model for each ground instance of every clause in the program.
plus(0,0,0).plus(s(0),0,s(0)):-plus(0,0,0).plus(s(s(0)),0,s(s(0))):-plus(s(0),0,s(0))....plus(0,s(0),s(0)).plus(s(0),s(0),s(s(0))):-plus(0,s(0),s(s(0))).plus(s(s(0)),s(0),s(s(s(0)))):-plus(s(0),s(0),s(s(0)))....
Semantics
Full clausal logic
49
1.renaming variables so that the two atoms have none in common2.ensuring that the atoms’ predicates and arity correspond3.scanning the subterms from left to right to
(I)find first pair of subterms where the two atoms differ;(a) if neither subterm is a variable, unification fails;(b) else substitute the other term for all occurrences of the variable and remember the partial substitution;
(II) repeat until no more differences found
atoms
plus(s(0),X,s(X)) plus(s(Y),s(0),s(s(Y)))and
have most general unifier
{Y/0, X/s(0))}
found by
Proof Theory (mgu)
yields unified atom plus(s(Y),s(0),s(s(Y)))
Full clausal logic
50
E
repeatselect s = t ∈ Ecase s = t of
f (s1, . . . , sn) = f (t1, . . . , tn) (n ≥ 0) :replace s = t by {s1 = t1, . . . , sn = tn}
f (s1, . . . , sm) = g(t1, . . . , tn) (f/m �= g/n) :fail
X = X :remove X = X from E
t = X (t �∈ Var) :replace t = X by X = t
X = t (X ∈ Var ∧ X �= t ∧ X occurs more than once in E) :if Xoccurs in tthen failelse replace all occurrences of X in E (except in X = t) by t
esacuntil no change
Clausal logic
examples
{f (X , g(Y )) = f (g(Z ), Z )}⇒ {X = g(Z ), g(Y ) = Z}⇒ {X = g(Z ), Z = g(Y )}⇒ {X = g(g(Y )), Z = g(Y )}⇒ {X/g(g(Y )), Z/g(Y )}
{f (X , g(X ), b) = f (a, g(Z ), Z )}⇒ {X = a, g(X ) = g(Z ), b = Z}⇒ {X = a, X = Z , b = Z}⇒ {X = a, a = Z , b = Z}⇒ {X = a, Z = a, b = Z}⇒ {X = a, Z = a, b = a}⇒ fail
52 / 259
Clausal logic
examples
{f (X , g(Y )) = f (g(Z ), Z )}⇒ {X = g(Z ), g(Y ) = Z}⇒ {X = g(Z ), Z = g(Y )}⇒ {X = g(g(Y )), Z = g(Y )}⇒ {X/g(g(Y )), Z/g(Y )}
{f (X , g(X ), b) = f (a, g(Z ), Z )}⇒ {X = a, g(X ) = g(Z ), b = Z}⇒ {X = a, X = Z , b = Z}⇒ {X = a, a = Z , b = Z}⇒ {X = a, Z = a, b = Z}⇒ {X = a, Z = a, b = a}⇒ fail
52 / 259
Proof Theory: mgu using Martelli-Montanari algorithm
= mgu
Full clausal logic
Proof Theory: occur check
51
loves(X,person_loved_by(X)). :- loves(Y,Y).
without occur check, atoms to be resolved upon unify under substitution
{Y/X, X/person_loved_by(X)}
and therefore resolving to the empty clause
BUT...try to print answer:
X=person_loved_by(person_loved_by(person_loved_by(...)))
moreover, not a logical consequence of the program
Full clausal logic
52
Clausal logic
occur check
{l(Y , Y ) = l(X , f (X ))}⇒ {Y = X , Y = f (X )}⇒ {Y = X , X = f (X )}⇒ fail
The last example illustrates the need for the “occur check” (which isnot done in most Prolog implementations)
53 / 259
Martelli-Montanari algorithm SWI-Prolog
?- l(Y,Y) = l(X,f(X)).Y = f(**),X = f(**).?-
?- unify_with_occurs_check(l(Y,Y),l(X,f(X))).false.?-
Proof Theory: occur check
Full clausal logic
53
P⊦C ⇒ P⊧Cfull clausal logic is sound
P∪{C} inconsistent ⇒ P ∪ {C} ⊢ �full clausal logic is refutation-complete
The question “P⊧C?” is only semi-decidable.
Meta-theory: soundness, completeness, decidability
Clausal Logic: Overview
54
Propositional Relational Full
Herbrand universe
Herbrand base
clause
Herbrand models
meta-theory
-
finite infinite
{p, q}
{a,f(a),f(f(a)),...}
{p(a,a), p(b,a),...}
{a,b}
{p(a,f(a)), p(f(a), f(f(a))),...}
p:-q p(X,Z):- q(X,Y),p(Y,Z)
p(X,f(X)):- q(X)
{}{p}{p,q}
{}{p(a,a)}{p(a,a),p(b,a),q(b,a)}...
finite number of finite models
{}{p(a,f(a)),q(a)}{p(f(a),f(f(a)), q(f(a))} ...
infinite number of finite or infinite models
soundrefutation-complete
decidable
soundrefutation-complete
decidable
sound (occurs check)refutation-complete
semi-decidable
Conversion to first-order predicate logic (1)
55
married;bachelor :- man,adult.haswife :- married.
becomes (man ∧ adult ⇒ married ∨ bachelor) ∧(married ⇒ haswife)
(¬man ∨ ¬adult ∨ married ∨ bachelor )∧ (¬married ∨ haswife)
or
reachable(X,Y,route(Z,R)):- connected(X,Z,L), reachable(Z,Y,R).
becomes ∀X∀Y∀Z∀R∀L : ¬connected(X,Z,L) ∨ ¬reachable(Z,Y,R) ∨ reachable(X,Y,route(Z,R))
A ⇒ B ≡ ¬A ∨ B
¬(A ∧ B) ≡ ¬A ∨ ¬B
56
nonempty(X) :- contains(X,Y).
becomes
or
∀X∀Y: nonempty(X) ∨ ¬contains(X,Y)
∀X: (nonempty(X) ∨ ∀Y¬contains(X,Y))
∀X: nonempty(X) ∨ ¬(∃Y:contains(X,Y))or
∀X: (∃Y:contains(X,Y)) ⇒ nonempty(X))or
Conversion to first-order predicate logic (2)
56
Conversion from first-order predicate logic (1)
57
1 eliminate ⇒ using A ⇒ B ≡ ¬A ∨ B.
2Put into negation normal form: negation only occurs immediately before propositions
∀X[brick(X)⇒(∃Y[on(X,Y)∧¬pyramid(Y)]∧ ¬∃Y[on(X,Y) ∧ on(Y,X)]∧ ∀Y[¬brick(Y)⇒¬equal(X,Y)])]
∀X[¬brick(X)∨(∃Y[on(X,Y)∧¬pyramid(Y)]∧ ¬∃Y[on(X,Y)∧on(Y,X)]∧ ∀Y[¬(¬brick(Y))∨¬equal(X,Y)])]
∀X[¬brick(X)∨(∃Y[on(X,Y)∧¬pyramid(Y)]∧ ∀Y[¬on(X,Y)∨¬on(Y,X)]∧ ∀Y[brick(Y)∨¬equal(X,Y)])]
A ⇒ B ≡ ¬A ∨ B
¬(A∧B) ≡ ¬A∨¬B ¬(A∨B) ≡ ¬A∧¬B
¬(¬A) ≡ A¬∀X [p(X)] ≡ ∃X [¬p(X)]¬(∃X [p(X)] ≡ ∀X [¬p(X)]
58
replace ∃ using Skolem functors (abstract names for objects, functor has to be new)
∀X[¬brick(X)∨([on(X,sup(X))∧¬pyramid(sup(X))]∧ ∀Y[¬on(X,Y)∨¬on(Y,X)]∧ ∀Y[brick(Y)∨¬equal(X,Y)])]
∀X[¬brick(X)∨(∃Y[on(X,Y)∧¬pyramid(Y)]∧ ∀Y[¬on(X,Y)∨¬on(Y,X)]∧ ∀Y[brick(Y)∨¬equal(X,Y)])]
Conversion from first-order predicate logic (2)
3
standardize all variables apart such that each quantifier has its own unique variable
∀X[¬brick(X)∨([on(X,sup(X))∧¬pyramid(sup(X))]∧ ∀Y[¬on(X,Y)∨¬on(Y,X)]∧ ∀Z[brick(Z)∨¬equal(X,Z)])]
4
59
∀X[¬brick(X)∨([on(X,sup(X))∧¬pyramid(sup(X))]∧ ∀Y[¬on(X,Y)∨¬on(Y,X)]∧ ∀Y[brick(Y)∨¬equal(X,Y)])]
move ∀ to the front
∀X∀Y∀Z[¬brick(X)∨([on(X,sup(X))∧¬pyramid(sup(X))]∧ [¬on(X,Y)∨¬on(Y,X)]∧ [brick(Z)∨¬equal(X,Z)])]
Conversion from first-order predicate logic (3)
5
60
convert to conjunctive normal form using A∨(B∧C) ≡ (A∨B)∧(A∨C)
∀X∀Y∀Z[(¬brick(X)∨[on(X,sup(X))∧¬pyramid(sup(X))])∧ (¬brick(X)∨[¬on(X,Y)∨¬on(Y,X)])∧ (¬brick(X)∨[brick(Z)∨¬equal(X,Z)])]
∀X∀Y∀Z[¬brick(X)∨([on(X,sup(X))∧¬pyramid(sup(X))]∧ [¬on(X,Y)∨¬on(Y,X)]∧ [brick(Z)∨¬equal(X,Z)])]
∀X∀Y∀Z[((¬brick(X)∨on(X,sup(X)))∧(¬brick(X)∨¬pyramid(sup(X))))∧ (¬brick(X)∨[¬on(X,Y)∨¬on(Y,X)])∧ (¬brick(X)∨[brick(Z)∨¬equal(X,Z)])]
∀X∀Y∀Z[[¬brick(X)∨on(X,sup(X))]∧ [¬brick(X)∨¬pyramid(sup(X))]∧ [¬brick(X)∨¬on(X,Y)∨¬on(Y,X)]∧ [¬brick(X)∨brick(Z)∨¬equal(X,Z)]]
Conversion from first-order predicate logic (4)
6
A∨(B∨C) ≡ A∨B∨C
61
split the conjuncts in clauses (a disjunction of literals)
∀X∀Y∀Z[[¬brick(X)∨on(X,sup(X))]∧ [¬brick(X)∨¬pyramid(sup(X))]∧ [¬brick(X)∨¬on(X,Y)∨¬on(Y,X)]∧ [¬brick(X)∨brick(Z)∨¬equal(X,Z)]]
convert to clausal syntax (negative literals to body, positive ones to head)
∀X ¬brick(X)∨on(X,sup(X))∀X ¬brick(X)∨¬pyramid(sup(X))∀X∀Y ¬brick(X)∨¬on(X,Y)∨¬on(Y,X)∀X∀Z ¬brick(X)∨brick(Z)∨¬equal(X,Z)
on(X,sup(X)) :- brick(X).:- brick(X), pyramid(sup(X)).:- brick(X), on(X,Y), on(Y,X).brick(X) :- brick(Z), equal(X,Z).
Conversion from first-order predicate logic (5)
7
8
∀X: (∃Y:contains(X,Y))⇒ nonempty(X))
∀X: ¬(∃Y:contains(X,Y)) ∨ nonempty(X))1 eliminate ⇒
2 put into negation normal form ∀X: (∀Y:¬contains(X,Y)) ∨ nonempty(X))
5 move ∀ to the front ∀X∀Y: ¬contains(X,Y) ∨ nonempty(X)
8 convert to clausal syntax nonempty(X) :- contains(X,Y)
62
3 replace ∃ using Skolem functors
4 standardize variables
6 convert to conjunctive normal form
7 split the conjuncts in clauses
Conversion from first-order predicate logic (6)
Definite Clausal Logicmarried(X);bachelor(X) :- man(X), adult(X).man(peter). adult(peter). man(paul).:-married(maria). :-bachelor(maria). :-bachelor(paul).
63
clause is used from right to left
clause is used from left to right
both literals from head and body are resolved
away
married(X);bachelor(X) :- man(X), adult(X). man(peter).
married(X);bachelor(X) :- man(peter), adult(peter). adult(peter).
married(peter);bachelor(peter)
married(X);bachelor(X) :- man(X), adult(X). :-married(maria).
bachelor(maria) :- man(maria), adult(maria). :-bachelor(maria).
:-man(maria);adult(maria)
married(X);bachelor(X) :- man(X), adult(X). man(paul).
married(paul);bachelor(paul) :- adult(paul). :-bachelor(paul).
married(paul):-adult(paul)
Syntax and Proof Procedure
64
A :- B1,...,Bn
full clausal logic clauses are restricted: at most one atom
in the head
from right to left:! procedural interpretation
“prove A by proving each of Bi“
rules out indefinite conclusions fixes direction to use clauses
for efficiency’s sake
Full clausal logic
Lost Expressivity
married(X); bachelor(X) :- man(X), adult(X).man(john). adult(john).
65
We can no longer express
which had two minimal models
{man(john),adult(john),married(john)}{man(john),adult(john),bachelor(john)}{man(john),adult(john),married(john),bachelor(john)}
first model is minimal model of general clause
married(X) :- man(X), adult(X), not bachelor(X).
second model is minimal model of general clause
bachelor(X) :- man(X), adult(X), not married(X).
Full clausal logic