30
30
from sage .matrix .matrix_space import MatrixSpace
31
31
from sage .misc .functional import denominator , is_even
32
32
from sage .misc .lazy_import import lazy_import
33
- from sage .misc .superseded import deprecated_function_alias
34
33
from sage .modules .free_module_element import vector
35
34
from sage .quadratic_forms .quadratic_form__evaluate import (
36
35
QFEvaluateMatrix ,
37
36
QFEvaluateVector ,
38
37
)
39
38
from sage .rings .ideal import Ideal
40
- from sage .rings .integer_ring import ZZ , IntegerRing
39
+ from sage .rings .integer_ring import ZZ
41
40
from sage .rings .polynomial .multi_polynomial import MPolynomial
42
41
from sage .rings .polynomial .polynomial_element import Polynomial
43
42
from sage .rings .polynomial .polynomial_ring_constructor import PolynomialRing
@@ -120,23 +119,23 @@ def quadratic_form_from_invariants(F, rk, det, P, sminus):
120
119
f = 0
121
120
if sminus % 4 in (2 , 3 ):
122
121
f = 1
123
- if (f + len (P )) % 2 == 1 :
122
+ if (f + len (P )) % 2 :
124
123
raise ValueError ("invariants do not define a rational quadratic form" )
125
124
D = []
126
125
while rk >= 2 :
127
126
if rk >= 4 :
128
127
if sminus > 0 :
129
128
a = ZZ (- 1 )
130
129
else :
131
- a = ZZ ( 1 )
130
+ a = ZZ . one ( )
132
131
elif rk == 3 :
133
132
Pprime = [p for p in P if hilbert_symbol (- 1 , - d , p ) == 1 ]
134
133
Pprime += [p for p in (2 * d ).prime_divisors ()
135
134
if hilbert_symbol (- 1 , - d , p ) == - 1 and p not in P ]
136
135
if sminus > 0 :
137
136
a = ZZ (- 1 )
138
137
else :
139
- a = ZZ ( 1 )
138
+ a = ZZ . one ( )
140
139
for p in Pprime :
141
140
if d .valuation (p ) % 2 == 0 :
142
141
a *= p
@@ -650,11 +649,13 @@ def __init__(
650
649
self .__det = determinant
651
650
self ._external_initialization_list .append ('determinant' )
652
651
653
- def list_external_initializations (self ):
652
+ def list_external_initializations (self ) -> list :
654
653
"""
655
654
Return a list of the fields which were set externally at
656
655
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
658
659
that made them, and are thus not guaranteed to be correct.
659
660
660
661
EXAMPLES::
@@ -728,7 +729,7 @@ def _repr_(self) -> str:
728
729
out_str += '\n '
729
730
out_str += "[ "
730
731
for j in range (n ):
731
- if ( i > j ) :
732
+ if i > j :
732
733
out_str += "* "
733
734
else :
734
735
out_str += str (self [i , j ]) + " "
@@ -752,7 +753,7 @@ def _latex_(self) -> str:
752
753
out_str += "\\ left[ \\ begin{array}{" + n * "c" + "}"
753
754
for i in range (n ):
754
755
for j in range (n ):
755
- if ( i > j ) :
756
+ if i > j :
756
757
out_str += " * & "
757
758
else :
758
759
out_str += str (self [i , j ]) + " & "
@@ -780,11 +781,9 @@ def __getitem__(self, ij):
780
781
781
782
# Ensure we're using upper-triangular coordinates
782
783
if i > j :
783
- tmp = i
784
- i = j
785
- j = tmp
784
+ i , j = j , i
786
785
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 ]
788
787
789
788
def __setitem__ (self , ij , coeff ):
790
789
r"""
@@ -814,13 +813,11 @@ def __setitem__(self, ij, coeff):
814
813
815
814
# Ensure we're using upper-triangular coordinates
816
815
if i > j :
817
- tmp = i
818
- i = j
819
- j = tmp
816
+ i , j = j , i
820
817
821
818
# Set the entry
822
819
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 )
824
821
except Exception :
825
822
raise RuntimeError ("this coefficient cannot be coerced to an element of the base ring for the quadratic form" )
826
823
@@ -884,7 +881,7 @@ def __add__(self, right):
884
881
"""
885
882
if not isinstance (right , QuadraticForm ):
886
883
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 ():
888
885
raise TypeError ("cannot add these since the quadratic forms do not have the same base rings" )
889
886
890
887
Q = QuadraticForm (self .base_ring (), self .dim () + right .dim ())
@@ -1106,7 +1103,7 @@ def _is_even_symmetric_matrix_(self, A, R=None):
1106
1103
1107
1104
# Test that all entries coerce to R
1108
1105
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 ):
1110
1107
try :
1111
1108
for i in range (n ):
1112
1109
for j in range (i , n ):
@@ -1186,7 +1183,7 @@ def Gram_matrix_rational(self):
1186
1183
sage: A.base_ring()
1187
1184
Rational Field
1188
1185
"""
1189
- return (ZZ ( 1 ) / ZZ (2 )) * self .matrix ()
1186
+ return (ZZ . one ( ) / ZZ (2 )) * self .matrix ()
1190
1187
1191
1188
def Gram_matrix (self ):
1192
1189
r"""
@@ -1558,13 +1555,13 @@ def change_ring(self, R):
1558
1555
# Return the coerced form
1559
1556
return QuadraticForm (R , self .dim (), [R (x ) for x in self .coefficients ()])
1560
1557
1561
- base_change_to = deprecated_function_alias (35248 , change_ring )
1562
-
1563
1558
def level (self ):
1564
1559
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`.
1568
1565
1569
1566
Over `\ZZ` this returns a nonnegative number.
1570
1567
@@ -1610,7 +1607,7 @@ def level(self):
1610
1607
inv_denoms = []
1611
1608
for i in range (self .dim ()):
1612
1609
for j in range (i , self .dim ()):
1613
- if ( i == j ) :
1610
+ if i == j :
1614
1611
inv_denoms += [denominator (mat_inv [i , j ] / 2 )]
1615
1612
else :
1616
1613
inv_denoms += [denominator (mat_inv [i , j ])]
@@ -1623,7 +1620,7 @@ def level(self):
1623
1620
##############################################################
1624
1621
1625
1622
# Normalize the result over ZZ
1626
- if self .base_ring () == IntegerRing () :
1623
+ if self .base_ring () == ZZ :
1627
1624
lvl = abs (lvl )
1628
1625
1629
1626
# Cache and return the level
@@ -1632,10 +1629,13 @@ def level(self):
1632
1629
1633
1630
def level_ideal (self ):
1634
1631
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!)
1639
1639
1640
1640
.. WARNING::
1641
1641
@@ -1724,7 +1724,7 @@ def bilinear_map(self, v, w):
1724
1724
return (self (v + w ) - self (v ) - self (w )) / 2
1725
1725
1726
1726
1727
- def DiagonalQuadraticForm (R , diag ):
1727
+ def DiagonalQuadraticForm (R , diag ) -> QuadraticForm :
1728
1728
"""
1729
1729
Return a quadratic form over `R` which is a sum of squares.
1730
1730
0 commit comments