An example of Prolog


next up previous contents
Next: Clauses
Up: Introduction to Prolog for Mathematicians
Previous: Types of declarative language

An example of Prolog

We describe relations on trees. The tree is stored as a sequence of unconditional facts:

is_a(abel,male).
is_a(adam,male).
... etc ...

is_a(amanda,female).
is_a(anjali,female).
... etc ...

is_father_of(abel,bert).
is_father_of(abel,belinda).
... etc ...

is_mother_of(anjali,bill).
is_mother_of(anjali,bridget).
... etc ...


is_grandparent_of(X, Z) :-
    is_parent_of(X, Y),
    is_parent_of(Y, Z).


is_parent_of(X, Y) :-
    is_mother_of(X, Y).

is_parent_of(X, Y) :-
    is_father_of(X, Y).


is_half_sister_of(X, Y) :-
    is_a(X, female),
    is_parent_of(Z, X),
    is_parent_of(Z, Y),
    X \= Y.



Jocelyn Ireson-Ireson-Paine
Mon Jul 17 22:27:41 BST 1995