3030from sage .matrix .matrix_space import MatrixSpace
3131from sage .misc .functional import denominator , is_even
3232from sage .misc .lazy_import import lazy_import
33- from sage .misc .superseded import deprecated_function_alias
3433from sage .modules .free_module_element import vector
3534from sage .quadratic_forms .quadratic_form__evaluate import (
3635 QFEvaluateMatrix ,
3736 QFEvaluateVector ,
3837)
3938from sage .rings .ideal import Ideal
40- from sage .rings .integer_ring import ZZ , IntegerRing
39+ from sage .rings .integer_ring import ZZ
4140from sage .rings .polynomial .multi_polynomial import MPolynomial
4241from sage .rings .polynomial .polynomial_element import Polynomial
4342from sage .rings .polynomial .polynomial_ring_constructor import PolynomialRing
@@ -120,23 +119,23 @@ def quadratic_form_from_invariants(F, rk, det, P, sminus):
120119 f = 0
121120 if sminus % 4 in (2 , 3 ):
122121 f = 1
123- if (f + len (P )) % 2 == 1 :
122+ if (f + len (P )) % 2 :
124123 raise ValueError ("invariants do not define a rational quadratic form" )
125124 D = []
126125 while rk >= 2 :
127126 if rk >= 4 :
128127 if sminus > 0 :
129128 a = ZZ (- 1 )
130129 else :
131- a = ZZ ( 1 )
130+ a = ZZ . one ( )
132131 elif rk == 3 :
133132 Pprime = [p for p in P if hilbert_symbol (- 1 , - d , p ) == 1 ]
134133 Pprime += [p for p in (2 * d ).prime_divisors ()
135134 if hilbert_symbol (- 1 , - d , p ) == - 1 and p not in P ]
136135 if sminus > 0 :
137136 a = ZZ (- 1 )
138137 else :
139- a = ZZ ( 1 )
138+ a = ZZ . one ( )
140139 for p in Pprime :
141140 if d .valuation (p ) % 2 == 0 :
142141 a *= p
@@ -650,11 +649,13 @@ def __init__(
650649 self .__det = determinant
651650 self ._external_initialization_list .append ('determinant' )
652651
653- def list_external_initializations (self ):
652+ def list_external_initializations (self ) -> list :
654653 """
655654 Return a list of the fields which were set externally at
656655 creation, and not created through the usual :class:`QuadraticForm`
657- methods. These fields are as good as the external process
656+ methods.
657+
658+ These fields are as good as the external process
658659 that made them, and are thus not guaranteed to be correct.
659660
660661 EXAMPLES::
@@ -728,7 +729,7 @@ def _repr_(self) -> str:
728729 out_str += '\n '
729730 out_str += "[ "
730731 for j in range (n ):
731- if ( i > j ) :
732+ if i > j :
732733 out_str += "* "
733734 else :
734735 out_str += str (self [i , j ]) + " "
@@ -752,7 +753,7 @@ def _latex_(self) -> str:
752753 out_str += "\\ left[ \\ begin{array}{" + n * "c" + "}"
753754 for i in range (n ):
754755 for j in range (n ):
755- if ( i > j ) :
756+ if i > j :
756757 out_str += " * & "
757758 else :
758759 out_str += str (self [i , j ]) + " & "
@@ -780,11 +781,9 @@ def __getitem__(self, ij):
780781
781782 # Ensure we're using upper-triangular coordinates
782783 if i > j :
783- tmp = i
784- i = j
785- j = tmp
784+ i , j = j , i
786785
787- return self .__coeffs [i * self .__n - i * ( i - 1 ) // 2 + j - i ]
786+ return self .__coeffs [i * self .__n - i * ( i - 1 ) // 2 + j - i ]
788787
789788 def __setitem__ (self , ij , coeff ):
790789 r"""
@@ -814,13 +813,11 @@ def __setitem__(self, ij, coeff):
814813
815814 # Ensure we're using upper-triangular coordinates
816815 if i > j :
817- tmp = i
818- i = j
819- j = tmp
816+ i , j = j , i
820817
821818 # Set the entry
822819 try :
823- self .__coeffs [i * self .__n - i * ( i - 1 ) // 2 + j - i ] = self .__base_ring (coeff )
820+ self .__coeffs [i * self .__n - i * ( i - 1 ) // 2 + j - i ] = self .__base_ring (coeff )
824821 except Exception :
825822 raise RuntimeError ("this coefficient cannot be coerced to an element of the base ring for the quadratic form" )
826823
@@ -884,7 +881,7 @@ def __add__(self, right):
884881 """
885882 if not isinstance (right , QuadraticForm ):
886883 raise TypeError ("cannot add these objects since they are not both quadratic forms" )
887- elif ( self .base_ring () != right .base_ring () ):
884+ elif self .base_ring () != right .base_ring ():
888885 raise TypeError ("cannot add these since the quadratic forms do not have the same base rings" )
889886
890887 Q = QuadraticForm (self .base_ring (), self .dim () + right .dim ())
@@ -1106,7 +1103,7 @@ def _is_even_symmetric_matrix_(self, A, R=None):
11061103
11071104 # Test that all entries coerce to R
11081105 n = A .nrows ()
1109- if not (( A .base_ring () == R ) or ring_coerce_test ):
1106+ if not (A .base_ring () == R or ring_coerce_test ):
11101107 try :
11111108 for i in range (n ):
11121109 for j in range (i , n ):
@@ -1186,7 +1183,7 @@ def Gram_matrix_rational(self):
11861183 sage: A.base_ring()
11871184 Rational Field
11881185 """
1189- return (ZZ ( 1 ) / ZZ (2 )) * self .matrix ()
1186+ return (ZZ . one ( ) / ZZ (2 )) * self .matrix ()
11901187
11911188 def Gram_matrix (self ):
11921189 r"""
@@ -1558,13 +1555,13 @@ def change_ring(self, R):
15581555 # Return the coerced form
15591556 return QuadraticForm (R , self .dim (), [R (x ) for x in self .coefficients ()])
15601557
1561- base_change_to = deprecated_function_alias (35248 , change_ring )
1562-
15631558 def level (self ):
15641559 r"""
1565- Determines the level of the quadratic form over a PID, which is a
1566- generator for the smallest ideal `N` of `R` such that `N\cdot (` the matrix of
1567- `2*Q` `)^{(-1)}` is in `R` with diagonal in `2R`.
1560+ Determine the level of the quadratic form over a PID.
1561+
1562+ This is a generator for the smallest ideal `N` of `R` such
1563+ that `N\cdot (` the matrix of `2*Q` `)^{(-1)}` is in `R` with
1564+ diagonal in `2R`.
15681565
15691566 Over `\ZZ` this returns a nonnegative number.
15701567
@@ -1610,7 +1607,7 @@ def level(self):
16101607 inv_denoms = []
16111608 for i in range (self .dim ()):
16121609 for j in range (i , self .dim ()):
1613- if ( i == j ) :
1610+ if i == j :
16141611 inv_denoms += [denominator (mat_inv [i , j ] / 2 )]
16151612 else :
16161613 inv_denoms += [denominator (mat_inv [i , j ])]
@@ -1623,7 +1620,7 @@ def level(self):
16231620 ##############################################################
16241621
16251622 # Normalize the result over ZZ
1626- if self .base_ring () == IntegerRing () :
1623+ if self .base_ring () == ZZ :
16271624 lvl = abs (lvl )
16281625
16291626 # Cache and return the level
@@ -1632,10 +1629,13 @@ def level(self):
16321629
16331630 def level_ideal (self ):
16341631 r"""
1635- Determine the level of the quadratic form (over `R`), which is the
1636- smallest ideal `N` of `R` such that `N \cdot (` the matrix of `2Q` `)^{(-1)}` is
1637- in `R` with diagonal in `2R`.
1638- (Caveat: This always returns the principal ideal when working over a field!)
1632+ Determine the level of the quadratic form (over `R`).
1633+
1634+ This is the smallest ideal `N` of `R` such that `N \cdot (`
1635+ the matrix of `2Q` `)^{(-1)}` is in `R` with diagonal in `2R`.
1636+
1637+ (Caveat: This always returns the principal ideal when working
1638+ over a field!)
16391639
16401640 .. WARNING::
16411641
@@ -1724,7 +1724,7 @@ def bilinear_map(self, v, w):
17241724 return (self (v + w ) - self (v ) - self (w )) / 2
17251725
17261726
1727- def DiagonalQuadraticForm (R , diag ):
1727+ def DiagonalQuadraticForm (R , diag ) -> QuadraticForm :
17281728 """
17291729 Return a quadratic form over `R` which is a sum of squares.
17301730
0 commit comments