father(frank, jane). father(james, anne). father(frank, tim). father(john, frank). mother(anne, jane). mother(betty, frank). parent(P, C) :- father(P, C). parent(P, C) :- mother(P, C). parents(F, M, C) :- father(F, C), mother(M, C). grandparent(G, C) :- parent(G, P), parent(P, C). sibling(A, B) :- parent(P, A), parent(P, B), A \= B. orphan(C) :- \+ parent(_, C). ancestor(A, D) :- parent(A, P), ancestor(P, D). % ancestor(P, C) :- parent(P, C). ancestor(P, P). all_equal(_, []). all_equal(A, [A|Tail]) :- all_equal(A, Tail). same_length([], []). same_length([_|A], [_|B]) :- same_length(A, B). my_reverse([], []). my_reverse([A|Tail], Rev) :- my_reverse(Tail, RevTail), append(RevTail, [A], Rev). all_fathers([], []). all_fathers([F|FS], [C|CS]) :- father(F, C), all_fathers(FS, CS).