subsets - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

# Online Help

###### All Products    Maple    MapleSim

combinat

 subsets
 iterate over the power set of a set or list

 Calling Sequence subsets(L)

Parameters

 L - set or list of elements

Description

 • The function subsets is an iterator for generating the power set of a set one set at a time.  It returns a table with two entries:  finished and $\mathrm{nextvalue}$.
 • The finished entry will be either true or false, depending on whether the end of the set has been reached. It is initially set to false.
 • The nextvalue entry is a procedure that traverses the power set. The result of a call to $\mathrm{nextvalue}$ will be the next set in the power set. When the entire set has been traversed, nextvalue will set the value of finished to true.
 • If the input L is a set, the subsets are returned as sets.  If the input is a list, the subsets are returned as lists.  Otherwise the only difference is in the order in which the subsets are generated.
 • The command with(combinat,subsets) allows the use of the abbreviated form of this command.

Examples

 > $\mathrm{with}\left(\mathrm{combinat}\right):$
 > $S≔\mathrm{subsets}\left(\left\{1,2\right\}\right):$
 > $\mathbf{while}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{not}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}S\left[\mathrm{finished}\right]\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}S\left[\mathrm{nextvalue}\right]\left(\right)\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathbf{end}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}$
 ${\varnothing }$
 $\left\{{1}\right\}$
 $\left\{{2}\right\}$
 $\left\{{1}{,}{2}\right\}$ (1)

 See Also