[top][index]
search for:

subsets {...} -- produce all the subsets

Synopsis:

  • Function: subsets -- produce all the subsets
  • Input:
  • an instance of class List.
  • subsets s -- yields a list of the subsets of the list s.

    The subsets are returned as lists whose elements are in the same order.

    i1 : subsets {1,2,3}

    o1 = {{}, {1}, {2}, {1, 2}, {3}, {1, 3}, {2, 3}, {1, 2, 3}}

    o1 : List

    See also:

  • subsets -- produce all the subsets
  • Code:

         -- ../../../Macaulay2/m2/combinatorics.m2:19-25
         subsets List := x -> (
              if #x === 0 then {x}
              else (
                   a := x#-1;
                   x = drop(x,-1);
                   s := subsets x;
                   join(s,apply(s,y->append(y,a)))))

    [top][index]
    search for: