# Is this a bug in QuadraticForm? QuadraticForm(ZZ, 2, [3, 2, 0]).lll()


gives a ValueError: a matrix from Full MatrixSpace of 2 by 1 dense matrices over Integer Ring cannot be converted to a matrix in Full MatrixSpace of 2 by 2 dense matrices over Integer Ring!

Is this a bug or am I missing some precondition?

edit retag close merge delete

Sort by » oldest newest most voted

sage: q = QuadraticForm(ZZ, 2, [3, 2, 0])
sage: q
Quadratic form in 2 variables over Integer Ring with coefficients:
[ 3 2 ]
[ * 0 ]
sage: q.is_definite()
False


Indeed when you try to see what q.lll() is doing:

sage: q.lll??


you see that it is doing

self(self.matrix().LLL_gram())


Let us try this step by step, by first computing self.matrix()

sage: m = q.matrix()
sage: m
[6 2]
[2 0]


and then applying the LLL_gram method to it.

sage: m.LLL_gram()


We get the same error as the one you got.

Looking at the documentation for this method:

sage: m.LLL_gram?


LLL reduction of the lattice whose gram matrix is self.

INPUT:

* "M" - gram matrix of a definite quadratic form

OUTPUT:

* "U" - unimodular transformation matrix such that U.transpose() *
M * U  is LLL-reduced.


So the documentation is telling us the input should be the Gram matrix from a definite quadratic form.

It is true that the message you got was not so helpful and that it took some digging to get to the problem.

Maybe it would be worth for the lll method to first check if the form is definite, and raise an error if not, rather than trying to do the computation and letting the user end up with a not so helpful error message. Of course, one could add a keyword to decide whether to perform the test, if this test makes the method slower. This way when one uses the method a lot with forms known to be definite, one could keep speed.

more

Thank you very much for tracking the bug! BUT "def lll(self): return self(self.matrix().LLL_gram())" ONLY says: "Returns an LLL-reduced form of Q (using Pari)." Now looking up LLL_gram() the docs say: "LLL reduction of the lattice whose gram matrix is self" AND "Semidefinite and indefinite forms no longer raise a ValueError." Contradiction! (I am using version 6.2.)

@tmonteil I like slelievre's answer but as I wrote I think it does not get the point. Just to reiterate: Yes, my example is indefinite and I get a ValueError. But the docs of LLL_gram say: "Semidefinite and indefinite forms no longer raise a ValueError." So I still think there is a bug.