Ask Your Question

Revision history [back]

IntegerLattice.closest_vector() not finding a vector already in the lattice

I am hitting some weird behaviour in IntegerLattice.closest_vector(). In some cases the answer seems off, even when the input vector is already in the lattice. Here is an example:

from sage.modules.free_module_integer import IntegerLattice
v = vector(ZZ, [1,1,-1])
L = IntegerLattice([v])
print (v in L)
print (L.closest_vector(v))

This outputs

True
(1,1,-1)

as expected. However,

from sage.modules.free_module_integer import IntegerLattice
v = vector(ZZ, [1,1,1,-1])
L = IntegerLattice([v])
print (v in L)
print (L.closest_vector(v))

Now outputs

True
(0,0,0,0)

which does not make any sense to me (I would expect the answer to be $v$ again). Am I doing something wrong or is this a bug?