quadratic_forms
system:sage

<h1><span style="font-family: arial,helvetica,sans-serif;">Quadratic Forms Primer: What's Implemented</span></h1>
<p><span style="font-family: arial,helvetica,sans-serif;">This primer is designed to highlight some of the functionality in Sage reguarding Quadratic Forms coming out of Sage Days 13. The focus is on what could be useful for the Arizona Winter School 2009.<br /></span></p>
<h2><span style="font-family: arial,helvetica,sans-serif;">The Basics: Defining a Quadratic Form</span></h2>
<p><span style="font-family: arial,helvetica,sans-serif;">There are currently two ways to define a QF:= Quadratic Form in Sage.&nbsp; The function <span style="font-family: courier new,courier;">BinaryQF <span style="font-family: arial,helvetica,sans-serif;">creates a binary quadratic form.&nbsp; The function <span style="font-family: courier new,courier;">QuadraticForm <span style="font-family: arial,helvetica,sans-serif;">creates a general quadratic form.</span></span></span></span></span></p>
<p><span style="font-family: arial,helvetica,sans-serif;"><span style="font-family: courier new,courier;">BinaryQF <span style="font-family: arial,helvetica,sans-serif;">takes as input a list of length 3 whose entries represent the coefficients of the binary quadratic form.&nbsp; This function outputs the polynomial form of the QF in terms of variables x and y.&nbsp; A word of warning, the input list must have integer entries.&nbsp; This function only works over ZZ.</span><br /></span></span></p>

{{{id=1|
B = BinaryQF([1,2,3]); B
///

x^2 + 2*x*y + 3*y^2
}}}

<p><span style="font-family: arial,helvetica,sans-serif;">Defining a binary QF, B, with <span style="font-family: courier new,courier;">BinaryQF </span></span><span style="font-family: arial,helvetica,sans-serif;">there is very little functionality associated with B.&nbsp; </span><span style="font-family: arial,helvetica,sans-serif;">To see the available functions type <span style="font-family: courier new,courier;">B.&lt;tab&gt;<span style="font-family: arial,helvetica,sans-serif;">.&nbsp;&nbsp; For the rest of the notebook the focus will be on the second way to define a quadratic form.</span></span></span></p>
<p><span style="font-family: arial,helvetica,sans-serif;"><span style="font-family: courier new,courier;"><span style="font-family: arial,helvetica,sans-serif;">The function <span style="font-family: courier new,courier;">QuadraticForm <span style="font-family: arial,helvetica,sans-serif;">takes as input the base ring, the number of coefficients, n, and the coefficients.&nbsp; The function takes the coefficents as a list of length n(n+1)/2 which has entries over the given ring. </span></span></span></span></span></p>

{{{id=82|
Q = QuadraticForm(ZZ, 4, [1,2,3,4,5,6,7,8,9,10]); Q
///

Quadratic form in 4 variables over Integer Ring with coefficients: 
[ 1 2 3 4 ]
[ * 5 6 7 ]
[ * * 8 9 ]
[ * * * 10 ]
}}}

<p><span style="font-family: arial,helvetica,sans-serif;">You can also create a list of the coefficients of Q when represented as a polynomial.</span></p>

{{{id=81|
Q.coefficients()
///

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
}}}

