fplll / fpylll

A Python interface for https://github.com/fplll/fplll
GNU General Public License v2.0
119 stars 60 forks source link

unexpected behavior of M.get_r(k,k) #177

Closed drazioti closed 3 years ago

drazioti commented 4 years ago

Hi everyone,

using the following code

from fpylll import *
A = IntegerMatrix(5, 5)
A[0,0],A[0,1],A[0,2],A[0,3],A[0,4]=2116657,0,0,0,0;
A[1,0],A[1,1],A[1,2],A[1,3],A[1,4]=3716698789988, 1 ,0, 0, 0;
A[2,0],A[2,1],A[2,2],A[2,3],A[2,4]=912858, 0, 1, 0, 0;
A[3,0],A[2,1],A[3,2],A[3,3],A[3,4]=772423, 0, 0, 1, 0;
A[4,0],A[4,1],A[4,2],A[4,3],A[4,4]=18560, 0, 0 ,0 ,1;
dim = A.nrows
M = GSO.Mat(A) 
M.update_gso()
gram =[M.get_r(k,k) for k in range(dim)]
print gram

I got [4480236855649.0, 0.0, 0.0, 0.0, 0.0] the first entry is OK. But the rest must be equal to 1.

What did I miss?

Thanks.

malb commented 3 years ago

This looks like a precision issue:

from fpylll import *
A = IntegerMatrix(5, 5)
A[0,0],A[0,1],A[0,2],A[0,3],A[0,4]=2116657,0,0,0,0;
A[1,0],A[1,1],A[1,2],A[1,3],A[1,4]=3716698789988, 1 ,0, 0, 0;
A[2,0],A[2,1],A[2,2],A[2,3],A[2,4]=912858, 0, 1, 0, 0;
A[3,0],A[2,1],A[3,2],A[3,3],A[3,4]=772423, 0, 0, 1, 0;
A[4,0],A[4,1],A[4,2],A[4,3],A[4,4]=18560, 0, 0 ,0 ,1;
print(A)
dim = A.nrows
M = GSO.Mat(A, float_type="ld")  # <-- Changed this
M.update_gso()
gram =[M.get_r(k,k) for k in range(dim)]
print(gram)

You can also LLL reduce your basis before creating your GSO object to make the input more well conditioned.