%%% 05.02.2012

%% Task 1
% L - a list of numbers
% M - a sublist of L

%% is_member(X, L) :- Checks if X is from L
is_member(H, [H|_]).
is_member(H, [_|T]) :- is_member(H, T).

%% subset(L, M) :- Checks if L is a subset of M
subset(L, M) :- not((is_member(E, L), not(is_member(E, M)))).

%% gensubset(L, M) :- Generates all subsets of M in L 
gensubset([], []).
gensubset([H|T], [H|S]) :- gensubset(T, S).
gensubset(T, [_|S]) :- gensubset(T, S).

%% p(L, M) :-
%p(L, M) :- gensubset(M, L), not((
%                                  is_member(X, M),
%                                  not(is_member(Y, M)),
%                                  A is X - Y, B is X * Y, C is X + Y,
%                                  not(subset([A, B, C], L))
%                        		 	  )).

%% doesn't work
p(L, M) :- gensubset(M, L), not((
  is_member(X, M),
  not(is_member(Y, M)),
  not(subset([X-Y, X*Y, X+Y], L)))).