I think your last procedure should read
%checks if each sublist of a given list of lists, has the sum of elements S
check([], [], _).
%the LR variable here gives a warning after entering the goal
check([H|T], [H|LR], S):-
sum(H, S),
!, check(T, LR, S).
check([_|T], LR, S):-
check(T, LR, S).
and then, some note:
- why generate all subsets, then filter out ? 'push' the test inside findall, it's easier and faster
- you have a sum/2 predicate that could be much more useful if it does what it says to do. Here is it:
--
% sum elements of a list
sum([], 0).
sum([H|T], S):-
sum(T, N),
S is N+H.
(to be true, I tested using this one, getting [[1,6],[2,5]]
)