Subsets

Subsets[list]

gives a list of all possible subsets of list.

Subsets[list,n]

gives all subsets containing at most n elements.

Subsets[list,{n}]

gives all subsets containing exactly n elements.

Subsets[list,{nmin,nmax}]

gives all subsets containing between nmin and nmax elements.

Subsets[list,nspec,s]

limits the result to the first s subsets.

Subsets[list,nspec,{s}]

gives if possible the s ^(th) subset.

Details

  • Subsets[list] gives the power set of list.
  • Subsets[list] orders subsets with shortest first, and later elements in list omitted first.
  • If the elements of list are in the order returned by Sort, then the complete result from Subsets[list] will also be in this order.
  • Subsets[list,All] is equivalent to Subsets[list].
  • Subsets[list,{nmin,nmax,dn}] gives subsets containing nmin, nmin+dn, elements.
  • Subsets[list,nspec,spec] gives the same result as Take[Subsets[list,nspec],spec], provided that the elements specified by spec are present.

Examples

open allclose all

Basic Examples  (2)

All possible subsets (power set):

In[1]:=
Click for copyable input
Out[1]=

All possible subsets containing up to 2 elements:

In[1]:=
Click for copyable input
Out[1]=

Subsets containing exactly 2 elements:

In[2]:=
Click for copyable input
Out[2]=

Scope  (4)

Generalizations & Extensions  (1)

Applications  (7)

Properties & Relations  (3)

Possible Issues  (1)

Neat Examples  (2)

See Also

Tuples  IntegerDigits  Binomial  IntegerPartitions  SymmetricPolynomial  BellB  RandomSample  SubsetQ  Subsequences  Groupings

Tutorials

Introduced in 2004
(5.1)