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)#

Bases: sage.structure.parent.Parent, sage.structure.unique_representation.UniqueRepresentation

The class of integer vectors of \(n\) weighted by weight, that is, the nonnegative integer vectors \((v_1, \ldots, v_{\ell})\) satisfying \(\sum_{i=1}^{\ell} v_i w_i = n\) where \(\ell\) is length(weight) and \(w_i\) is weight[i].

INPUT:

  • n – a non negative integer (optional)

  • weight – a 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 n and weight be exchanged to simplify the logic?

Element#

alias of sage.combinat.integer_vector.IntegerVector

class sage.combinat.integer_vector_weighted.WeightedIntegerVectors_all(weight)#

Bases: sage.sets.disjoint_union_enumerated_sets.DisjointUnionEnumeratedSets

Set 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]
grading(x)#

EXAMPLES:

sage: C = WeightedIntegerVectors([2,1,3])
sage: C.grading((2,1,1))
8
subset(size=None)#

EXAMPLES:

sage: C = WeightedIntegerVectors([2,1,3])
sage: C.subset(4)
Integer vectors of 4 weighted by [2, 1, 3]
sage.combinat.integer_vector_weighted.iterator_fast(n, l)#

Iterate over all l weighted integer vectors with total weight n.

INPUT:

  • n – an integer

  • l – 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 trac ticket #20491 is fixed:

sage: type(list(iterator_fast(2, [2]))[0][0])
<class 'sage.rings.integer.Integer'>