# subsets -- produce the subsets of a set or list

## Synopsis

• Usage:
subsets(A)
subsets(A, n)
• Inputs:
• A, a list, , sequence, set or integer
• n, an integer, optional input to specify subsets of a particular size
• Outputs:
• L, a list, of subsets (of size n if given)

## 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 {apple, banana}} o5 : List

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

• partition -- partition a set or list by values of a function
• set -- make a set
• sublists -- process interspersed subsequences of a visible list
• substring -- extract part of a string
• lists and sequences -- a detailed overview of lists and sequences in Macaulay2

## Ways to use subsets :

• "subsets(List)"
• "subsets(List,ZZ)"
• "subsets(Sequence,ZZ)"
• "subsets(Set)"
• "subsets(Set,ZZ)"
• "subsets(ZZ)"
• "subsets(ZZ,ZZ)"

## For the programmer

The object subsets is .