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

asked 2024-05-21 06:14:16 +0100

arinicks gravatar image

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?

edit retag flag offensive close merge delete

Comments

Please report the issue at https://github.com/sagemath/sage/issues

Meanwhile, you can try to use fpylll instead:

from fpylll import CVP, IntegerMatrix
v = vector(ZZ, [1,1,1,-1])
A = IntegerMatrix.from_matrix( [v] )
CVP.closest_vector(A,v)
Max Alekseyev gravatar imageMax Alekseyev ( 2024-05-21 16:43:33 +0100 )edit

Thanks, reported as https://github.com/sagemath/sage/issu.... fpylll is working fine.

arinicks gravatar imagearinicks ( 2024-05-22 03:36:43 +0100 )edit