Union of two sets. ?- union([a,b,c],[d,e,f],[a,b,c,d,e,f]). true. ?- union([a,b,c],[d]). false. ?- union([a,b,c],[c,d,e],R). R = [a,b,c,d,e]. myunion([],X,X):-!. myunion([X|R],Y,Z):- member(X,Y),myunion(R,Y,Z),!. myunion([X|R],Y,[X|Z]):- myunion(R,Y,Z).
Intersection of two sets. ?- intersection([],[a,b,c],[]). true. ?- intersection([a,b,c],[c,d],[c]). true. ?- intersection([a,b,c],[b,c,d],R). R = [b,c]. intersect([],X,[]):- !. intersect([X|R],Y,[X|T]):- member(X,Y),intersect(R,Y,T),!. intersect([X|R],Y,L):- intersect(R,Y,L).