Information Technology Reference
In-Depth Information
of Sue.” The programmers put that atom in the program because they believed, or
were willing to assume, that the corresponding English sentence was true. If they had
thought that John was a child of Gina, they would have put child(john,gina) in the
program instead.
Similarly, the program had the clause
parent(Y,X) :- child(X,Y).
because its creators took the English sentence “If x is a child of y , then y is the parent
of x ” to be true. If, instead, they had used the clause
parent(X,Y) :- child(X,Y).
Prolog would not have complained; the clause is grammatically correct. The trouble
is that the results would say that John is both a child and a parent of Sue. Garbage in,
garbage out. So the clause is not correct because the English sentence “If x is a child
of y , then x is a parent of y ” is not true.
Suppose the following is in the program:
my_predicate(X,Y) :- child(X,Y).
Is the corresponding sentence true? It depends on what my_predicate means. It is
always a good idea to include comments in the program to help anyone reading it
(including yourself) to understand what was meant:
% my_predicate(X,Y) holds when X is a child of Y, or vice versa.
my_predicate(X,Y) :- child(X,Y).
Now, at least, it is clear that the corresponding sentence is true.
4.1.2 The whole truth
However, it is not enough to make sure that all the clauses are true. If the
program includes the clause child(john,sue) but does not include the clause
child(john,sam) , it will still not work properly. A query asking if Sam is a par-
ent of John will not get a good answer even if all the clauses are true (that is, if the
sentences they represent are true). The problem is that part of the truth is missing .
Consider, for example, the two clauses in the family example about opp_sex :
opp_sex(X,Y) :- male(X), female(Y).
opp_sex(Y,X) :- male(X), female(Y).
Suppose the second one had been left out. On the surface, everything looks fine. The
program is grammatically correct (Prolog loads it normally), and every clause in the
program is true. If one didn't look too carefully, one might read the single clause
 
Search WWH ::




Custom Search