Path: blob/master/sage/quadratic_forms/quadratic_form__genus.py
4100 views
"""1Local and Global Genus Symbols23"""456#############################################################7## ##8## Wrappers for the Genus/Genus Symbol Code in ../genera/ ##9## ##10#############################################################1112from sage.quadratic_forms.genera.genus import Genus, LocalGenusSymbol, \13is_GlobalGenus, is_2_adic_genus, canonical_2_adic_compartments, \14canonical_2_adic_trains, canonical_2_adic_reduction, \15basis_complement, p_adic_symbol, is_even_matrix, \16split_odd, trace_diag_mod_8, two_adic_symbol17#is_trivial_symbol18#GenusSymbol_p_adic_ring, GenusSymbol_global_ring1920## Removed signature_pair_of_matrix due to a circular import issue.2122## NOTE: Removed the signature routine here... and rewrote it for now.232425from sage.rings.integer_ring import IntegerRing26from sage.rings.arith import is_prime, prime_divisors27282930def global_genus_symbol(self):31"""32Returns the genus of a two times a quadratic form over ZZ. These33are defined by a collection of local genus symbols (a la Chapter3415 of Conway-Sloane), and a signature.3536EXAMPLES::3738sage: Q = DiagonalQuadraticForm(ZZ, [1,2,3,4])39sage: Q.global_genus_symbol()40Genus of [2 0 0 0]41[0 4 0 0]42[0 0 6 0]43[0 0 0 8]4445::4647sage: Q = QuadraticForm(ZZ, 4, range(10))48sage: Q.global_genus_symbol()49Genus of [ 0 1 2 3]50[ 1 8 5 6]51[ 2 5 14 8]52[ 3 6 8 18]5354"""55## Check that the form is defined over ZZ56if not self.base_ring() == IntegerRing():57raise TypeError, "Oops! The quadratic form is not defined over the integers."5859## Return the result60try:61return Genus(self.Hessian_matrix())62except:63raise TypeError, "Oops! There is a problem computing the genus symbols for this form."64656667def local_genus_symbol(self, p):68"""69Returns the Conway-Sloane genus symbol of 2 times a quadratic form70defined over ZZ at a prime number p. This is defined (in the71Genus_Symbol_p_adic_ring() class in the quadratic_forms/genera72subfolder) to be a list of tuples (one for each Jordan component73p^m*A at p, where A is a unimodular symmetric matrix with74coefficients the p-adic integers) of the following form:75761. If p>2 then return triples of the form [`m`, `n`, `d`] where77`m` = valuation of the component7879`n` = rank of A8081`d` = det(A) in {1,u} for normalized quadratic non-residue u.82832. If p=2 then return quintuples of the form [`m`,`n`,`s`, `d`, `o`] where84`m` = valuation of the component8586`n` = rank of A8788`d` = det(A) in {1,3,5,7}8990`s` = 0 (or 1) if A is even (or odd)9192`o` = oddity of A (= 0 if s = 0) in Z/8Z93= the trace of the diagonalization of A9495NOTE: The Conway-Sloane convention for describing the prime 'p =96-1' is not supported here, and neither is the convention for97including the 'prime' Infinity. See note on p370 of Conway-Sloane98(3rd ed) for a discussion of this convention.99100INPUT:101102-`p` -- a prime number > 0103104OUTPUT:105Returns a Conway-Sloane genus symbol at p, which is an106instance of the Genus_Symbol_p_adic_ring class.107108EXAMPLES::109110sage: Q = DiagonalQuadraticForm(ZZ, [1,2,3,4])111sage: Q.local_genus_symbol(2)112Genus symbol at 2 : [[1, 2, 3, 1, 4], [2, 1, 1, 1, 1], [3, 1, 1, 1, 1]]113sage: Q.local_genus_symbol(3)114Genus symbol at 3 : [[0, 3, 1], [1, 1, -1]]115sage: Q.local_genus_symbol(5)116Genus symbol at 5 : [[0, 4, 1]]117118"""119## Check that p is prime and that the form is defined over ZZ.120if not is_prime(p):121raise TypeError, "Oops! The number " + str(p) + " isn't prime."122if not self.base_ring() == IntegerRing():123raise TypeError, "Oops! The quadratic form is not defined over the integers."124125## Return the result126try:127M = self.Hessian_matrix()128return LocalGenusSymbol(M, p)129except:130raise TypeError, "Oops! There is a problem computing the local genus symbol at the prime " + str(p) + " for this form."131132133134135136137def CS_genus_symbol_list(self, force_recomputation=False):138"""139Returns the list of Conway-Sloane genus symbols in increasing order of primes dividing 2*det.140141EXAMPLES::142143sage: Q = DiagonalQuadraticForm(ZZ, [1,2,3,4])144sage: Q.CS_genus_symbol_list()145[Genus symbol at 2 : [[1, 2, 3, 1, 4], [2, 1, 1, 1, 1], [3, 1, 1, 1, 1]],146Genus symbol at 3 : [[0, 3, 1], [1, 1, -1]]]147148"""149## Try to use the cached list150if force_recomputation == False:151try:152return self.__CS_genus_symbol_list153except:154pass155156## Otherwise recompute and cache the list157list_of_CS_genus_symbols = [ ]158159for p in prime_divisors(2 * self.det()):160list_of_CS_genus_symbols.append(self.local_genus_symbol(p))161162self.__CS_genus_symbol_list = list_of_CS_genus_symbols163return list_of_CS_genus_symbols164165166