Information Technology Reference
In-Depth Information
It is worth observing that if one reads the query
\+ female(gina)
as saying that
Gina is not female, then the conclusions from Prolog are no longer
logically sound
.
Although the query succeeds, it is
not
the case that the family knowledge base
logically entails that Gina is not female; the sex of Gina is left unspecified.
3.2.4 Tracing the back-chaining
In
considering
an
extended
version
of
back-chaining
to
handle
negation,
it
is
worthwhile to follow how Prolog answers conjunctive queries with negation like
parent(X,john), \+ female(X).
to see how Prolog ends up with the answer
X = sam
.
1.
Start by replacing variables in the query with new names to make sure that they
do not conflict with any variables that appear in the Prolog program:
parent(_G312,john), \+ female(_G312).
2.
Work on the first atom in the query,
parent(_G312,john)
. Find the clause
parent(Y,X) :- child(X,Y)
in the program (figure 3.1) whose head matches
the first atom in the query. This leaves the conjunctive query
child(john,_G312), \+ female(_G312).
to work on. (The second part of the query is kept unchanged.)
3.
Work on the first atom of the new query,
child(john,_G312)
. Find a matching
clause
child(john,sue)
with no body in the program (figure 3.1). Tentatively,
this part of the query is finished. This leaves the query
\+ female(sue).
(Note that the
child(john,sue)
clause in the program was a bad choice. It will
be necessary to backtrack, but that is not known yet.)
4.
Work on
\+ female(sue)
. Since this is a negated query, remove the
\+
and
consider the unnegated version.
a.
Work on the query
female(sue)
, and find a matching atomic sentence in the
program. Return
success
.
Since the unnegated version succeeds, the negated query
fails
. Backtrack to the
most recent choice point (step 3) and reconsider.