Integer vectors

sage.combinat.integer_vector.IntegerVectors(n=None, k=None, **kwargs)

Returns the combinatorial class of integer vectors.

EXAMPLES: If n is not specified, it returns the class of all integer vectors.

sage: IntegerVectors()
Integer vectors
sage: [] in IntegerVectors()
True
sage: [1,2,1] in IntegerVectors()
True
sage: [1, 0, 0] in IntegerVectors()
True

If n is specified, then it returns the class of all integer vectors which sum to n.

sage: IV3 = IntegerVectors(3); IV3
Integer vectors that sum to 3

Note that trailing zeros are ignored so that [3, 0] does not show up in the following list (since [3] does)

sage: IntegerVectors(3, max_length=2).list()
[[3], [2, 1], [1, 2], [0, 3]]

If n and k are both specified, then it returns the class of integer vectors that sum to n and are of length k.

sage: IV53 = IntegerVectors(5,3); IV53
Integer vectors of length 3 that sum to 5
sage: IV53.cardinality()
21
sage: IV53.first()
[5, 0, 0]
sage: IV53.last()
[0, 0, 5]
sage: IV53.random_element()
[4, 0, 1]
class sage.combinat.integer_vector.IntegerVectors_all
__contains__(x)

EXAMPLES:

sage: [] in IntegerVectors()
True
sage: [3,2,2,1] in IntegerVectors()
True
__repr__()

EXAMPLES:

sage: IntegerVectors()
Integer vectors
cardinality()

EXAMPLES:

sage: IntegerVectors().cardinality()
+Infinity
list()

EXAMPLES:

sage: IntegerVectors().list()
...
NotImplementedError: infinite list
class sage.combinat.integer_vector.IntegerVectors_nconstraints(n, constraints)
__contains__(x)

EXAMPLES:

sage: [0,3,0,1,2] in IntegerVectors(6)
True
sage: [0,3,0,1,2] in IntegerVectors(6, max_length=3)
False
__init__(n, constraints)

TESTS:

sage: IV = IntegerVectors(3, max_length=2)
sage: IV == loads(dumps(IV))
True
__repr__()

EXAMPLES:

sage: repr(IntegerVectors(3))
'Integer vectors that sum to 3'
sage: repr(IntegerVectors(3, max_length=2))
'Integer vectors that sum to 3 with constraints: max_length=2'
cardinality()

EXAMPLES:

sage: IntegerVectors(3, max_length=2).cardinality()
4
sage: IntegerVectors(3).cardinality()
+Infinity
list()

EXAMPLES:

sage: IntegerVectors(3, max_length=2).list()
[[3], [2, 1], [1, 2], [0, 3]]
sage: IntegerVectors(3).list()
...
NotImplementedError: infinite list
class sage.combinat.integer_vector.IntegerVectors_nk(n, k)
__contains__(x)

TESTS:

sage: IV = IntegerVectors(2,3)
sage: all([i in IV for i in IV])
True
sage: [0,1,2] in IV
False
sage: [2.0, 0, 0] in IV
False
sage: [0,1,0,1] in IV
False
sage: [0,1,1] in IV
True
sage: [-1,2,1] in IV
False
__init__(n, k)

TESTS:

sage: IV = IntegerVectors(2,3)
sage: IV == loads(dumps(IV))
True

AUTHORS:

  • Martin Albrecht
  • Mike Hansen
__iter__()

EXAMPLE:

sage: IV = IntegerVectors(2,3)
sage: list(IV)
[[2, 0, 0], [1, 1, 0], [1, 0, 1], [0, 2, 0], [0, 1, 1], [0, 0, 2]]
sage: list(IntegerVectors(3, 0))
[]
sage: list(IntegerVectors(3, 1))
[[3]]
sage: list(IntegerVectors(0, 1))
[[0]]
sage: list(IntegerVectors(0, 2))
[[0, 0]]
sage: list(IntegerVectors(2, 2))
[[2, 0], [1, 1], [0, 2]]
sage: IntegerVectors(0,0).list()
[[]]
sage: IntegerVectors(1,0).list()
[]
sage: IntegerVectors(0,1).list()
[[0]]
sage: IntegerVectors(2,2).list()
[[2, 0], [1, 1], [0, 2]]
sage: IntegerVectors(-1,0).list()
[]
sage: IntegerVectors(-1,2).list()
[]
__repr__()

TESTS:

sage: IV = IntegerVectors(2,3)
sage: repr(IV)
'Integer vectors of length 3 that sum to 2'
_list_rec(n, k)

Return a list of a exponent tuples of length size such that the degree of the associated monomial is D.

INPUT:

  • n - degree (must be 0)
  • k - length of exponent tuples (must be 0)

EXAMPLES:

sage: IV = IntegerVectors(2,3)
sage: IV._list_rec(2,3)
[(2, 0, 0), (1, 1, 0), (1, 0, 1), (0, 2, 0), (0, 1, 1), (0, 0, 2)]
list()

EXAMPLE:

sage: IV = IntegerVectors(2,3)
sage: IV.list()
[[2, 0, 0], [1, 1, 0], [1, 0, 1], [0, 2, 0], [0, 1, 1], [0, 0, 2]]
sage: IntegerVectors(3, 0).list()
[]
sage: IntegerVectors(3, 1).list()
[[3]]
sage: IntegerVectors(0, 1).list()
[[0]]
sage: IntegerVectors(0, 2).list()
[[0, 0]]
sage: IntegerVectors(2, 2).list()
[[2, 0], [1, 1], [0, 2]]
class sage.combinat.integer_vector.IntegerVectors_nkconstraints(n, k, constraints)
__contains__(x)

TESTS:

sage: [0] in IntegerVectors(0)
True
sage: [0] in IntegerVectors(0, 1)
True
sage: [] in IntegerVectors(0, 0)
True
sage: [] in IntegerVectors(0, 1)
False
sage: [] in IntegerVectors(1, 0)
False
sage: [3] in IntegerVectors(3)
True
sage: [3] in IntegerVectors(2,1)
False
sage: [3] in IntegerVectors(2)
False
sage: [3] in IntegerVectors(3,1)
True
sage: [3,2,2,1] in IntegerVectors(9)
False
sage: [3,2,2,1] in IntegerVectors(9,5)
False            
sage: [3,2,2,1] in IntegerVectors(8)
True
sage: [3,2,2,1] in IntegerVectors(8,5)
False
sage: [3,2,2,1] in IntegerVectors(8,4)
True
sage: [3,2,2,1] in IntegerVectors(8,4, min_part = 1)
True
sage: [3,2,2,1] in IntegerVectors(8,4, min_part = 2)
False
__init__(n, k, constraints)

EXAMPLES:

sage: IV = IntegerVectors(2,3,min_slope=0)
sage: IV == loads(dumps(IV))
True
__iter__()

EXAMPLES:

sage: IntegerVectors(-1, 0, min_part = 1).list()
[]
sage: IntegerVectors(-1, 2, min_part = 1).list()
[]
sage: IntegerVectors(0, 0, min_part=1).list()
[[]]
sage: IntegerVectors(3, 0, min_part=1).list()
[]
sage: IntegerVectors(0, 1, min_part=1).list()
[]
sage: IntegerVectors(2, 2, min_part=1).list()
[[1, 1]]
sage: IntegerVectors(2, 3, min_part=1).list()
[]
sage: IntegerVectors(4, 2, min_part=1).list()
[[3, 1], [2, 2], [1, 3]]
sage: IntegerVectors(0, 3, outer=[0,0,0]).list()
[[0, 0, 0]]
sage: IntegerVectors(1, 3, outer=[0,0,0]).list()
[]
sage: IntegerVectors(2, 3, outer=[0,2,0]).list()
[[0, 2, 0]]
sage: IntegerVectors(2, 3, outer=[1,2,1]).list()
[[1, 1, 0], [1, 0, 1], [0, 2, 0], [0, 1, 1]]
sage: IntegerVectors(2, 3, outer=[1,1,1]).list()
[[1, 1, 0], [1, 0, 1], [0, 1, 1]]
sage: IntegerVectors(2, 5, outer=[1,1,1,1,1]).list()
[[1, 1, 0, 0, 0],
 [1, 0, 1, 0, 0],
 [1, 0, 0, 1, 0],
 [1, 0, 0, 0, 1],
 [0, 1, 1, 0, 0],
 [0, 1, 0, 1, 0],
 [0, 1, 0, 0, 1],
 [0, 0, 1, 1, 0],
 [0, 0, 1, 0, 1],
 [0, 0, 0, 1, 1]]
sage: iv = [ IntegerVectors(n,k) for n in range(-2, 7) for k in range(7) ]
sage: all(map(lambda x: x.cardinality() == len(x.list()), iv))
True
sage: essai = [[1,1,1], [2,5,6], [6,5,2]]
sage: iv = [ IntegerVectors(x[0], x[1], max_part = x[2]-1) for x in essai ]
sage: all(map(lambda x: x.cardinality() == len(x.list()), iv))
True
__repr__()

EXAMPLES:

sage: IntegerVectors(2,3,min_slope=0).__repr__()
'Integer vectors of length 3 that sum to 2 with constraints: min_slope=0'
_parameters()

Returns a tuple (min_length, max_length, floor, ceiling, min_slope, max_slope) for the parameters of self.

EXAMPLES:

sage: IV = IntegerVectors(2,3,min_slope=0)
sage: min_length, max_length, floor, ceiling, min_slope, max_slope = IV._parameters()
sage: min_length
3
sage: max_length
3
sage: [floor(i) for i in range(1,10)]
[0, 0, 0, 0, 0, 0, 0, 0, 0]
sage: [ceiling(i) for i in range(1,5)]
[+Infinity, +Infinity, +Infinity, +Infinity]
sage: min_slope
0
sage: max_slope
+Infinity

