%the family.pl program
%sister, brother, aunt, uncle, nephew, niece, cousin, second_cousin, etc.

%Solution:

% X is a sister of Y if
sister(X, Y):- female(X), sibling(X,Y).

brother(X,Y):- male(X), sibling(X,Y).
    
uncle(X,Y):- brother(X,Z), parent(Z,Y).

aunt(X,Y):- sister(X,Z), parent(Z,Y).

nephew(X,Y):- male(X), uncle(Y,X). 
nephew(X,Y):- male(X), aunt(Y,X).

niece(X,Y):- female(X), uncle(Y,X).
niece(X,Y):- female(X), aunt(Y,X).

% X is the cousin of Y
cousin(X,Y) :- parent(Z,X),parent(V,Y),sibling(Z,V).

second_cousin(X,Y) :- grandparent(Z,X), grandparent(V,Y),
                      sibling(Z,V).


%Note: the predicate sibling gives duplicate solutions when two siblings share two parents. 
