Macaulay2 » Documentation
Packages » Macaulay2Doc :: subsets
next | previous | forward | backward | up | index | toc

subsets -- produce the subsets of a set or list

Synopsis

Description

If A is an integer, subsets(A) lists the subsets of \{0, 1, ..., A-1\}.

i1 : subsets(3)

o1 = {{}, {0}, {1}, {0, 1}, {2}, {0, 2}, {1, 2}, {0, 1, 2}}

o1 : List
i2 : subsets(5, 3)

o2 = {{0, 1, 2}, {0, 1, 3}, {0, 2, 3}, {1, 2, 3}, {0, 1, 4}, {0, 2, 4}, {1,
     ------------------------------------------------------------------------
     2, 4}, {0, 3, 4}, {1, 3, 4}, {2, 3, 4}}

o2 : List

A can be a list, sequence, or set. The elements need not be of the same type.

i3 : subsets({"apple", "banana", {1,2,3}, 7.1}, 3)

o3 = {{apple, banana, {1, 2, 3}}, {apple, banana, 7.1}, {apple, {1, 2, 3},
     ------------------------------------------------------------------------
     7.1}, {banana, {1, 2, 3}, 7.1}}

o3 : List

If a list contains repetitions, so will the subsets of that list. Since a Set has no repetitions, neither do its subsets. Also, the subsets of a set will again be sets (while the subsets of a list are lists).

i4 : subsets({"apple", "apple", "banana"})

o4 = {{}, {apple}, {apple}, {apple, apple}, {banana}, {apple, banana},
     ------------------------------------------------------------------------
     {apple, banana}, {apple, apple, banana}}

o4 : List
i5 : subsets(set{"apple", "apple", "banana"})

o5 = {set {}, set {banana}, set {apple}, set {banana, apple}}

o5 : List

The subsets of a Sequence are lists, not sequences. Also, a subset size must be specified when calling subsets on a sequence.

See also

Ways to use subsets :

For the programmer

The object subsets is a method function.