sage: IV = IntegerVectors(3,10,inner=[4,1,3], min_part = 2)
sage: min_length, max_length, floor, ceiling, min_slope, max_slope = IV._parameters()
sage: floor(1), floor(2), floor(3)
(4, 2, 3)

sage: IV = IntegerVectors(3, 10, outer=[4,1,3], max_part = 3)
sage: min_length, max_length, floor, ceiling, min_slope, max_slope = IV._parameters()
sage: ceiling(1), ceiling(2), ceiling(3)
(3, 1, 3)
cardinality()

EXAMPLES:

sage: IntegerVectors(3,3, min_part=1).cardinality()
1
sage: IntegerVectors(5,3, min_part=1).cardinality()
6
sage: IntegerVectors(13, 4, min_part=2, max_part=4).cardinality()
16
first()

EXAMPLES:

sage: IntegerVectors(2,3,min_slope=0).first()
[0, 1, 1]
next(x)

EXAMPLES:

sage: IntegerVectors(2,3,min_slope=0).last()
[0, 0, 2]
class sage.combinat.integer_vector.IntegerVectors_nnondescents(n, comp)

The combinatorial class of integer vectors v graded by two parameters:

  • n: the sum of the parts of v
  • comp: the non descents composition of v

In other words: the length of v equals c[1]+...+c[k], and v is decreasing in the consecutive blocs of length c[1], ..., c[k]

Those are the integer vectors of sum n which are lexicographically maximal (for the natural left->right reading) in their orbit by the young subgroup S_c_1 x x S_c_k. In particular, they form a set of orbit representative of integer vectors w.r.t. this young subgroup.

__init__(n, comp)

EXAMPLES:

sage: IV = IntegerVectors(4, [2])
sage: IV == loads(dumps(IV))
True
__iter__()

TESTS:

sage: IntegerVectors(0, []).list()
[[]]
sage: IntegerVectors(5, []).list()
[]
sage: IntegerVectors(0, [1]).list()
[[0]]
sage: IntegerVectors(4, [1]).list()
[[4]]
sage: IntegerVectors(4, [2]).list()
[[4, 0], [3, 1], [2, 2]]
sage: IntegerVectors(4, [2,2]).list()
 [[4, 0, 0, 0],
 [3, 0, 1, 0],
 [2, 0, 2, 0],
 [2, 0, 1, 1],
 [1, 0, 3, 0],
 [1, 0, 2, 1],
 [0, 0, 4, 0],
 [0, 0, 3, 1],
 [0, 0, 2, 2]]
sage: IntegerVectors(5, [1,1,1]).list()
[[5, 0, 0],
 [4, 1, 0],
 [4, 0, 1],
 [3, 2, 0],
 [3, 1, 1],
 [3, 0, 2],
 [2, 3, 0],
 [2, 2, 1],
 [2, 1, 2],
 [2, 0, 3],
 [1, 4, 0],
 [1, 3, 1],
 [1, 2, 2],
 [1, 1, 3],
 [1, 0, 4],
 [0, 5, 0],
 [0, 4, 1],
 [0, 3, 2],
 [0, 2, 3],
 [0, 1, 4],
 [0, 0, 5]]
sage: IntegerVectors(0, [2,3]).list()
[[0, 0, 0, 0, 0]]
__repr__()

EXAMPLES:

sage: IntegerVectors(4, [2]).__repr__()
'Integer vectors of 4 with non-descents composition [2]'
sage.combinat.integer_vector._default_function(l, default, i)

EXAMPLES:

sage: from sage.combinat.integer_vector import _default_function
sage: import functools
sage: f = functools.partial(_default_function, [1,2,3], 99)
sage: f(0)
99
sage: f(1)
1
sage: f(2)
2
sage: f(3)
3
sage: f(4)
99
sage.combinat.integer_vector.constant_func(i)

Returns the constant function i.

EXAMPLES:

sage: f = sage.combinat.integer_vector.constant_func(3)
sage: f(-1)
3
sage: f('asf')
3
sage.combinat.integer_vector.list2func(l, default=None)

Given a list l, return a function that takes in a value i and return l[i-1]. If default is not None, then the function will return the default value for out of range i’s.

EXAMPLES:

sage: f = sage.combinat.integer_vector.list2func([1,2,3])
sage: f(1)
1
sage: f(2)
2
sage: f(3)
3
sage: f(4)
...
IndexError: list index out of range
sage: f = sage.combinat.integer_vector.list2func([1,2,3], 0)
sage: f(3)
3
sage: f(4)
0

Previous topic

Tools for generating lists of integers in lexicographic order.

Next topic

Weighted Integer Vectors

This Page