I know this old post, but I am not going to update it for no reason. the answer, which is accepted with all due respect, generates all subsets separably and does not generate a set of credentials.
a few days ago, I tried to implement the powerSet/2 predicate without using the built-in bagof/2 predicate. but even with bagof/2 and setof/2 this is not a very simple task for beginners (generating the entire subset is separable is another problem and is much simpler). therefore, after implementing the solution, I thought it was better to put it here so that people who were looking for this topic were not mistaken.
My solution (without bagof/2 )
generate (X, [Y], [[X | Y]]).
generate (X, S, P): -
S = [H | T]
append ([X], H, Temp),
generate (X, T, Rest),
append ([Temp], Rest, P),!.
powerSet ([], [[]]).
powerSet (Set, P): -
Set = [H | T]
powerSet (T, PsT),
generate (H, PsT, Ps),
% write ('trying to push'), print (H), write ('to'),
% write ('all elements of powerset of'), print (T), write ('which is'),
% print (PsT), nl,
% write ('and the result is'), print (Ps), nl, nl,
append (Ps, PsT, P),!.
the code will be understood by referring to the comments.
another solution is available here , which uses the built-in predicate bagof/3 .
perhaps now it would be more useful.