Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There are two functions in Sage which are similar, but do not do exactly what you need. The implementations might provide useful ideas though. This one does not respect the grading, but otherwise solves the second problem. It is implemented in Cython, so is probably quite fast:

sage: IntegerListsLex(n=9, length=3, min_slope=1, min_part=1, max_part=6).list()
[[2, 3, 4], [1, 3, 5], [1, 2, 6]]

This one respects the grading. Though it does not enumerate subsets, but multisets (subsets with repetition):

sage: WeightedIntegerVectors(4, (1,1,1,2,2,3)).list()
[[0, 0, 1, 0, 0, 1],
 [0, 1, 0, 0, 0, 1],
 [1, 0, 0, 0, 0, 1],
 [0, 0, 0, 0, 2, 0],
 ...

In general, you will want to avoid constructing elements of the wrong grade, as early as possible.

There are two functions in Sage which are similar, but do not do exactly what you need. The implementations might provide useful ideas though. This one does not respect the grading, but otherwise solves the second problem. It is implemented in Cython, so is probably quite fast:

sage: IntegerListsLex(n=9, length=3, min_slope=1, min_part=1, max_part=6).list()
[[2, 3, 4], [1, 3, 5], [1, 2, 6]]

This one respects the grading. Though Though, it does not enumerate subsets, but multisets (subsets with repetition):

sage: WeightedIntegerVectors(4, (1,1,1,2,2,3)).list()
[[0, 0, 1, 0, 0, 1],
 [0, 1, 0, 0, 0, 1],
 [1, 0, 0, 0, 0, 1],
 [0, 0, 0, 0, 2, 0],
 ...

In general, you will want to avoid constructing elements of the wrong grade, as early as possible.