%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% family.pl      (L. McCann, September 2004)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%
% Facts that define a simple family tree. 
% --------------------------------------------------------------------

parent(hank,ben).
parent(hank,denise).
parent(irene,ben).
parent(irene,denise).
parent(alice,carl).
parent(ben,carl).
parent(denise,frank).
parent(denise,gary).
parent(earl,frank).
parent(earl,gary).

%
% Rules that tell Prolog about family relationships
% --------------------------------------------------------------------

     % The parent of a parent is a grandparent.

grandparent(X,Z) :- parent(X,Y) , parent(Y,Z).

     % Two things are siblings if they share a parent and are not the same

sibling(X,Y) :- parent(Z,X) , parent(Z,Y) , X \= Y.

     % Your parent is one of your ancestors

ancestor(X,Y) :- parent(X,Y).

     % X is Y's ancestor if X is also an ancestor of Y's parent (Z)

ancestor(X,Y) :- parent(Z,Y) , ancestor(X,Z).