<p><span style="font-family: arial,helvetica,sans-serif;">Examining the functions available to Q by <span style="font-family: courier new,courier;">Q.&lt;tab&gt;</span> many functions appear.&nbsp; Not all of them are supported and not all make sense.&nbsp; The rest of this worksheet is dedicated to examining some of the functions which are supported and do make sense.&nbsp; The worksheet also makes note of two functions which should appear in Sage and do not (yet).<br /></span></p>
<h2><span style="font-family: arial,helvetica,sans-serif;">Local Rational Invariants/Matrix Representation</span></h2>
<p><span style="font-family: arial,helvetica,sans-serif;">Any QF Q is associated with a bilinear form B by the following:&nbsp; If Q is a quadratic form in n variables over the ring $R$, take U,V in $R^n$.&nbsp; Then $B(U,V) = 1/2 (Q(U+V)-Q(U)-Q(V))$ and B has an associated matrix, M, given by $B(e_i,e_j) =M_{i,j}$ where $e_i$ and $e_j$ are the $i^{th}$ and $j^{th}$ basis vectors over $R^n$.&nbsp; The matrix M is the Gram Matrix of Q.&nbsp; This matrix matrix depends on the choice of basis.&nbsp; In Sage when working over the integers, Sage assumes the standard choice.&nbsp; Taking X to be the vector of n variables, $X^t M X = Q$ where Q is represented as a polynomial.&nbsp; However, these computations assume 2 is invertible in R.&nbsp; If 2 is not invertible in R, we can work over a larger ring (e.g. \mathbb{QQ} instead of \mathbb{ZZ}) or we can take the Hessian Matrix which is 2*M.&nbsp; Since working in a field of characteristic 2 can lead to problems, unless otherwise stated, assume the characteristic is not 2.&nbsp; One more note, the Gram Matrix of Q has elements in $\frac{1}{2} \mathbb{Z}$ but Sage creates a matrix in $\mathbb{Q}$.<br /></span></p>
<p><span style="font-family: arial,helvetica,sans-serif;"><br /></span></p>

