Given a set of facts, we can ask questions about them by inserting variables where there was a constant:
mother (peggy, george).
mother (peggy, jill).
father (robert, mary).
father (robert, george).
?mother(J, george). => J = peggy.
?mother(peggy,H). => H = george; H = jill.
?father(P, Q). => P = robert, Q = mary; P = robert, Q = george.
- Even though the facts are written in such a way that the name of the predicate implies a one-way relationship, in fact the SAME fact can be used to determine a "child" relationship as in the second case above.
- Where there is more than one possible answer to a question, Prolog will locate all possible answers.
Testing for equality is extremely simple:
as a fact!
Then we can define not equal by the rule
notequal(X,Y) :- not equal(X,Y).
Last Updated 03/27/2000
J.A.N. Lee, 2000