Information Technology Reference
In-Depth Information
as, “Two people are of opposite sex if one of them is male and the other is female.”
But what the single clause actually says is, “ x is of opposite sex from y if x is male
and y is female.” It says nothing about the converse, so that information is missing.
This is a very easy thing to overlook. It might only come to light when a query like
opp_sex(jane,sam) does not produce the expected answer.
Consider the my_predicate clause. How can one tell whether there are enough
clauses for it. Again, it depends on what the predicate was intended to mean. From
the comment it appears that a second clause is needed:
% my_predicate(X,Y) holds when X is a child of Y, or vice versa.
my_predicate(X,Y) :- child(X,Y).
my_predicate(X,Y) :- child(Y,X).
With that second clause, the program matches what was intended.
So a Prolog program must include enough clauses to spell out the whole truth.
There are two additional points to remember:
A program might not contain all possible truths about a matter. The family pro-
gram did not include the parents of George, for instance. So some truths might
be missing, for a variety of good reasons. This must be accepted, and sometimes
documented with comments.
But a program must include all relevant truths, explicitly or implicitly. Consider
the truth that Sue is a parent of John. Nowhere is the clause parent(sue,john )
in the program. The reason is that this clause can be derived from other clauses
using back-chaining; its truth is represented implicitly by the program. So to
capture the whole truth, one needs to allow for the fact that some of it will be
calculated by back-chaining over the knowledge base.
In summary, when writing Prolog programs, all the clauses in a Prolog program
must be true, and all the necessary clauses must be represented somehow in the
program in a way that Prolog can find them using back-chaining.
Writing a Prolog program involves building a knowledge base of clauses that
captures
1.
the truth, and nothing but,
2.
the whole truth,
3.
in a form suitable for back-chaining.
Saying that a program is logically correct means that it is correct with respect to gram-
mar and to truth: it has exactly the right logical entailments. Saying that a program is
 
Search WWH ::




Custom Search