diff --git a/src/sage/quadratic_forms/binary_qf.py b/src/sage/quadratic_forms/binary_qf.py index 880452d9430..555fe01b3ef 100755 --- a/src/sage/quadratic_forms/binary_qf.py +++ b/src/sage/quadratic_forms/binary_qf.py @@ -1928,7 +1928,7 @@ def BinaryQF_reduced_representatives(D, primitive_only=False, proper=True): if D > 0: # Indefinite if D.is_square(): b = D.sqrt() - c = ZZ(0) + c = ZZ.zero() # -b/2 < a <= b/2 for a in xsrange((-b/2).floor() + 1, (b/2).floor() + 1): if not primitive_only or (gcd([a, b, c]) == 1): diff --git a/src/sage/quadratic_forms/genera/genus.py b/src/sage/quadratic_forms/genera/genus.py index d9c298f5f0a..8946683a988 100644 --- a/src/sage/quadratic_forms/genera/genus.py +++ b/src/sage/quadratic_forms/genera/genus.py @@ -1202,7 +1202,7 @@ def two_adic_symbol(A, val): return [[s[0]+m0] + s[1:] for s in sym + two_adic_symbol(A, val)] -class Genus_Symbol_p_adic_ring(): +class Genus_Symbol_p_adic_ring: r""" Local genus symbol over a `p`-adic ring. @@ -2132,7 +2132,7 @@ def direct_sum(self, other): def excess(self): r""" - Returns the `p`-excess of the quadratic form whose Hessian + Return the `p`-excess of the quadratic form whose Hessian matrix is the symmetric matrix `A`. When `p = 2`, the `p`-excess is called the oddity. @@ -2242,7 +2242,7 @@ def norm(self): sage: G = Genus(matrix(ZZ,2,[0, 1, 1, 0])) sage: G.local_symbol(2).norm() 2 - """ + """ if self.rank() == 0: return ZZ(0) p = self.prime() @@ -2321,7 +2321,7 @@ def compartments(self): return canonical_2_adic_compartments(symbol) -class GenusSymbol_global_ring(): +class GenusSymbol_global_ring: r""" This represents a collection of local genus symbols (at primes) and signature information which represent the genus of a diff --git a/src/sage/quadratic_forms/qfsolve.py b/src/sage/quadratic_forms/qfsolve.py index 85116e43f9e..ff91830874c 100644 --- a/src/sage/quadratic_forms/qfsolve.py +++ b/src/sage/quadratic_forms/qfsolve.py @@ -213,7 +213,7 @@ def solve(self, c=0): if not c: x = qfsolve(M) if isinstance(x, Integer): - raise ArithmeticError("no solution found (local obstruction at {})".format(x)) + raise ArithmeticError(f"no solution found (local obstruction at {x})") return x # If c != 0, define a new quadratic form Q = self - c*z^2 @@ -228,7 +228,7 @@ def solve(self, c=0): x = qfsolve(N) # Raise an error if qfsolve() doesn't find a solution if isinstance(x, Integer): - raise ArithmeticError("no solution found (local obstruction at {})".format(x)) + raise ArithmeticError(f"no solution found (local obstruction at {x})") # Let z be the last term of x, and remove z from x z = x[-1] diff --git a/src/sage/quadratic_forms/quadratic_form.py b/src/sage/quadratic_forms/quadratic_form.py index 3db01b9fe2f..c78e7badeb4 100644 --- a/src/sage/quadratic_forms/quadratic_form.py +++ b/src/sage/quadratic_forms/quadratic_form.py @@ -305,200 +305,200 @@ class QuadraticForm(SageObject): # Routines to compute the p-adic local normal form lazy_import("sage.quadratic_forms.quadratic_form__local_normal_form", [ - "find_entry_with_minimal_scale_at_prime", - "local_normal_form", - "jordan_blocks_by_scale_and_unimodular", - "jordan_blocks_in_unimodular_list_by_scale_power" - ]) + "find_entry_with_minimal_scale_at_prime", + "local_normal_form", + "jordan_blocks_by_scale_and_unimodular", + "jordan_blocks_in_unimodular_list_by_scale_power" + ]) # Routines to perform elementary variable substitutions from sage.quadratic_forms.quadratic_form__variable_substitutions import \ - swap_variables, \ - multiply_variable, \ - divide_variable, \ - scale_by_factor, \ - extract_variables, \ - elementary_substitution, \ - add_symmetric + swap_variables, \ + multiply_variable, \ + divide_variable, \ + scale_by_factor, \ + extract_variables, \ + elementary_substitution, \ + add_symmetric # Routines to compute p-adic field invariants from sage.quadratic_forms.quadratic_form__local_field_invariants import \ - rational_diagonal_form, \ - _rational_diagonal_form_and_transformation, \ - signature_vector, \ - signature, \ - hasse_invariant, \ - hasse_invariant__OMeara, \ - is_hyperbolic, \ - is_anisotropic, \ - is_isotropic, \ - anisotropic_primes, \ - compute_definiteness, \ - compute_definiteness_string_by_determinants, \ - is_positive_definite, \ - is_negative_definite, \ - is_indefinite, \ - is_definite + rational_diagonal_form, \ + _rational_diagonal_form_and_transformation, \ + signature_vector, \ + signature, \ + hasse_invariant, \ + hasse_invariant__OMeara, \ + is_hyperbolic, \ + is_anisotropic, \ + is_isotropic, \ + anisotropic_primes, \ + compute_definiteness, \ + compute_definiteness_string_by_determinants, \ + is_positive_definite, \ + is_negative_definite, \ + is_indefinite, \ + is_definite # Routines to compute local densities by the reduction procedure from sage.quadratic_forms.quadratic_form__local_density_congruence import \ - count_modp_solutions__by_Gauss_sum, \ - local_good_density_congruence_odd, \ - local_good_density_congruence_even, \ - local_good_density_congruence, \ - local_zero_density_congruence, \ - local_badI_density_congruence, \ - local_badII_density_congruence, \ - local_bad_density_congruence, \ - local_density_congruence, \ - local_primitive_density_congruence + count_modp_solutions__by_Gauss_sum, \ + local_good_density_congruence_odd, \ + local_good_density_congruence_even, \ + local_good_density_congruence, \ + local_zero_density_congruence, \ + local_badI_density_congruence, \ + local_badII_density_congruence, \ + local_bad_density_congruence, \ + local_density_congruence, \ + local_primitive_density_congruence # Routines to compute local densities by counting solutions of various types from sage.quadratic_forms.quadratic_form__count_local_2 import \ - count_congruence_solutions_as_vector, \ - count_congruence_solutions, \ - count_congruence_solutions__good_type, \ - count_congruence_solutions__zero_type, \ - count_congruence_solutions__bad_type, \ - count_congruence_solutions__bad_type_I, \ - count_congruence_solutions__bad_type_II + count_congruence_solutions_as_vector, \ + count_congruence_solutions, \ + count_congruence_solutions__good_type, \ + count_congruence_solutions__zero_type, \ + count_congruence_solutions__bad_type, \ + count_congruence_solutions__bad_type_I, \ + count_congruence_solutions__bad_type_II # Routines to be called by the user to compute local densities lazy_import("sage.quadratic_forms.quadratic_form__local_density_interfaces", [ - "local_density", - "local_primitive_density" - ]) + "local_density", + "local_primitive_density" + ]) # Routines for computing with ternary forms from sage.quadratic_forms.quadratic_form__ternary_Tornaria import \ - disc, \ - content, \ - adjoint, \ - antiadjoint, \ - is_adjoint, \ - reciprocal, \ - omega, \ - delta, \ - level__Tornaria, \ - discrec, \ - hasse_conductor, \ - clifford_invariant, \ - clifford_conductor, \ - basiclemma, \ - basiclemmavec, \ - xi, \ - xi_rec, \ - lll, \ - representation_number_list, \ - representation_vector_list, \ - is_zero, \ - is_zero_nonsingular, \ - is_zero_singular + disc, \ + content, \ + adjoint, \ + antiadjoint, \ + is_adjoint, \ + reciprocal, \ + omega, \ + delta, \ + level__Tornaria, \ + discrec, \ + hasse_conductor, \ + clifford_invariant, \ + clifford_conductor, \ + basiclemma, \ + basiclemmavec, \ + xi, \ + xi_rec, \ + lll, \ + representation_number_list, \ + representation_vector_list, \ + is_zero, \ + is_zero_nonsingular, \ + is_zero_singular # Routines to compute the theta function from sage.quadratic_forms.quadratic_form__theta import \ - theta_series, \ - theta_series_degree_2, \ - theta_by_pari, \ - theta_by_cholesky + theta_series, \ + theta_series_degree_2, \ + theta_by_pari, \ + theta_by_cholesky # Routines to compute the product of all local densities lazy_import("sage.quadratic_forms.quadratic_form__siegel_product", [ - "siegel_product" - ]) + "siegel_product" + ]) # Routines to compute p-neighbors from sage.quadratic_forms.quadratic_form__neighbors import \ - find_primitive_p_divisible_vector__random, \ - find_primitive_p_divisible_vector__next, \ - find_p_neighbor_from_vec, \ - neighbor_iteration, \ - orbits_lines_mod_p + find_primitive_p_divisible_vector__random, \ + find_primitive_p_divisible_vector__next, \ + find_p_neighbor_from_vec, \ + neighbor_iteration, \ + orbits_lines_mod_p # Routines to reduce a given quadratic form from sage.quadratic_forms.quadratic_form__reduction_theory import \ - reduced_binary_form1, \ - reduced_ternary_form__Dickson, \ - reduced_binary_form, \ - minkowski_reduction, \ - minkowski_reduction_for_4vars__SP + reduced_binary_form1, \ + reduced_ternary_form__Dickson, \ + reduced_binary_form, \ + minkowski_reduction, \ + minkowski_reduction_for_4vars__SP # Wrappers for Conway-Sloane genus routines (in ./genera/) lazy_import("sage.quadratic_forms.quadratic_form__genus", [ - "global_genus_symbol", - "local_genus_symbol", - "CS_genus_symbol_list" - ]) + "global_genus_symbol", + "local_genus_symbol", + "CS_genus_symbol_list" + ]) # Routines to compute local masses for ZZ. lazy_import("sage.quadratic_forms.quadratic_form__mass", [ - "shimura_mass__maximal", - "GHY_mass__maximal" - ]) + "shimura_mass__maximal", + "GHY_mass__maximal" + ]) lazy_import("sage.quadratic_forms.quadratic_form__mass__Siegel_densities", [ - "mass__by_Siegel_densities", - "Pall_mass_density_at_odd_prime", - "Watson_mass_at_2", - "Kitaoka_mass_at_2", - "mass_at_two_by_counting_mod_power" - ]) + "mass__by_Siegel_densities", + "Pall_mass_density_at_odd_prime", + "Watson_mass_at_2", + "Kitaoka_mass_at_2", + "mass_at_two_by_counting_mod_power" + ]) lazy_import("sage.quadratic_forms.quadratic_form__mass__Conway_Sloane_masses", [ - "parity", - "is_even", - "is_odd", - "conway_species_list_at_odd_prime", - "conway_species_list_at_2", - "conway_octane_of_this_unimodular_Jordan_block_at_2", - "conway_diagonal_factor", - "conway_cross_product_doubled_power", - "conway_type_factor", - "conway_p_mass", - "conway_standard_p_mass", - "conway_standard_mass", - "conway_mass" -# conway_generic_mass, \ -# conway_p_mass_adjustment - ]) + "parity", + "is_even", + "is_odd", + "conway_species_list_at_odd_prime", + "conway_species_list_at_2", + "conway_octane_of_this_unimodular_Jordan_block_at_2", + "conway_diagonal_factor", + "conway_cross_product_doubled_power", + "conway_type_factor", + "conway_p_mass", + "conway_standard_p_mass", + "conway_standard_mass", + "conway_mass" + # conway_generic_mass, \ + # conway_p_mass_adjustment + ]) # Routines to check local representability of numbers lazy_import("sage.quadratic_forms.quadratic_form__local_representation_conditions", [ - "local_representation_conditions", - "is_locally_universal_at_prime", - "is_locally_universal_at_all_primes", - "is_locally_universal_at_all_places", - "is_locally_represented_number_at_place", - "is_locally_represented_number" - ]) + "local_representation_conditions", + "is_locally_universal_at_prime", + "is_locally_universal_at_all_primes", + "is_locally_universal_at_all_places", + "is_locally_represented_number_at_place", + "is_locally_represented_number" + ]) # Routines to make a split local covering of the given quadratic form. from sage.quadratic_forms.quadratic_form__split_local_covering import \ - cholesky_decomposition, \ - vectors_by_length, \ - complementary_subform_to_vector, \ - split_local_cover + cholesky_decomposition, \ + vectors_by_length, \ + complementary_subform_to_vector, \ + split_local_cover # Routines to make automorphisms of the given quadratic form. lazy_import("sage.quadratic_forms.quadratic_form__automorphisms", [ - "basis_of_short_vectors", - "short_vector_list_up_to_length", - "short_primitive_vector_list_up_to_length", - "_compute_automorphisms", - "automorphism_group", - "automorphisms", - "number_of_automorphisms", - "set_number_of_automorphisms" - ]) + "basis_of_short_vectors", + "short_vector_list_up_to_length", + "short_primitive_vector_list_up_to_length", + "_compute_automorphisms", + "automorphism_group", + "automorphisms", + "number_of_automorphisms", + "set_number_of_automorphisms" + ]) # Routines to test the local and global equivalence/isometry of two quadratic forms. from sage.quadratic_forms.quadratic_form__equivalence_testing import \ - is_globally_equivalent_to, \ - is_locally_equivalent_to, \ - has_equivalent_Jordan_decomposition_at_prime, \ - is_rationally_isometric + is_globally_equivalent_to, \ + is_locally_equivalent_to, \ + has_equivalent_Jordan_decomposition_at_prime, \ + is_rationally_isometric # Routines for solving equations of the form Q(x) = c. lazy_import("sage.quadratic_forms.qfsolve", [ - "solve" - ]) + "solve" + ]) # Genus lazy_import("sage.quadratic_forms.genera.genus", @@ -617,7 +617,7 @@ def __init__(self, R, n=None, entries=None, unsafe_initialization=False, number_ # Verify the size of the matrix is an integer >= 0 n = ZZ(n) if n < 0: - raise ValueError("the size must be a non-negative integer, not {}".format(n)) + raise ValueError(f"the size must be a non-negative integer, not {n}") # Store the relevant variables N = n * (n + 1) // 2 @@ -738,7 +738,7 @@ def _repr_(self): if (i > j): out_str += "* " else: - out_str += str(self[i,j]) + " " + out_str += str(self[i, j]) + " " out_str += "]" return out_str @@ -762,7 +762,7 @@ def _latex_(self): if (i > j): out_str += " * & " else: - out_str += str(self[i,j]) + " & " + out_str += str(self[i, j]) + " & " # if i < (n-1): # out_str += "\\" out_str += "\\end{array} \\right]" @@ -1051,7 +1051,7 @@ def __call__(self, v): if is_Matrix(v): # Check that v has the correct number of rows if v.nrows() != n: - raise TypeError("the matrix must have {} rows".format(n)) + raise TypeError(f"the matrix must have {n} rows") # Create the new quadratic form m = v.ncols() @@ -1061,7 +1061,7 @@ def __call__(self, v): elif (is_Vector(v) or isinstance(v, (list, tuple))): # Check the vector/tuple/list has the correct length if not (len(v) == n): - raise TypeError("your vector needs to have length {}".format(n)) + raise TypeError(f"your vector needs to have length {n}") # TO DO: Check that the elements can be coerced into the base ring of Q -- on first elt. if len(v) > 0: @@ -1291,7 +1291,7 @@ def gcd(self): raise TypeError("the given quadratic form must be defined over ZZ") return GCD(self.coefficients()) - def polynomial(self,names='x'): + def polynomial(self, names='x'): r""" Return the quadratic form as a polynomial in `n` variables. @@ -1335,7 +1335,7 @@ def polynomial(self,names='x'): M = matrix(B, n) for i in range(n): for j in range(i, n): - M[i,j] = self[i,j] + M[i, j] = self[i, j] try: R = PolynomialRing(self.base_ring(), names, n) except Exception: @@ -1379,17 +1379,16 @@ def from_polynomial(poly): raise ValueError('polynomial has monomials of degree != 2') base = R.base_ring() vs = R.gens() - coeffs = [] - for i, v in enumerate(vs): - for w in vs[i:]: - coeffs.append(poly.monomial_coefficient(v*w)) + coeffs = [poly.monomial_coefficient(v * w) + for i, v in enumerate(vs) for w in vs[i:]] return QuadraticForm(base, len(vs), coeffs) - def is_primitive(self): + def is_primitive(self) -> bool: """ - Determines if the given integer-valued form is primitive - (i.e. not an integer (`> 1`) multiple of another integer-valued - quadratic form). + Determine if the given integer-valued form is primitive. + + This means not an integer (`> 1`) multiple of another integer-valued + quadratic form. EXAMPLES:: @@ -1399,9 +1398,8 @@ def is_primitive(self): sage: Q = QuadraticForm(ZZ, 2, [2,4,8]) sage: Q.is_primitive() False - """ - return (self.gcd() == 1) + return self.gcd() == 1 def primitive(self): r""" @@ -1630,9 +1628,9 @@ def level(self): for i in range(self.dim()): for j in range(i, self.dim()): if (i == j): - inv_denoms += [denominator(mat_inv[i,j] / 2)] + inv_denoms += [denominator(mat_inv[i, j] / 2)] else: - inv_denoms += [denominator(mat_inv[i,j])] + inv_denoms += [denominator(mat_inv[i, j])] lvl = LCM(inv_denoms) lvl = Ideal(self.base_ring()(lvl)).gen() ############################################################## diff --git a/src/sage/quadratic_forms/quadratic_form__automorphisms.py b/src/sage/quadratic_forms/quadratic_form__automorphisms.py index 175f447bbea..4b6e3594f83 100644 --- a/src/sage/quadratic_forms/quadratic_form__automorphisms.py +++ b/src/sage/quadratic_forms/quadratic_form__automorphisms.py @@ -78,10 +78,8 @@ def basis_of_short_vectors(self, show_lengths=False): vector_list_by_length[l].append(vector([-x for x in v])) # Make a matrix from the column vectors (in order of ascending length). - sorted_list = [] - for i in range(len(vector_list_by_length)): - for v in vector_list_by_length[i]: - sorted_list.append(v) + sorted_list = [v for i in range(len(vector_list_by_length)) + for v in vector_list_by_length[i]] sorted_matrix = Matrix(sorted_list).transpose() # Determine a basis of vectors of minimal length @@ -205,7 +203,7 @@ def short_vector_list_up_to_length(self, len_bound, up_to_sign_flag=False): parilens = pari(r"(M,v) -> vector(#v, i, (v[i]~ * M * v[i])\2)")(self, parilist) # Sort the vectors into lists by their length - vec_sorted_list = [list() for i in range(len_bound)] + vec_sorted_list = [[] for i in range(len_bound)] for i in range(len(parilist)): length = int(parilens[i]) # In certain trivial cases, PARI can sometimes return longer diff --git a/src/sage/quadratic_forms/quadratic_form__equivalence_testing.py b/src/sage/quadratic_forms/quadratic_form__equivalence_testing.py index 148fcbd21f2..2bd4df8f890 100644 --- a/src/sage/quadratic_forms/quadratic_form__equivalence_testing.py +++ b/src/sage/quadratic_forms/quadratic_form__equivalence_testing.py @@ -442,9 +442,9 @@ def is_rationally_isometric(self, other, return_matrix=False): sage: V.is_rationally_isometric(W) Traceback (most recent call last): ... - NotImplementedError: This only tests regular forms + NotImplementedError: this only tests regular forms - Forms must have the same base ring otherwise a `TypeError` is raised:: + Forms must have the same base ring otherwise a :class:`TypeError` is raised:: sage: # needs sage.rings.number_field sage: K1. = QuadraticField(5) @@ -491,7 +491,7 @@ def is_rationally_isometric(self, other, return_matrix=False): True """ if self.Gram_det() == 0 or other.Gram_det() == 0: - raise NotImplementedError("This only tests regular forms") + raise NotImplementedError("this only tests regular forms") if self.base_ring() != other.base_ring(): raise TypeError("forms must have the same base ring.") diff --git a/src/sage/quadratic_forms/quadratic_form__genus.py b/src/sage/quadratic_forms/quadratic_form__genus.py index 8727645b453..52468e9889a 100644 --- a/src/sage/quadratic_forms/quadratic_form__genus.py +++ b/src/sage/quadratic_forms/quadratic_form__genus.py @@ -133,10 +133,8 @@ def CS_genus_symbol_list(self, force_recomputation=False): pass # Otherwise recompute and cache the list - list_of_CS_genus_symbols = [] - - for p in prime_divisors(2 * self.det()): - list_of_CS_genus_symbols.append(self.local_genus_symbol(p)) + list_of_CS_genus_symbols = [self.local_genus_symbol(p) + for p in prime_divisors(2 * self.det())] self.__CS_genus_symbol_list = list_of_CS_genus_symbols return list_of_CS_genus_symbols diff --git a/src/sage/quadratic_forms/quadratic_form__local_representation_conditions.py b/src/sage/quadratic_forms/quadratic_form__local_representation_conditions.py index 888f4ae2832..c337d2994a0 100644 --- a/src/sage/quadratic_forms/quadratic_form__local_representation_conditions.py +++ b/src/sage/quadratic_forms/quadratic_form__local_representation_conditions.py @@ -17,7 +17,7 @@ from sage.rings.rational_field import QQ -class QuadraticFormLocalRepresentationConditions(): +class QuadraticFormLocalRepresentationConditions: """ A class for dealing with the local conditions of a quadratic form, and checking local representability of numbers. diff --git a/src/sage/quadratic_forms/quadratic_form__mass__Siegel_densities.py b/src/sage/quadratic_forms/quadratic_form__mass__Siegel_densities.py index a99eb439e0f..9133a84b76f 100644 --- a/src/sage/quadratic_forms/quadratic_form__mass__Siegel_densities.py +++ b/src/sage/quadratic_forms/quadratic_form__mass__Siegel_densities.py @@ -197,8 +197,8 @@ def Watson_mass_at_2(self): s_max = max(scale_list) # Step 1: Compute dictionaries of the diagonal block and 2x2 block for each scale - diag_dict = dict((i, Null_Form) for i in range(s_min - 2, s_max + 4)) # Initialize with the zero form - dim2_dict = dict((i, Null_Form) for i in range(s_min, s_max + 4)) # Initialize with the zero form + diag_dict = {i: Null_Form for i in range(s_min - 2, s_max + 4)} # Initialize with the zero form + dim2_dict = {i: Null_Form for i in range(s_min, s_max + 4)} # Initialize with the zero form for s, L in Jordan_Blocks: i = 0 while i < L.dim() - 1 and L[i, i + 1] == 0: # Find where the 2x2 blocks start @@ -210,8 +210,8 @@ def Watson_mass_at_2(self): diag_dict[s] = L # Step 2: Compute three dictionaries of invariants (for n_j, m_j, nu_j) - n_dict = dict((j, 0) for j in range(s_min + 1, s_max + 2)) - m_dict = dict((j, 0) for j in range(s_min, s_max + 4)) + n_dict = {j: 0 for j in range(s_min + 1, s_max + 2)} + m_dict = {j: 0 for j in range(s_min, s_max + 4)} for s, L in Jordan_Blocks: n_dict[s + 1] = L.dim() if diag_dict[s].dim() == 0: @@ -219,8 +219,8 @@ def Watson_mass_at_2(self): else: m_dict[s + 1] = ZZ(L.dim() - 1) // ZZ(2) - nu_dict = dict((j, n_dict[j + 1] - 2 * m_dict[j + 1]) - for j in range(s_min, s_max + 1)) + nu_dict = {j: n_dict[j + 1] - 2 * m_dict[j + 1] + for j in range(s_min, s_max + 1)} nu_dict[s_max + 1] = 0 # Step 3: Compute the e_j dictionary @@ -280,8 +280,8 @@ def Kitaoka_mass_at_2(self): s_max = max(scale_list) # Step 1: Compute dictionaries of the diagonal block and 2x2 block for each scale - diag_dict = dict((i, Null_Form) for i in range(s_min - 2, s_max + 4)) # Initialize with the zero form - dim2_dict = dict((i, Null_Form) for i in range(s_min, s_max + 4)) # Initialize with the zero form + diag_dict = {i: Null_Form for i in range(s_min - 2, s_max + 4)} # Initialize with the zero form + dim2_dict = {i: Null_Form for i in range(s_min, s_max + 4)} # Initialize with the zero form for s, L in Jordan_Blocks: i = 0 while i < L.dim() - 1 and L[i, i + 1] == 0: # Find where the 2x2 blocks start