% family.pl % British Royal Family mother(victoria, edward). father(albert, edward). mother(victoria, alice). father(albert, alice). % Greek Gods father(zeus, ares). mother(hera, ares). father(ares, harmonia). mother(aphrodite, harmonia). father(cadmus, semele). mother(harmonia, semele). father(zeus, dionysus). mother(semele, dionysus). % Rules parent(X,Y) :- mother(X,Y). parent(X,Y) :- father(X,Y). /* This one loops ancestor(X,Y) :- parent(X,Y). ancestor(X,Y) :- ancestor(X,Z), parent(Z,Y). */ ancestor(X,Y) :- parent(X,Y). ancestor(X,Y) :- parent(X,Z), ancestor(Z,Y). sibling(X,Y) :- mother(M,X), mother(M,Y), X \== Y, father(F,X), father(F,Y). halfsibling(X,Y) :- parent(Z,X), parent(Z,Y), X \== Y, \+ sibling(X,Y). /* Example run: % prolog SICStus 3.7: Tue Sep 08 19:55:50 MET DST 1998 Licensed to cs.rutgers.edu | ?- [family]. {consulting family.pl...} {family.pl consulted, 10 msec 3464 bytes} yes | ?- ancestor(zeus,D). D = ares ? ;;  D = dionysus ? ; D = harmonia ? ; D = semele ? ; D = dionysus ? ; no | ?- ancestor(A,alice). A = victoria ? ; A = albert ? ; no | ?- sibling(X,Y). X = edward, Y = alice ? ; X = alice, Y = edward ? ; no | ?- halfsibling(X,Y). X = ares, Y = dionysus ? ; X = dionysus, Y = ares ? ; no | ?- halt. */