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,- 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– 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] - >>> from sage.all import * >>> WeightedIntegerVectors(Integer(8), [Integer(1),Integer(1),Integer(2)]) Integer vectors of 8 weighted by [1, 1, 2] >>> WeightedIntegerVectors(Integer(8), [Integer(1),Integer(1),Integer(2)]).first() [0, 0, 4] >>> WeightedIntegerVectors(Integer(8), [Integer(1),Integer(1),Integer(2)]).last() [8, 0, 0] >>> WeightedIntegerVectors(Integer(8), [Integer(1),Integer(1),Integer(2)]).cardinality() 25 >>> w = WeightedIntegerVectors(Integer(8), [Integer(1),Integer(1),Integer(2)]).random_element() >>> w.parent() is WeightedIntegerVectors(Integer(8), [Integer(1),Integer(1),Integer(2)]) True >>> WeightedIntegerVectors([Integer(1),Integer(1),Integer(2)]) Integer vectors weighted by [1, 1, 2] >>> WeightedIntegerVectors([Integer(1),Integer(1),Integer(2)]).cardinality() +Infinity >>> WeightedIntegerVectors([Integer(1),Integer(1),Integer(2)]).first() [0, 0, 0] - Todo - Should the order of the arguments - nand- weightbe exchanged to simplify the logic?- Element[source]¶
- alias of - IntegerVector
 
- class sage.combinat.integer_vector_weighted.WeightedIntegerVectors_all(weight)[source]¶
- Bases: - 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] - >>> from sage.all import * >>> W = WeightedIntegerVectors([Integer(3),Integer(1),Integer(1),Integer(2),Integer(1)]); W Integer vectors weighted by [3, 1, 1, 2, 1] >>> W.cardinality() +Infinity >>> W12 = W.graded_component(Integer(12)) >>> W12.an_element() [4, 0, 0, 0, 0] >>> W12.last() [0, 12, 0, 0, 0] >>> W12.cardinality() 441 >>> 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)[source]¶
- EXAMPLES: - sage: C = WeightedIntegerVectors([2,1,3]) sage: C.grading((2,1,1)) 8 - >>> from sage.all import * >>> C = WeightedIntegerVectors([Integer(2),Integer(1),Integer(3)]) >>> C.grading((Integer(2),Integer(1),Integer(1))) 8 
 - subset(size=None)[source]¶
- EXAMPLES: - sage: C = WeightedIntegerVectors([2,1,3]) sage: C.subset(4) Integer vectors of 4 weighted by [2, 1, 3] - >>> from sage.all import * >>> C = WeightedIntegerVectors([Integer(2),Integer(1),Integer(3)]) >>> C.subset(Integer(4)) Integer vectors of 4 weighted by [2, 1, 3] 
 
- sage.combinat.integer_vector_weighted.iterator_fast(n, l)[source]¶
- Iterate over all - lweighted integer vectors with total weight- n.- INPUT: - n– 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]] - >>> from sage.all import * >>> from sage.combinat.integer_vector_weighted import iterator_fast >>> list(iterator_fast(Integer(3), [Integer(2),Integer(1),Integer(1)])) [[1, 1, 0], [1, 0, 1], [0, 3, 0], [0, 2, 1], [0, 1, 2], [0, 0, 3]] >>> list(iterator_fast(Integer(2), [Integer(2)])) [[1]] - Test that Issue #20491 is fixed: - sage: type(list(iterator_fast(2, [2]))[0][0]) <class 'sage.rings.integer.Integer'> - >>> from sage.all import * >>> type(list(iterator_fast(Integer(2), [Integer(2)]))[Integer(0)][Integer(0)]) <class 'sage.rings.integer.Integer'>