father(frank, jane). father(james, anne). father(john, frank). father(james, sarah). father(frank, tim). mother(anne, jane). mother(betty, frank). mother(anne, tim). parent(P, C) :- father(P, C). parent(P, C) :- mother(P, C). parents(C, M, F) :- mother(M,C), father(F,C). grandparent(G, C) :- parent(G, P), parent(P, C). sibling(A, B) :- parent(P, A), parent(P, B). sibling(A, B) :- parent(P, A), parent(P, B), A \== B. full_sibling(A, B) :- father(F, A), father(F, B), mother(M, A), mother(M, B), A \== B. orphan(C) :- \+ parent(_, C). ancestor(A, D) :- parent(A, P), ancestor(P, D). ancestor(P, C) :- parent(P, C). % all_equal(A, L) all elements of the list L are A all_equal(_, []). all_equal(A, [A|L]) :- all_equal(A, L). same_length([], []). same_length([_|L1], [_|L2]) :- same_length(L1, L2). convert_to(_, [], []). convert_to(A, [_|List], [A|AList]) :- convert_to(A, List, AList). my_reverse([], []). my_reverse([A|L1], L2) :- my_reverse(L1, L1rev), append(L1rev, [A], L2). % all_fathers(CS, FS) true if FS are the respective fathers of CS. all_fathers([], []). all_fathers([C|CS], [F|FS]) :- father(F, C), all_fathers(CS, FS).