Weighted Integer Vectors¶
AUTHORS:
- Mike Hansen (2007): initial version, ported from MuPAD-Combinat
- Nicolas M. Thiery (2010-10-30): WeightedIntegerVectors(weights) + cleanup
Warning
The list(self) function in this file used the Permutation
class improperly, returning
a list of, generally speaking, invalid permutations (repeated entries, including 0).
-
sage.combinat.integer_vector_weighted.
WeightedIntegerVectors
(n=None, weight=None)¶ Returns the combinatorial class of integer vectors of
n
weighted byweight
, that is, the nonnegative integer vectorssatisfying
.
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: WeightedIntegerVectors(8, [1,1,2]).random_element() [1, 1, 3] 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]
TESTS:
sage: WeightedIntegerVectors(None,None) Traceback (most recent call last): ... ValueError: weights should be specified
Todo
should the order of the arguments
n
andweight
be exchanged to simplify the logic ?
-
class
sage.combinat.integer_vector_weighted.
WeightedIntegerVectors_all
(weights)¶ 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]
-
-
class
sage.combinat.integer_vector_weighted.
WeightedIntegerVectors_nweight
(n, weight)¶ Bases:
sage.structure.unique_representation.UniqueRepresentation
,sage.structure.parent.Parent
TESTS:
sage: C = WeightedIntegerVectors(8, [1,1,2]) sage: C.__class__ <class 'sage.combinat.integer_vector_weighted.WeightedIntegerVectors_nweight_with_category'> sage: TestSuite(C).run()