Jump to content

Power set: Difference between revisions

→‎Logical (cut-free) Definition: clarify meaning of efficiency
m (→‎Logical (cut-free) Definition: remove redundant comment)
(→‎Logical (cut-free) Definition: clarify meaning of efficiency)
Line 1,712:
The predicate subseq(X,Y) is true if and only if the list X is a subsequence of the list Y.
 
The specificationsdefinitions here are elementary, logical (cut-free), and efficient (within the class of comparably generic implementations).
<lang Prolog>powerset(X,Y) :- bagof( S, subseq(S,X), Y).
powerset(X,Y) :- bagof( S, subseq(S,X), Y).
 
subseq( [], []).
Line 1,722 ⟶ 1,721:
</lang>
Output :
<pre> ?- powerset([1,2,3], X).
<pre>
?- powerset([1,2,3], X).
X = [[], [1], [1, 2], [1, 2, 3], [1, 3], [2], [2, 3], [3]].
</pre>
2,511

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.