next | previous | forward | backward | up | top | index | toc | home

subsets(ZZ,ZZ) -- produce all the subsets

Synopsis

Description

i1 : subsets(7,3)

o1 = {{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}, {0, 1, 5}, {0, 2, 5}, {1, 2, 5},
     ------------------------------------------------------------------------
     {0, 3, 5}, {1, 3, 5}, {2, 3, 5}, {0, 4, 5}, {1, 4, 5}, {2, 4, 5}, {3, 4,
     ------------------------------------------------------------------------
     5}, {0, 1, 6}, {0, 2, 6}, {1, 2, 6}, {0, 3, 6}, {1, 3, 6}, {2, 3, 6},
     ------------------------------------------------------------------------
     {0, 4, 6}, {1, 4, 6}, {2, 4, 6}, {3, 4, 6}, {0, 5, 6}, {1, 5, 6}, {2, 5,
     ------------------------------------------------------------------------
     6}, {3, 5, 6}, {4, 5, 6}}

o1 : List
If each of the sets is reversed, then the resulting list is in lexicographic order.
i2 : x = reverse \ subsets(6,3)

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

o2 : List
i3 : sort x === x

o3 = true