Weighted integer vectors¶
AUTHORS:
Mike Hansen (2007): initial version, ported from MuPAD-Combinat
Nicolas M. Thiery (2010-10-30): WeightedIntegerVectors(weights) + cleanup
- class sage.combinat.integer_vector_weighted.WeightedIntegerVectors(n, weight)[source]¶
Bases:
Parent,UniqueRepresentationThe class of integer vectors of
weighted byweight, that is, the nonnegative integer vectors satisfying where islength(weight)and isweight[i].INPUT:
n– nonnegative integer (optional)weight– tuple (or list or iterable) of positive integers
EXAMPLES:
sage: WeightedIntegerVectors(8, [1,1,2]) Integer vectors of 8 weighted by [1, 1, 2] sage: WeightedIntegerVectors(8, [1,1,2]).first() [0, 0, 4] sage: WeightedIntegerVectors(8, [1,1,2]).last() [8, 0, 0] sage: WeightedIntegerVectors(8, [1,1,2]).cardinality() 25 sage: w = WeightedIntegerVectors(8, [1,1,2]).random_element() sage: w.parent() is WeightedIntegerVectors(8, [1,1,2]) True sage: WeightedIntegerVectors([1,1,2]) Integer vectors weighted by [1, 1, 2] sage: WeightedIntegerVectors([1,1,2]).cardinality() +Infinity sage: WeightedIntegerVectors([1,1,2]).first() [0, 0, 0]
Todo
Should the order of the arguments
nandweightbe exchanged to simplify the logic?- Element[source]¶
alias of
IntegerVector
- class sage.combinat.integer_vector_weighted.WeightedIntegerVectors_all(weight)[source]¶
Bases:
DisjointUnionEnumeratedSetsSet of weighted integer vectors.
EXAMPLES:
sage: W = WeightedIntegerVectors([3,1,1,2,1]); W Integer vectors weighted by [3, 1, 1, 2, 1] sage: W.cardinality() +Infinity sage: W12 = W.graded_component(12) sage: W12.an_element() [4, 0, 0, 0, 0] sage: W12.last() [0, 12, 0, 0, 0] sage: W12.cardinality() 441 sage: for w in W12: print(w) [4, 0, 0, 0, 0] [3, 0, 0, 1, 1] [3, 0, 1, 1, 0] ... [0, 11, 1, 0, 0] [0, 12, 0, 0, 0]
- sage.combinat.integer_vector_weighted.iterator_fast(n, l)[source]¶
Iterate over all
lweighted integer vectors with total weightn.INPUT:
n– integerl– the weights in weakly decreasing order
EXAMPLES:
sage: from sage.combinat.integer_vector_weighted import iterator_fast sage: list(iterator_fast(3, [2,1,1])) [[1, 1, 0], [1, 0, 1], [0, 3, 0], [0, 2, 1], [0, 1, 2], [0, 0, 3]] sage: list(iterator_fast(2, [2])) [[1]]
Test that Issue #20491 is fixed:
sage: type(list(iterator_fast(2, [2]))[0][0]) <class 'sage.rings.integer.Integer'>