What's with subset/2?

I think that this has been already discussed here in the context of ord_subset/2. As long as you represent the set as list, the same considerations apply. For any list without repetitions the set of subsequences of the list is the same as the set of subsets. The gist of it (excerpt from the linked post):

list_subseq_1([], _).
list_subseq_1([X|Xs], L) :-
    append(_, [X|Rest], L),
    list_subseq_1(Xs, Rest).

So, for a subsequence you can use append/3, instead of member/2 and select/3 or delete/3 and so on.

For your example, I get:

?- list_subseq([1,2,3], [A,B]).
A = 1, B = 2 ;
A = 1, B = 3 ;
A = 2, B = 3 ;
false.
1 Like