ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 26 Jun 2014 22:16:01 -0500Is this a bug in QuadraticForm?http://ask.sagemath.org/question/11042/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?Sat, 21 Jun 2014 22:00:16 -0500http://ask.sagemath.org/question/11042/is-this-a-bug-in-quadraticform/Answer by slelievre for <pre><code>QuadraticForm(ZZ, 2, [3, 2, 0]).lll()
</code></pre>
<p>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!</p>
<p>Is this a bug or am I missing some precondition?</p>
http://ask.sagemath.org/question/11042/is-this-a-bug-in-quadraticform/?answer=16134#post-id-16134The 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()
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?
we read:
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.
Sun, 22 Jun 2014 07:56:51 -0500http://ask.sagemath.org/question/11042/is-this-a-bug-in-quadraticform/?answer=16134#post-id-16134Comment by tmonteil for <p>The problem is that your quadratic form is not definite.</p>
<pre><code>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
</code></pre>
<p>Indeed when you try to see what <code>q.lll()</code> is doing:</p>
<pre><code>sage: q.lll??
</code></pre>
<p>you see that it is doing</p>
<pre><code>self(self.matrix().LLL_gram())
</code></pre>
<p>Let us try this step by step, by first computing <code>self.matrix()</code></p>
<pre><code>sage: m = q.matrix()
sage: m
[6 2]
[2 0]
</code></pre>
<p>and then applying the <code>LLL_gram</code> method to it.</p>
<pre><code>sage: m.LLL_gram()
</code></pre>
<p>We get the same error as the one you got.</p>
<p>Looking at the documentation for this method:</p>
<pre><code>sage: m.LLL_gram?
</code></pre>
<p>we read:</p>
<pre><code>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.
</code></pre>
<p>So the documentation is telling us the input should be the Gram matrix
from a definite quadratic form.</p>
<p>It is true that the message you got was not so helpful and that it
took some digging to get to the problem.</p>
<p>Maybe it would be worth for the <code>lll</code> 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.</p>
http://ask.sagemath.org/question/11042/is-this-a-bug-in-quadraticform/?comment=16141#post-id-16141@petropolis : if you like this answer, do not forget to accept it.Tue, 24 Jun 2014 07:09:38 -0500http://ask.sagemath.org/question/11042/is-this-a-bug-in-quadraticform/?comment=16141#post-id-16141Comment by petropolis for <p>The problem is that your quadratic form is not definite.</p>
<pre><code>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
</code></pre>
<p>Indeed when you try to see what <code>q.lll()</code> is doing:</p>
<pre><code>sage: q.lll??
</code></pre>
<p>you see that it is doing</p>
<pre><code>self(self.matrix().LLL_gram())
</code></pre>
<p>Let us try this step by step, by first computing <code>self.matrix()</code></p>
<pre><code>sage: m = q.matrix()
sage: m
[6 2]
[2 0]
</code></pre>
<p>and then applying the <code>LLL_gram</code> method to it.</p>
<pre><code>sage: m.LLL_gram()
</code></pre>
<p>We get the same error as the one you got.</p>
<p>Looking at the documentation for this method:</p>
<pre><code>sage: m.LLL_gram?
</code></pre>
<p>we read:</p>
<pre><code>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.
</code></pre>
<p>So the documentation is telling us the input should be the Gram matrix
from a definite quadratic form.</p>
<p>It is true that the message you got was not so helpful and that it
took some digging to get to the problem.</p>
<p>Maybe it would be worth for the <code>lll</code> 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.</p>
http://ask.sagemath.org/question/11042/is-this-a-bug-in-quadraticform/?comment=16140#post-id-16140@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.Thu, 26 Jun 2014 22:16:01 -0500http://ask.sagemath.org/question/11042/is-this-a-bug-in-quadraticform/?comment=16140#post-id-16140Comment by petropolis for <p>The problem is that your quadratic form is not definite.</p>
<pre><code>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
</code></pre>
<p>Indeed when you try to see what <code>q.lll()</code> is doing:</p>
<pre><code>sage: q.lll??
</code></pre>
<p>you see that it is doing</p>
<pre><code>self(self.matrix().LLL_gram())
</code></pre>
<p>Let us try this step by step, by first computing <code>self.matrix()</code></p>
<pre><code>sage: m = q.matrix()
sage: m
[6 2]
[2 0]
</code></pre>
<p>and then applying the <code>LLL_gram</code> method to it.</p>
<pre><code>sage: m.LLL_gram()
</code></pre>
<p>We get the same error as the one you got.</p>
<p>Looking at the documentation for this method:</p>
<pre><code>sage: m.LLL_gram?
</code></pre>
<p>we read:</p>
<pre><code>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.
</code></pre>
<p>So the documentation is telling us the input should be the Gram matrix
from a definite quadratic form.</p>
<p>It is true that the message you got was not so helpful and that it
took some digging to get to the problem.</p>
<p>Maybe it would be worth for the <code>lll</code> 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.</p>
http://ask.sagemath.org/question/11042/is-this-a-bug-in-quadraticform/?comment=16142#post-id-16142Thank 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.)
Sun, 22 Jun 2014 10:05:51 -0500http://ask.sagemath.org/question/11042/is-this-a-bug-in-quadraticform/?comment=16142#post-id-16142