Gegevensbanken
Download
Report
Transcript Gegevensbanken
Applied Computer Science II
Resolution in FOL
Luc De Raedt
1
Clausal Form
Clauses are universally quantified
disjunctions of literals; all variables in a
clause are universally quantified
(x1 ,..., xn )(l1 ... ln )
written as
l1 ... ln
or
{l1 ,..., ln }
2
Towards Resolution
• Examples:
{Nat(s(A)),Nat(A)} {Nat(s(A)),Nat(A)}
{Nat(A)}
{Nat(x)}
gives
gives
{Nat(s(A))}
{Nat(s(A))}
{Nat(s(s(x))),Nat(s(x))}
{Nat(s(A))}
gives
{Nat(s(s(A)))}
• We need to be able to work with variables !
• Unification of two expressions/literals
3
Terms and instances
• Consider following atoms
P(x,f(y),B)
P(z,f(w),B) alphabetic variant
P(x,f(A),B) instance
P(g(z),f(A),B) instance
P(C,f(A),A) not an instance
• Ground expressions do not contain any variables
4
A substitution s {v1 / t1 ,..., vn / tn } substitutes
Substitution
terms ti for variables vi ( ti does NOT contain vi )
Applying a substitution s to an expression
yields the expression s which is
with all occurrences of vi replaced by ti
P(x,f(y),B)
P(z,f(w),B)
P(x,f(A),B)
s ={x/z,y/w}
s ={y/A}
P(g(z),f(A),B)
s ={x/g(z),y/A}
P(C,f(A),A)
no substitution !
5
Composing substitutions
• Composing substitutions s1 and s2 gives s1 s2
which is that substitution obtained by first
applying s2 to the terms in s1and adding
remaining term/vars pairs to s1
{z/g(x,y)}{x/A,y/B,w/C,z/D}=
{z/g(A,B),x/A,y/B,w/C}
• Apply to
P(x,y,z)
gives
P(A,B,g(A,B))
6
s
Properties of substitutions
( s1 ) s2 ( s1s2 )
( s1s2 ) s3 s1 (s2 s3 ) associativity
s1s2 s2 s1 not commutative
7
Unification
• Unifying a set of expressions {wi}
– Find substitution s such that wi s wj s for all i, j
– Example
{P(x,f(y),B),P(x,f(B),B)}
s ={y/B,x/A} not the simplest unifier
s ={y/B} most general unifier (mgu)
• The most general unifier, the mgu, g of {wi} has
the property that if s is any unifier of {wi} then
there exists a substitution s’ such that
{wi}s={wi}gs’
• The common instance produced is unique up to
alphabetic variants (variable renaming)
8
Disagreement set
The disagreement set of a set of expressions
{wi} is the set of subterms { ti } of {wi} at
the first position in {wi} for which the {wi}
disagree
{P(x,A,f(y)),P(w,B,z)} gives {x,w}
{P(x,A,f(y)),P(x,B,z)} gives {A,B}
{P(x,y,f(y)),P(x,B,z)} gives {y,B}
9
Unification algorithm
Unify(Terms)
Initialize k 0;
Initialize Tk Terms;
Initialize k {};
* If Tk is a singleton, then output k . Otherwise, continue.
Let Dk be the disagreement set of Tk
If there exists a var vk and a term tk in D k such that vk
does not occur in tk , continue. Otherwise, exit with failure.
k 1 k {vk / tk };
Tk 1 Tk {vk / tk };
k k 1;
Goto *
10
Predicate calculus Resolution
John Allan Robinson (1965)
Let C1 and C2 be two clauses with
literals l1 C1 and l2 C2 such that
C1 and C2 do not contain common variables,
and mgu (l1 , l2 )
then C [{ C1 {l1}} {C2 {l2 }}]
is a resolvent of C1 and C2
11
Example
P(x) Q(f(x)) and R(g(x)) Q(f(A))
Standardizing the variables apart
P(x) Q(f(x)) and R(g(y)) Q(f(A))
Substitution ={x/A}
Resolvent P(A) R(g(y))
P(x) Q(x,y) and P(A) R(B,z)
Standardizing the variables apart
Substitution ={x/A}
Resolvent Q(A,y) R(B,z)
12
A stronger version of resolution
Use more than one literal per clause
{P(u),P(v)} and {P(x),P(y)}
do not resolve to empty clause.
However, ground instances
{P(A)} and {P(A)} resolve to empty clause
13
Factors
Let C1 be a clause such that there exists
a substitution that is a mgu of a set of literals
in C1. Then C1 is a factor of C1
Each clause is a factor of itself.
Also, {P(f(y)),R(f(y),y)}is a factor of {P(x),P(f(y)),R(x,y)}
with {x / f ( y )}
14
Resolution
Let C1 and C2 be two clauses and let
C1' and C2 ' be factors of C1 and C2 that do not common variables,
literals l1 C1' and l2 C2' such that
mgu (l1 , l2 )
then C [{ C '1 {l1}} {C2 ' {l2 }}]
is a resolvent of C1 and C2
15
Resolution
• Properties
– Resolution is sound
• If there is a resolution derivation of a clause C from a database
KB of clauses, then KB |=c
– Incomplete
Given P(A)
Infer {P(A),P(B)}
– But fortunately it is refutation complete
• If KB is unsatisfiable then KB |-
16
Refutation
To decide whether a formula KB |= w do
• Convert KB to clausal form KB’
• Convert w to clausal form w’
• Combine w’ and KB’ to give
• Iteratively apply resolution to and add the
results back to until either no more
resolvents can be added, or until the empty
clause is produced.
17
18
Answer extraction
Suppose we wish to prove whether KB |=
(w)f(w)
We are probably interested in knowing the w
for which f(w) holds.
Add Ans(w) literal to each clause coming
from the negation of the theorem to be
proven; stop resolution process when there
is a clause containing only Ans literal
19
{1 \ 0}
{0 \ 1}
20
21
22
Resolution Search Strategies
• Ordering strategies
– In what order to perform resolution ?
– Breadth-first, depth-first, iterative deepening ?
– Unit-preference strategy :
• Prefer those resolution steps in which at least one clause is a
unit clause (containing a single literal)
• Refinement strategies
– Input : at least one of the clauses being resolved is a
member of the original set of clauses
• (complete for horn clauses, incomplete in general)
24
• Refinement strategies (ctd.)
– Linear : at least one of the parents is a member of the
original set of clauses or is an ancestor of the other
parent
• Refutation complete
– Ancestor : c2 is a descendant of c1 iff c2 is a resolvent
of c1 (and another clause) or if c2 is a resolvent of a
descendant of c1 (and another clause); c1 is an
ancestor of c2
– Set of support : the set of clauses coming from the
negation of the theorem (to be proven) and their
descendants
– Set of support strategy : require that at least one of the
clauses in each resolution step belongs to the set of
support
25
Herbrand base and
interpretations
Let KB be a set of clauses.
Let O( KB) denote the set of constants in KB, if there
are no constant symbols, then O( KB ) { A}
Let F ( KB)denote the set of function symbols.
Let P( KB )denote the set of predicate symbols.
Now, the Herbrand Universe H ( KB) is the set of
all legal ground terms that can be formed using O( KB)
and F ( KB).
A Herbrand interpretation for a set of clauses KB
is an interpretation that
1) has H ( KB)as its domain
2) assigns true or false to all ground atoms
27
The Herbrand base for a set of clauses KB
is the set of ground clauses obtained by replacing
the variables in KB by all terms in the Herbrand Universe
Theorem (Herbrand's theorem)
If a finite set of clauses KB is unsatisfiable
then the Herbrand base for KB is unsatisfiable.
28
Conclusions
• Logic
– A sound basis for reasoning, modeling and
computer science
– Syntax and Semantics
– Propositional and First Order
– Soundness and Completeness
– Resolution
29