{{{id=17|
Q.Gram_matrix()
///

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/aly/.sage/sage_notebook/worksheets/admin/15/code/284.py", line 6, in <module>
    exec compile(ur'Q.Gram_matrix()' + '\n', '', 'single')
  File "/home/aly/Desktop/sage-3.4.alpha0/local/lib/python2.5/site-packages/SQLAlchemy-0.4.6-py2.5.egg/", line 1, in <module>
    
  File "/home/aly/Desktop/sage-3.4.alpha0/local/lib/python2.5/site-packages/sage/quadratic_forms/quadratic_form.py", line 884, in Gram_matrix
    raise TypeError, "Oops!  This form does not have an integral Gram matrix. =("
TypeError: Oops!  This form does not have an integral Gram matrix. =(
}}}

<p><span style="font-family: arial,helvetica,sans-serif;">In this example the Gram Matrix of Q is not integral.&nbsp; So take either the Gram Matrix over $\mathbb{Q}$ or the Hessian Matrix.</span></p>

{{{id=9|
Q.Gram_matrix_rational()
///

[  1   1 3/2   2]
[  1   5   3 7/2]
[3/2   3   8 9/2]
[  2 7/2 9/2  10]
}}}

{{{id=19|
Q.Hessian_matrix()
///

[ 2  2  3  4]
[ 2 10  6  7]
[ 3  6 16  9]
[ 4  7  9 20]
}}}

<p><span style="font-family: arial,helvetica,sans-serif;">Also note that</span> <span style="font-family: courier new,courier;">Q.matrix()</span> <span style="font-family: arial,helvetica,sans-serif;">returns the Hessian Matrix of Q.</span></p>
<p><span style="font-family: arial,helvetica,sans-serif;">Other invarients you can compute include the discriminant of Q, which is the determinant of d*M where d is an integer such that $M \in R$ and the dimention of Q which is defined in Sage to be the number of variables in Q thus is also the dimension of $M$.<br /></span></p>

{{{id=24|
Q.disc()
///

1749
}}}

{{{id=21|
H= Q.Hessian_matrix()
H.det()
///

1749
}}}

{{{id=75|
Q.dim()
///

4
}}}

<p><span style="font-family: arial,helvetica,sans-serif;">Using the matrix of a QF sage can also compute the signature.&nbsp; This signature of a QF the difference between the number of positive and negative eigenvalues of the matrix.</span></p>

{{{id=71|
Q.signature()
///

4
}}}

<p><span style="font-family: arial,helvetica,sans-serif;">Another local invariant Sage can compute is the Hass Invariant at a prime p.&nbsp; This can be computed by calling either <span style="font-family: courier new,courier;">hasse_invariant()</span>&nbsp; or <span style="font-family: courier new,courier;">hasse_invariant_OMeara()</span>&nbsp; .&nbsp; The first is the Hasse invariant as defined in Cassels' Rational Quadratic Forms and the second is as defined in O'Meara's Introduction to Quadratic Forms.<br /></span></p>

{{{id=78|
Q.hasse_invariant(next_prime(2^10))
///

1
}}}

{{{id=52|
Q.hasse_invariant__OMeara(next_prime(2^10))
///

1
}}}

<p><span style="font-family: arial,helvetica,sans-serif;">You can also determine whether a quadratic form is isotropic over a given p-adic field, meaning there exists a non-zero vector $v\in F^n$ such that Q(v) = 0, or not, in which case it is called anisotropic.&nbsp; <br /></span></p>

{{{id=47|
Q.is_isotropic(next_prime(2^10))
///

True
}}}

{{{id=46|
Q.is_anisotropic(next_prime(2^10))
///

False
}}}

<p><span style="font-family: arial,helvetica,sans-serif;">In general, it is also possible to compute the Isotropic and Anisotropic dimensions.&nbsp; However these have yet to be implemented in Sage.&nbsp; If you are interested in implementing these, that would be awesome.&nbsp; Cassels's Rational Quadratic Forms gives a method for their computation.<br /></span></p>

<h2><span style="font-family: arial,helvetica,sans-serif;">Local Integral Invarients</span></h2>
<p><span style="font-family: arial,helvetica,sans-serif;">If p is a prime not equal to 2, the matrix of Q can be diagonalized over $\mathbb{Z}_p$.&nbsp; If p is equal to 2, then we use blocks of size less than or equal to 2 on the diagonal.&nbsp; This is called the Jordan decomposition.&nbsp; It is represented in Sage in the following two ways.<br /></span></p>

{{{id=43|
Q.jordan_blocks_by_scale_and_unimodular(next_prime(2^10))
///

[(0, Quadratic form in 4 variables over Integer Ring with coefficients: 
[ 1 0 0 0 ]
[ * 4 0 0 ]
[ * * 332 0 ]
[ * * * 2322672 ]
)]
}}}

{{{id=44|
Q.jordan_blocks_in_unimodular_list_by_scale_power(next_prime(2^10))
///

[Quadratic form in 4 variables over Integer Ring with coefficients: 
[ 1 0 0 0 ]
[ * 4 0 0 ]
[ * * 332 0 ]
[ * * * 2322672 ]
]
}}}

<p><span style="font-family: arial,helvetica,sans-serif;">Note that the previous two functions do not necessarily return the same object.&nbsp; The first</span>,<span style="font-family: arial,helvetica,sans-serif;"> according to Sage documentation, "</span><span style="font-family: arial,helvetica,sans-serif;">returns a list of pairs $(s_i , L_i$) where $L_i$ is a maximal $p^{s_i}$-unimodular Jordan component which is further decomposed into block diagonals of block size less than or equal to 2.&nbsp; For each $L_i$ the 2x2 blocks are listed after the 1x1 blocks (which follows from the convention of the local_normal_form method).</span></p>
<p><span style="font-family: arial,helvetica,sans-serif;">The second function "Returns a list of Jordan components, whose component at index i&nbsp; should be scaled by the factor $p^i$.&nbsp;"</span>&nbsp; <span style="font-family: arial,helvetica,sans-serif;">It is only defined for QFs over $\mathbb{Z}$</span> <span style="font-family: arial,helvetica,sans-serif;">and for p = 2 only works correctly if the Gram matrix is integral.</span></p>

<p><span style="font-family: arial,helvetica,sans-serif;">Sage also computes the local density of a QF. The local density of Q is the limit as $\alpha \rightarrow \infty$ of the ratio of the number of solutions $Q(X) \equiv $ m (mod $p^{\alpha}$) and $p^{\alpha (n-1)}$ where n is the rank of Q.&nbsp; </span><span style="font-family: arial,helvetica,sans-serif;">However, the QF must first be in local normal form.&nbsp; The local normal form is defined to be the integrally equivalent quadratic form over the p-adic integers which gives the Jordan decomposition. </span></p>

{{{id=59|
LNF = Q.local_normal_form(next_prime(2^10));LNF
///

Quadratic form in 4 variables over Integer Ring with coefficients: 
[ 1 0 0 0 ]
[ * 4 0 0 ]
[ * * 332 0 ]
[ * * * 2322672 ]
}}}

{{{id=35|
LNF.local_density(p = next_prime(2^10), m=1)
///

1062960/1062961
}}}

<h2><span style="font-family: arial,helvetica,sans-serif;">Global Invariants</span></h2>
<p><span style="font-family: arial,helvetica,sans-serif;">Sage also computes Global Invariants of QFs such as automorphisms, representation numbers, and theta series.&nbsp; In general, class numbers can also be computed.&nbsp; Currently there is group working on implementing this in Sage.</span></p>
<p><span style="font-family: arial,helvetica,sans-serif;">Here you can find the automorphisms of Q or just the number of automorphisms of Q.<br /></span></p>
<p><span style="font-family: arial,helvetica,sans-serif;"><br /></span></p>

{{{id=63|
Q.automorphisms()
///

[[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 1], [ 1  2  3  4]
[ 0 -1  0  0]
[ 0  0 -1  0]
[ 0  0  0 -1], [-1 -2 -3 -4]
[ 0  1  0  0]
[ 0  0  1  0]
[ 0  0  0  1], [-1  0  0  0]
[ 0 -1  0  0]
[ 0  0 -1  0]
[ 0  0  0 -1]]
}}}

{{{id=64|
Q.number_of_automorphisms()
///

4
}}}

<p><span style="font-family: arial,helvetica,sans-serif;">If a is in R, then the representation number of a and Q is r(Q,a) = #$\{x \in R^n |&nbsp; Q(x) = a \}$.&nbsp; Sage has the functions <span style="font-family: courier new,courier;">representation_number_list</span>&nbsp; and <span style="font-family: courier new,courier;">representation_vector_list</span>.&nbsp; The first takes as input an integer b and computes a list of the representation numbers a from 0 to b-1</span>.&nbsp; <span style="font-family: arial,helvetica,sans-serif;">The second computes the vectors x such that Q(x) = a for a 0 from b</span>.</p>

{{{id=65|
Q.representation_number_list(3)
///

[1, 2, 0]
}}}

{{{id=34|
Q.representation_vector_list(5)
///

[[(0, 0, 0, 0)], [(1, 0, 0, 0), (-1, 0, 0, 0)], [], [], [(-1, 1, 0, 0), (1, -1, 0, 0), (2, 0, 0, 0), (-2, 0, 0, 0)]]
}}}

<p><span style="font-family: arial,helvetica,sans-serif;">Following computing represenation numbers, Sage also computes $\Theta$ series of QFs.&nbsp; The $\Theta$ series is defined to be $\Theta(q) = \sum_{m \geq 0} r</span><span style="font-family: arial,helvetica,sans-serif;">(Q,a)$$e^{2\pi i m q}$. Sage outputs the $\Theta$ series as a power series in the variable given (the default is 'q').&nbsp; The default is to give the first 10 terms, however by passing an integer in the function Sage can give more terms.<br /></span></p>

{{{id=40|
Q.theta_series()
///

1 + 2*q + 4*q^4 + 4*q^5 + 6*q^6 + 10*q^7 + 12*q^8 + 10*q^9 + O(q^10)
}}}

{{{id=27|
Q.theta_series(15)
///

1 + 2*q + 4*q^4 + 4*q^5 + 6*q^6 + 10*q^7 + 12*q^8 + 10*q^9 + 4*q^10 + 8*q^11 + 4*q^12 + 26*q^13 + 4*q^14 + O(q^15)
}}}

<p><span style="font-family: arial,helvetica,sans-serif;">This is just a brief overview of the main Quadratic Forms functionality found in Sage and what should and might not be in Sage. Hopefully by the time you read this we will also have similar pages for Quaternion Algebras and Automorphic forms.&nbsp; Happy mathing!<br /></span></p>

{{{id=29|

///
}}}

{{{id=30|

///
}}}

<p><span style="font-family: arial,helvetica,sans-serif;"><br /></span></p>

{{{id=16|

///
}}}

{{{id=13|

///
}}}

{{{id=0|

///
}}}

{{{id=7|

///
}}}