ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 12 Dec 2014 22:31:54 +0100quadratic form over the integers with odd coefficientshttps://ask.sagemath.org/question/25216/quadratic-form-over-the-integers-with-odd-coefficients/ Hi,
I'm a newcomer in Sage, and even after thorough examination of the manual I cannot understand the constructor QuadraticFrom :
sage: Q = QuadraticForm(ZZ, 2, [1,2,3])
sage: Q
Quadratic form in 2 variables over Integer Ring with coefficients:
[ 1 2 ]
[ * 3 ]
But
sage: Q.polynomial()
2*x0^2 + 4*x0*x1 + 6*x1^2
So how do I construct a quadratic form with odd coefficients in its polynomial expression ? The polynomial x0^2 + 4*x0*x1 + 3*x1^2 defines a genuine quadratic form over the integers. Is it made on purpose for some reasons related to classification of lattices ?
Thank you.Thu, 11 Dec 2014 14:23:36 +0100https://ask.sagemath.org/question/25216/quadratic-form-over-the-integers-with-odd-coefficients/Comment by Peter Luschny for <p>Hi,</p>
<p>I'm a newcomer in Sage, and even after thorough examination of the manual I cannot understand the constructor QuadraticFrom :</p>
<pre><code>sage: Q = QuadraticForm(ZZ, 2, [1,2,3])
sage: Q
Quadratic form in 2 variables over Integer Ring with coefficients:
[ 1 2 ]
[ * 3 ]
</code></pre>
<p>But</p>
<pre><code>sage: Q.polynomial()
2*x0^2 + 4*x0*x1 + 6*x1^2
</code></pre>
<p>So how do I construct a quadratic form with odd coefficients in its polynomial expression ? The polynomial x0^2 + 4<em>x0</em>x1 + 3*x1^2 defines a genuine quadratic form over the integers. Is it made on purpose for some reasons related to classification of lattices ?</p>
<p>Thank you.</p>
https://ask.sagemath.org/question/25216/quadratic-form-over-the-integers-with-odd-coefficients/?comment=25244#post-id-25244If you are interested in binary quadratic forms this may be of interest for you: http://oeis.org/wiki/User:Peter_Luschny/BinaryQuadraticFormsFri, 12 Dec 2014 22:31:54 +0100https://ask.sagemath.org/question/25216/quadratic-form-over-the-integers-with-odd-coefficients/?comment=25244#post-id-25244Answer by slelievre for <p>Hi,</p>
<p>I'm a newcomer in Sage, and even after thorough examination of the manual I cannot understand the constructor QuadraticFrom :</p>
<pre><code>sage: Q = QuadraticForm(ZZ, 2, [1,2,3])
sage: Q
Quadratic form in 2 variables over Integer Ring with coefficients:
[ 1 2 ]
[ * 3 ]
</code></pre>
<p>But</p>
<pre><code>sage: Q.polynomial()
2*x0^2 + 4*x0*x1 + 6*x1^2
</code></pre>
<p>So how do I construct a quadratic form with odd coefficients in its polynomial expression ? The polynomial x0^2 + 4<em>x0</em>x1 + 3*x1^2 defines a genuine quadratic form over the integers. Is it made on purpose for some reasons related to classification of lattices ?</p>
<p>Thank you.</p>
https://ask.sagemath.org/question/25216/quadratic-form-over-the-integers-with-odd-coefficients/?answer=25225#post-id-25225[Edited 2014-12-12, 2014-12-13.]
The documentation on Quadratic forms indeed documents this restriction.
You can access this documentation within Sage by typing `QuadraticForm?`. You can view the source code by typing `QuadraticForm??`.
You can also access this documentation online. On the online [documentation for quadratic forms in Sage](http://www.sagemath.org/doc/reference/quadratic_forms/sage/quadratic_forms/quadratic_form.html), the "Next Topic" is [Binary Quadratic Forms with Integer Coefficients](http://www.sagemath.org/doc/reference/quadratic_forms/sage/quadratic_forms/binary_qf.html), which does not have this restriction.
So if your quadratic forms are only in two variables, use `BinaryQF`. Here the quadratic form you gave as an example:
sage: Q = BinaryQF([1,4,3])
sage: Q
x^2 + 4*x*y + 3*y^2
Thu, 11 Dec 2014 19:27:02 +0100https://ask.sagemath.org/question/25216/quadratic-form-over-the-integers-with-odd-coefficients/?answer=25225#post-id-25225Comment by slelievre for <p>[Edited 2014-12-12, 2014-12-13.]</p>
<p>The documentation on Quadratic forms indeed documents this restriction.</p>
<p>You can access this documentation within Sage by typing <code>QuadraticForm?</code>. You can view the source code by typing <code>QuadraticForm??</code>.</p>
<p>You can also access this documentation online. On the online <a href="http://www.sagemath.org/doc/reference/quadratic_forms/sage/quadratic_forms/quadratic_form.html">documentation for quadratic forms in Sage</a>, the "Next Topic" is <a href="http://www.sagemath.org/doc/reference/quadratic_forms/sage/quadratic_forms/binary_qf.html">Binary Quadratic Forms with Integer Coefficients</a>, which does not have this restriction.</p>
<p>So if your quadratic forms are only in two variables, use <code>BinaryQF</code>. Here the quadratic form you gave as an example:</p>
<pre><code>sage: Q = BinaryQF([1,4,3])
sage: Q
x^2 + 4*x*y + 3*y^2
</code></pre>
https://ask.sagemath.org/question/25216/quadratic-form-over-the-integers-with-odd-coefficients/?comment=25241#post-id-25241Sorry, my initial answer was not very helpful. I edited to point to Binary quadratic forms with integer coefficients.Fri, 12 Dec 2014 18:42:03 +0100https://ask.sagemath.org/question/25216/quadratic-form-over-the-integers-with-odd-coefficients/?comment=25241#post-id-25241Comment by Basile for <p>[Edited 2014-12-12, 2014-12-13.]</p>
<p>The documentation on Quadratic forms indeed documents this restriction.</p>
<p>You can access this documentation within Sage by typing <code>QuadraticForm?</code>. You can view the source code by typing <code>QuadraticForm??</code>.</p>
<p>You can also access this documentation online. On the online <a href="http://www.sagemath.org/doc/reference/quadratic_forms/sage/quadratic_forms/quadratic_form.html">documentation for quadratic forms in Sage</a>, the "Next Topic" is <a href="http://www.sagemath.org/doc/reference/quadratic_forms/sage/quadratic_forms/binary_qf.html">Binary Quadratic Forms with Integer Coefficients</a>, which does not have this restriction.</p>
<p>So if your quadratic forms are only in two variables, use <code>BinaryQF</code>. Here the quadratic form you gave as an example:</p>
<pre><code>sage: Q = BinaryQF([1,4,3])
sage: Q
x^2 + 4*x*y + 3*y^2
</code></pre>
https://ask.sagemath.org/question/25216/quadratic-form-over-the-integers-with-odd-coefficients/?comment=25234#post-id-25234I carefully read both the documentation and the source code before asking. Still no explanation why, for instance, they ask matrices of quadratic forms over the integers to have even diagonal ! Following this constructor it seems impossible to define x^2 as a quadratic form over ZZ.Fri, 12 Dec 2014 09:20:58 +0100https://ask.sagemath.org/question/25216/quadratic-form-over-the-integers-with-odd-coefficients/?comment=25234#post-id-25234