# 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.
{"ft_lang_label":"__label__en","ft_lang_prob":0.8665949,"math_prob":0.80985713,"size":1463,"snap":"2021-31-2021-39","text_gpt3_token_len":398,"char_repetition_ratio":0.123372175,"word_repetition_ratio":0.0,"special_character_ratio":0.25974026,"punctuation_ratio":0.146875,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9800972,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-07-27T22:25:02Z\",\"WARC-Record-ID\":\"<urn:uuid:18efa79a-5221-421b-a9d4-1e9ecbccee05>\",\"Content-Length\":\"61056\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:49e69b3b-0763-4023-8035-e6f047cc8e78>\",\"WARC-Concurrent-To\":\"<urn:uuid:754a2ff0-e04e-4d08-8de3-00c17a354f8d>\",\"WARC-IP-Address\":\"194.254.163.53\",\"WARC-Target-URI\":\"https://ask.sagemath.org/question/11042/is-this-a-bug-in-quadraticform/?answer=16134\",\"WARC-Payload-Digest\":\"sha1:UMZ3FGNZM2WJP3H6KTULQPUBGFFA6DWR\",\"WARC-Block-Digest\":\"sha1:ESOCAWPJJ5OMM3BHA4GXCAG7SDQMXJZO\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-31/CC-MAIN-2021-31_segments_1627046153491.18_warc_CC-MAIN-20210727202227-20210727232227-00541.warc.gz\"}"}