@@ -137,8 +137,7 @@ def __init__(self, a, b=None, c=None):
137
137
"""
138
138
from sage .rings .polynomial .multi_polynomial import MPolynomial
139
139
if b is None and c is None :
140
- if (isinstance (a , (list , tuple ))
141
- and len (a ) == 3 ):
140
+ if isinstance (a , (list , tuple )) and len (a ) == 3 :
142
141
a , b , c = a
143
142
elif a == 0 :
144
143
a = b = c = 0
@@ -215,8 +214,8 @@ def __mul__(self, right):
215
214
return BinaryQF (self .__pari__ ().qfbcompraw (right ))
216
215
# ...or a 2x2 matrix...
217
216
if (isinstance (right .parent (), MatrixSpace )
218
- and right .nrows () == right .ncols () == 2 ):
219
- aa ,bb ,cc ,dd = right .list ()
217
+ and right .nrows () == right .ncols () == 2 ):
218
+ aa , bb , cc , dd = right .list ()
220
219
A = self .polynomial ()(aa , cc )
221
220
C = self .polynomial ()(bb , dd )
222
221
B = self .polynomial ()(aa + bb , cc + dd ) - A - C
@@ -536,10 +535,10 @@ def from_polynomial(poly):
536
535
if not isinstance (R , MPolynomialRing_base ) or R .ngens () != 2 :
537
536
raise TypeError (f'not a bivariate polynomial ring: { R } ' )
538
537
if not all (mon .degree () == 2 for mon in poly .monomials ()):
539
- raise ValueError (f 'polynomial has monomials of degree != 2' )
540
- x ,y = R .gens ()
538
+ raise ValueError ('polynomial has monomials of degree != 2' )
539
+ x , y = R .gens ()
541
540
coeffs = (poly .monomial_coefficient (mon ) for mon in (x ** 2 , x * y , y ** 2 ))
542
- a ,b , c = map (ZZ , coeffs )
541
+ a , b , c = map (ZZ , coeffs )
543
542
return BinaryQF (a , b , c )
544
543
545
544
@cached_method
@@ -924,7 +923,7 @@ def reduced_form(self, transformation=False, algorithm="default"):
924
923
'supported using PARI' )
925
924
926
925
if transformation :
927
- y ,g = self .__pari__ ().qfbredsl2 ()
926
+ y , g = self .__pari__ ().qfbredsl2 ()
928
927
return BinaryQF (y ), Matrix (ZZ , g )
929
928
return BinaryQF (self .__pari__ ().qfbred ())
930
929
@@ -1153,7 +1152,7 @@ def cycle(self, proper=False):
1153
1152
'implemented for non-square discriminants' )
1154
1153
if proper :
1155
1154
# Prop 6.10.5 in Buchmann Vollmer
1156
- C = list (self .cycle (proper = False )) # make a copy so we can modify it
1155
+ C = list (self .cycle (proper = False )) # make a copy that we can modify
1157
1156
if len (C ) % 2 :
1158
1157
C += C
1159
1158
for i in range (len (C )// 2 ):
@@ -1316,7 +1315,7 @@ def is_equivalent(self, other, proper=True):
1316
1315
sage: Q1.is_equivalent(Q2, proper=True) # optional - sage.libs.pari
1317
1316
True
1318
1317
"""
1319
- if type (other ) != type ( self ):
1318
+ if not isinstance (other , BinaryQF ):
1320
1319
raise TypeError ("%s is not a BinaryQF" % other )
1321
1320
if self .discriminant () != other .discriminant ():
1322
1321
return False
@@ -1342,7 +1341,7 @@ def is_equivalent(self, other, proper=True):
1342
1341
return is_properly_equiv
1343
1342
else :
1344
1343
g = gcd (a , b )
1345
- return is_properly_equiv or ((gcd (ao ,b ) == g ) and ((a * ao - g ** 2 ) % (b * g ) == 0 ))
1344
+ return is_properly_equiv or ((gcd (ao , b ) == g ) and ((a * ao - g ** 2 ) % (b * g ) == 0 ))
1346
1345
1347
1346
proper_cycle = otherred .cycle (proper = True )
1348
1347
@@ -1654,13 +1653,13 @@ def solve_integer(self, n, *, algorithm="general"):
1654
1653
# https://math.stackexchange.com/a/980075
1655
1654
w = self .discriminant ().sqrt ()
1656
1655
r = (- self ._b + (w if w != self ._b else - w )) / (2 * self ._a )
1657
- p ,q = r .as_integer_ratio ()
1658
- g ,u , v = p .xgcd (q )
1659
- M = Matrix (ZZ , [[v ,p ],[- u ,q ]])
1656
+ p , q = r .as_integer_ratio ()
1657
+ g , u , v = p .xgcd (q )
1658
+ M = Matrix (ZZ , [[v , p ], [- u , q ]])
1660
1659
elif self ._c :
1661
- M = Matrix (ZZ , [[0 ,1 ],[1 ,0 ]])
1660
+ M = Matrix (ZZ , [[0 , 1 ], [1 , 0 ]])
1662
1661
else :
1663
- M = Matrix (ZZ , [[1 ,0 ],[0 ,1 ]])
1662
+ M = Matrix (ZZ , [[1 , 0 ], [0 , 1 ]])
1664
1663
assert M .is_unit ()
1665
1664
Q = self .matrix_action_right (M )
1666
1665
assert not Q ._c
@@ -1845,7 +1844,7 @@ def BinaryQF_reduced_representatives(D, primitive_only=False, proper=True):
1845
1844
c = ZZ (0 )
1846
1845
# -b/2 < a <= b/2
1847
1846
for a in xsrange ((- b / 2 ).floor () + 1 , (b / 2 ).floor () + 1 ):
1848
- if ( not primitive_only ) or (gcd ([a ,b , c ]) == 1 ):
1847
+ if not primitive_only or (gcd ([a , b , c ]) == 1 ):
1849
1848
form_list .append (BinaryQF (a , b , c ))
1850
1849
# We follow the description of Buchmann/Vollmer 6.7.1. They
1851
1850
# enumerate all reduced forms. We only want representatives.
@@ -1879,14 +1878,14 @@ def BinaryQF_reduced_representatives(D, primitive_only=False, proper=True):
1879
1878
a4 = 4 * a
1880
1879
s = D + a * a4
1881
1880
w = 1 + (s - 1 ).isqrt () if s > 0 else 0
1882
- if w % 2 != D % 2 :
1881
+ if w % 2 != D % 2 :
1883
1882
w += 1
1884
1883
for b in xsrange (w , a + 1 , 2 ):
1885
1884
t = b * b - D
1886
1885
if t % a4 == 0 :
1887
1886
c = t // a4
1888
- if ( not primitive_only ) or gcd ([a , b , c ]) == 1 :
1889
- if b > 0 and a > b and c > a :
1887
+ if not primitive_only or gcd ([a , b , c ]) == 1 :
1888
+ if c > a > b > 0 :
1890
1889
form_list .append (BinaryQF ([a , - b , c ]))
1891
1890
form_list .append (BinaryQF ([a , b , c ]))
1892
1891
if not proper or D > 0 :
0 commit comments