HOW PROLOG REACHES SOLUTIONS USING THEOREM

advertisement
HOW PROLOG REACHES SOLUTIONS USING THEOREM
PROVING BY MEANS OF RESOLUTION
Preliminary Relations.
In the relations below X, Y Z, V are variables for some object (out of some
unspecified, possibly infinite, set of objects) and p,q,r are variables for
predicates, while e.g. p(X) is a predicate with variable X.
┐p means (not p), i.e. p is untrue. p is an alternate notation for (not p)
A.
p and q has the same truth value (true or false) as ( p or q)
This can be shown by considering all 4 combinations of p and q being true or
false. (De Morgan’s law.)
B. (p if q) has the same truth value as (p or q)
This also can be shown by considering all 4 possible combinations of p and q
being true or false.
C. Given that (p or q) and (p or r) are both true, we can conclude that
(q or r) is true by considering both the cases where p is true and is false.
Futhermore, if
p(X) or q(Y)
is true for all X and Y
and
p(Z) or r(V)
is true for all Z and V
then this last formula must also be true when Z =X, giving
p(X) or r(V)
and we so deduce
q(Y) or r(V)
This type of deduction is called resolution, and below we depict it graphically:
p(X) or q(Y)
p(Z) or r(V)
substituting Z → X
q(Y) or r(V)
D. To say that p(X) is true for all X, has the same truth value as
as saying that there isn’t any object X for which p(X) is false.
i.e. (for all x) ( p(X) ) has the same truth value as
┐(there
exists x) ( p(x) )
We will illustrate the process of theorem proving via the following example, in
which the intended reference
by
g(Y, X) is that Y is a grandfather of X
and by
p(Y, X) is that Y is a parent of X
and by
s(Y, X) is that Y is a sister of X
Given the following 5 rules:
1. g(G, X) :- p(G,P), p(P,x).
This means:
for all G and X the following is true:
G is the grandfather of X
if there exists P such that G is the parent of P and P is the parent of X.
2. p(P2, X2) :- s(S,X2), p(P2,S).
This means:
for all P2 and X2 the following is true:
P2 is a parent of X2
if there exists S such that S is the sister of X2 and P2 is a parent of S.
3. s(hannah, John).
4. p(george, Hannah).
5. p(miles, george).
?:- g(T, john).
which means Hannah is a sister of John
which means George is a parent of Hannah
which means Miles is a parent of George
The query: who is the grandfather of John?
Rule 1 can be expressed as:
(for all G and X) ( g(G,X) if (there exists P) { p(G,P) and p(P,X) }
)
Using relation B, we get:
(for all G and X) ( g(G,X) or (there exists P) { p(G,P) and p(P,X) }
)
ie. (for all G and X) ( g(G,X) or
Using relation D, we get:
(for all G and X) ( g(G,X) or
┐
┐ ┐
(there exists P) { p(G,P) and p(P,X) }
(for all P) { p(G,P) and p(P,X) }
)
The two “nots” ┐ ┐ cancel each other out, and using relation A, we get:
(for all G and X) ( g(G,X) or (for all P) { p(G,P) or p(P,X) } )
Since P does not occur in g(G,X), we can express the above as:
(for all G, X and P) ( g(G,X) or { p(G,P) or p(P,X) } )
i.e.
(for all G, X,and P) ( g(G,X) or p(G,P) or p(P,X)
We write this as just:
New 1.
g(G,X) or p(G,P) or p(P,X)
with the prefix “(for all G, X, and P)” implied.
)
)
By similar reasoning, Rule 2 can be expressed as:
New 2.
p(P2,X2) or s(S,X2) or p(P2,S).
These are the versions of rules 1 and 2 that we will refer to below.
To find who the grandfather of John is, we consider as an additional rule:
nobody is the grandfather of John! i.e.:
6.
G(T, john)
which means, for all T, T is not the grandfather of John
We then show that this statement is inconsistent with the other 5 given rules by
demonstrating that we can then derive, using resolution, that some statement is
true, as well as derive that it is false. The series of substitutions this involves to
produce this contradiction, will in effect supply a value of T for which G(T,john) is
true. This is shown in graphical form on the next page.
In this graphical representation the blue numbers indicating the rules involved:
6
1
g(T,John)
g(G,X) or p(G,P) or p(P,X)
T→ G
X→ john
2
p(G,P) or p(P,john)
p(P2, X2) or s(S,X2) or p(P2,S).
P2→ P
X2→ john
3
p(G,P) or s( S,John) or p(P,S)
s(hannah, john)
S→hannah
p(G,P) or p(P,hannah)
4
p(george, Hannah)
P→ george
p(G,george)
G→ Miles
P(miles,george) in contradiction to rule 5: P(miles,george)
The sequence of substitutions that led to this contradiction, starting with
the T in the introduced rule 6 (that for no T is g(T,john) ) was:
T → G → miles
So we conclude that in fact g(miles,John) is true, i.e. miles is the
grandparent of John.
Download