Power set: Difference between revisions
Content deleted Content added
m →Logical (cut-free) Definition: remove redundant comment |
→Logical (cut-free) Definition: clarify meaning of efficiency |
||
Line 1,712: | 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 predicate subseq(X,Y) is true if and only if the list X is a subsequence of the list Y. |
||
The |
The definitions here are elementary, logical (cut-free), and efficient (within the class of comparably generic implementations). |
||
<lang Prolog> |
<lang Prolog>powerset(X,Y) :- bagof( S, subseq(S,X), Y). |
||
powerset(X,Y) :- bagof( S, subseq(S,X), Y). |
|||
subseq( [], []). |
subseq( [], []). |
||
Line 1,722: | Line 1,721: | ||
</lang> |
</lang> |
||
Output : |
Output : |
||
⚫ | |||
<pre> |
|||
⚫ | |||
X = [[], [1], [1, 2], [1, 2, 3], [1, 3], [2], [2, 3], [3]]. |
X = [[], [1], [1, 2], [1, 2, 3], [1, 3], [2], [2, 3], [3]]. |
||
</pre> |
</pre> |