Ask Your Question

Is this a bug in QuadraticForm?

asked 2014-06-22 05:00:16 +0200

petropolis gravatar image

updated 2014-06-23 15:45:05 +0200

slelievre gravatar image
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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-06-22 14:56:51 +0200

slelievre gravatar image

The problem is that your quadratic form is not definite.

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()

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

sage: q.lll??

you see that it is doing


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?

we read:

LLL reduction of the lattice whose gram matrix is self.


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


* "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.

edit flag offensive delete link 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.)

petropolis gravatar imagepetropolis ( 2014-06-22 17:05:51 +0200 )edit

@petropolis : if you like this answer, do not forget to accept it.

tmonteil gravatar imagetmonteil ( 2014-06-24 14:09:38 +0200 )edit

@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.

petropolis gravatar imagepetropolis ( 2014-06-27 05:16:01 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-06-22 05:00:16 +0200

Seen: 332 times

Last updated: Jun 22 '14