up previous next
subsets    --    returns all sublists of a list


Syntax
subsets(S: LIST): LIST
subsets(S: LIST, N: INT): LIST

Description
This function computes all sublists (subsets) of a list (set). If N is specified, it computes all sublists of cardinality N.

Example
/**/  subsets([1, 4, 7]);
[[ ],  [7],  [4],  [4, 7],  [1],  [1, 7],  [1, 4],  [1, 4, 7]]

/**/  subsets([1, 4, 7], 2);
[[1, 4],  [1, 7],  [4, 7]]

/**/  subsets([2,3,3]);                 -- list with repeated entries
[[ ],  [3],  [3],  [3, 3],  [2],  [2, 3],  [2, 3],  [2, 3, 3]]

/**/  subsets(MakeSet([2,3,3]));
[[ ],  [3],  [2],  [2, 3]]

See Also