[X|[a,b]] = [Y,a,B].
% B = b
% X = Y
f(g(0),X) = f(X,g(Y)).
% X = g(0) , from the unifcation of the first argument
% Y = 0 , because X = g(Y) means g(0) = g(Y)
z(k(0),X) = z(k(X),s(0)).
% Does not unify!
% because X the first equation needs X = 0 and the second needs X = s(0) and
% 0 = s(0) does not unify
c(X,Y) = c(Z,Z).
%because the firste argument and second both need to unify to Z
%the answer is
%X = Y, Y = Z
% 3b1
%need two cases, one where X:mother Y:father, and one for X:father Y:mother
%we can ignore the name and the year of birth, so use _
parents(X,Y) :- person(_, X, Y, _).
parents(X,Y) :- person(_, Y, X, _).
% 3b2
%need to check for \== too be sure that Partner1 and Partner2 is not the same partner
itscomplicated(X) :- parents(X,Partner1), parents(X,Partner2), Partner1 \== Partner2.
%3c1
%create a max predicate to make things easier
max(A, B, A) :- A >= B.
max(A, B, B) :- B > A.
depth(empty, 0).
depth(node(L,_,R), N) :-
depth(L, LeftDepth), %find depth of left subtree
depth(R, RightDepth),%find depth of right subtree
max(LeftDepth, RightDepth, MaxDepth), %find maximum of the two depths
N is MaxDepth + 1. %the depth of the tree is 1 + the maximum of the two depths
%3c2
heap(empty, 0).
heap(node(empty, _, empty), 1).
heap(node(node(empty,LeftSubtreeValue,empty), Value, empty), 2) :-
LeftSubtreeValue =< Value.
heap(node(node(LL, LV, LR), V, node(RL,RV,RR)), N) :-
heap(node(LL, LV, LR), LD), % L is a heap
heap(node(RL, RV, RR), RD), % R is a heap
LV =< V, % left top value <= V
RV =< V, % right top value <= V
(LD =:= RD ; LD - 1 =:= RD), %if L has depth D, then R has depth D or D-1
N is LD + 1. %maximum of the two branches will always be the left depth