1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
male(tom). male(jim). male(alex). male(theo). male(joe). female(mary). female(betty). female(alice). female(dorothy). female(jill). parent(alice, mary). parent(tom, jim). parent(betty, jim). parent(mary, alex). parent(tom, alex). parent(dorothy, tom). parent(dorothy, theo). parent(mary, joe). parent(tom, joe). parent(theo, jill). mother(M, C) :- parent(M, C), female(M). grandparent(GP, GC) :- parent(GP, X), parent(X, GC). ancestor(A, D) :- parent(A, D). ancestor(A, D) :- parent(A, D1), ancestor(D1, D). sibling(X, Y) :- parent(P, X), parent(P, Y), X \= Y. cousin(X, Y) :- grandparent(G, X), grandparent(G, Y), X \= Y, \+sibling(X, Y). |
Other examples used in class are at the Prolog Tutorial website.