% intersection(A, B, C) where C is the intersection of A and B intersection([], _, []). intersection([X|R], Y, [X|Z]) :- member(X, Y), intersection(R, Y, Z). intersection([X|R], Y, Z) :- \+ member(X, Y), intersection(R, Y, Z). % union(A, B, C) where C is the union of A and B union([], X, X). union([X|R], Y, Z) :- member(X, Y), union(R, Y, Z). union([X|R], Y, [X|Z]) :- \+ member(X, Y), union(R, Y, Z). member(X, [X|_]). member(X, [_|Y]) :- member(X, Y).