Skip to content

Commit 2272afd

Browse files
author
Release Manager
committed
gh-36157: some pep for E30 and more in quadratic forms pep8 cleanup for E302 and others in quadratic_forms ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. URL: #36157 Reported by: Frédéric Chapoton Reviewer(s): Kwankyu Lee
2 parents 09dd403 + 46114f9 commit 2272afd

File tree

5 files changed

+68
-57
lines changed

5 files changed

+68
-57
lines changed

src/sage/quadratic_forms/genera/genus.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ def _local_genera(p, rank, det_val, max_scale, even):
174174
"""
175175
from sage.misc.mrange import cantor_product
176176
from sage.combinat.integer_lists.invlex import IntegerListsLex
177-
scales_rks = [] # contains possibilities for scales and ranks
178-
for rkseq in IntegerListsLex(rank, length=max_scale+1): # rank sequences
177+
scales_rks = [] # contains possibilities for scales and ranks
178+
for rkseq in IntegerListsLex(rank, length=max_scale + 1): # rank sequences
179179
# sum(rkseq) = rank
180180
# len(rkseq) = max_scale + 1
181181
# now assure that we get the right determinant
@@ -278,7 +278,7 @@ def _blocks(b, even_only=False):
278278
# odd case
279279
if not even_only:
280280
# format (det, oddity)
281-
for s in [(1,2), (5,6), (1,6), (5,2), (7,0), (3,4)]:
281+
for s in [(1, 2), (5, 6), (1, 6), (5, 2), (7, 0), (3, 4)]:
282282
b1 = copy(b)
283283
b1[2] = s[0]
284284
b1[3] = 1
@@ -289,20 +289,20 @@ def _blocks(b, even_only=False):
289289
b1 = copy(b)
290290
b1[3] = 0
291291
b1[4] = 0
292-
d = (-1)**(rk//2) % 8
292+
d = (-1)**(rk // 2) % 8
293293
for det in [d, d * (-3) % 8]:
294294
b1 = copy(b1)
295295
b1[2] = det
296296
blocks.append(b1)
297297
# odd case
298298
if not even_only:
299-
for s in [(1,2), (5,6), (1,6), (5,2), (7,0), (3,4)]:
299+
for s in [(1, 2), (5, 6), (1, 6), (5, 2), (7, 0), (3, 4)]:
300300
b1 = copy(b)
301301
b1[2] = s[0]*(-1)**(rk//2 -1) % 8
302302
b1[3] = 1
303303
b1[4] = s[1]
304304
blocks.append(b1)
305-
for s in [(1,4), (5,0)]:
305+
for s in [(1, 4), (5, 0)]:
306306
b1 = copy(b)
307307
b1[2] = s[0]*(-1)**(rk//2 - 2) % 8
308308
b1[3] = 1
@@ -445,12 +445,14 @@ def is_GlobalGenus(G):
445445
verbose(mesg="False in is_2_adic_genus(sym)", level=2)
446446
return False
447447
if (a*b).kronecker(p) != 1:
448-
verbose(mesg="False in (%s*%s).kronecker(%s)"%(a,b,p), level=2)
448+
verbose(mesg="False in (%s*%s).kronecker(%s)" % (a, b, p),
449+
level=2)
449450
return False
450451
oddity -= loc.excess()
451452
else:
452453
if a.kronecker(p) != b:
453-
verbose(mesg="False in %s.kronecker(%s) != *%s"%(a,p,b), level=2)
454+
verbose(mesg="False in %s.kronecker(%s) != *%s" % (a, p, b),
455+
level=2)
454456
return False
455457
oddity += loc.excess()
456458
if oddity % 8 != 0:
@@ -586,6 +588,7 @@ def canonical_2_adic_compartments(genus_symbol_quintuple_list):
586588
i += 1
587589
return compartments
588590

591+
589592
def canonical_2_adic_trains(genus_symbol_quintuple_list, compartments=None):
590593
r"""
591594
Given a `2`-adic local symbol (as the underlying list of quintuples)
@@ -658,7 +661,7 @@ def canonical_2_adic_trains(genus_symbol_quintuple_list, compartments=None):
658661
# avoid a special case for the end of symbol
659662
# if a jordan component has rank zero it is considered even.
660663
symbol = genus_symbol_quintuple_list
661-
symbol.append([symbol[-1][0]+1, 0, 1, 0, 0]) #We have just modified the input globally!
664+
symbol.append([symbol[-1][0]+1, 0, 1, 0, 0]) # We have just modified the input globally!
662665
# Hence, we have to remove the last entry of symbol at the end.
663666
try:
664667

@@ -684,9 +687,10 @@ def canonical_2_adic_trains(genus_symbol_quintuple_list, compartments=None):
684687
trains.append(new_train)
685688
return trains
686689
finally:
687-
#revert the input list to its original state
690+
# revert the input list to its original state
688691
symbol.pop()
689692

693+
690694
def canonical_2_adic_reduction(genus_symbol_quintuple_list):
691695
r"""
692696
Given a `2`-adic local symbol (as the underlying list of quintuples)
@@ -749,14 +753,14 @@ def canonical_2_adic_reduction(genus_symbol_quintuple_list):
749753
# Canonical determinants:
750754
for i in range(len(genus_symbol_quintuple_list)):
751755
d = genus_symbol_quintuple_list[i][2]
752-
if d in (1,7):
756+
if d in (1, 7):
753757
canonical_symbol[i][2] = 1
754758
else:
755759
canonical_symbol[i][2] = -1
756760
# Oddity fusion:
757761
compartments = canonical_2_adic_compartments(genus_symbol_quintuple_list)
758762
for compart in compartments:
759-
oddity = sum([ genus_symbol_quintuple_list[i][4] for i in compart ]) % 8
763+
oddity = sum([genus_symbol_quintuple_list[i][4] for i in compart]) % 8
760764
for i in compart:
761765
genus_symbol_quintuple_list[i][4] = 0
762766
genus_symbol_quintuple_list[compart[0]][4] = oddity
@@ -3425,16 +3429,17 @@ def _gram_from_jordan_block(p, block, discr_form=False):
34253429
d = 2**(rk % 2)
34263430
if Integer(d).kronecker(p) != det:
34273431
u = ZZ(_min_nonsquare(p))
3428-
q[0,0] = u
3432+
q[0, 0] = u
34293433
q = q * (2 / p**level)
34303434
if p != 2 and not discr_form:
34313435
q = matrix.identity(QQ, rk)
34323436
if det != 1:
34333437
u = ZZ(_min_nonsquare(p))
3434-
q[0,0] = u
3438+
q[0, 0] = u
34353439
q = q * p**level
34363440
return q
34373441

3442+
34383443
# Helper functions for mass computations
34393444

34403445
def M_p(species, p):

src/sage/quadratic_forms/qfsolve.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616
- Tyler Gaona (2015-11-14): added the `solve` method
1717
"""
1818

19-
#*****************************************************************************
19+
# ****************************************************************************
2020
# Copyright (C) 2008 Nick Alexander
2121
# Copyright (C) 2014 Jeroen Demeyer
2222
#
2323
# This program is free software: you can redistribute it and/or modify
2424
# it under the terms of the GNU General Public License as published by
2525
# the Free Software Foundation, either version 2 of the License, or
2626
# (at your option) any later version.
27-
# http://www.gnu.org/licenses/
28-
#*****************************************************************************
27+
# https://www.gnu.org/licenses/
28+
# ****************************************************************************
2929

3030
from sage.rings.integer_ring import ZZ
3131
from sage.rings.rational_field import QQ
@@ -80,6 +80,7 @@ def qfsolve(G):
8080
return vector(QQ, ret)
8181
return ZZ(ret)
8282

83+
8384
def qfparam(G, sol):
8485
r"""
8586
Parametrize the conic defined by the matrix `G`.
@@ -220,8 +221,8 @@ def solve(self, c=0):
220221
N = Matrix(self.base_ring(), d+1, d+1)
221222
for i in range(d):
222223
for j in range(d):
223-
N[i,j] = M[i,j]
224-
N[d,d] = -c
224+
N[i, j] = M[i, j]
225+
N[d, d] = -c
225226

226227
# Find a solution x to Q(x) = 0, using qfsolve()
227228
x = qfsolve(N)

src/sage/quadratic_forms/quadratic_form__neighbors.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def find_primitive_p_divisible_vector__next(self, p, v=None):
131131
if a in ZZ and (a % p == 0):
132132
return w
133133

134+
134135
def find_p_neighbor_from_vec(self, p, y):
135136
r"""
136137
Return the `p`-neighbor of ``self`` defined by ``y``.
@@ -173,7 +174,7 @@ def find_p_neighbor_from_vec(self, p, y):
173174
"""
174175
p = ZZ(p)
175176
if not p.divides(self(y)):
176-
raise ValueError("y=%s must be of square divisible by p=%s"%(y,p))
177+
raise ValueError("y=%s must be of square divisible by p=%s" % (y, p))
177178
if self.base_ring() not in [ZZ, QQ]:
178179
raise NotImplementedError("the base ring of this form must be the integers or the rationals")
179180

@@ -197,14 +198,14 @@ def find_p_neighbor_from_vec(self, p, y):
197198
z = (ZZ**n).gen(k)
198199
break
199200
else:
200-
raise ValueError("either y is not primitive or self is not maximal at %s"%p)
201+
raise ValueError("either y is not primitive or self is not maximal at %s" % p)
201202
z *= (2*y*G*z).inverse_mod(p)
202203
y = y - b*z
203204
# assert y*G*y % p^2 == 0
204205
if p == 2:
205206
val = b.valuation(p)
206207
if val <= 1:
207-
raise ValueError("y=%s must be of square divisible by 2"%y)
208+
raise ValueError("y=%s must be of square divisible by 2" % y)
208209
if val == 2 and not odd:
209210
# modify it to have square 4
210211
for k in range(n):
@@ -348,14 +349,15 @@ def p_divisible_vectors(Q, max_neighbors):
348349
break
349350

350351
if len(isom_classes) >= max_classes:
351-
warn("reached the maximum number of isometry classes=%s. Increase the optional argument max_classes to obtain more." %max_classes)
352+
warn("reached the maximum number of isometry classes=%s. Increase the optional argument max_classes to obtain more." % max_classes)
352353

353354
if mass is not None:
354355
assert mass_count <= mass
355356
if mass_count < mass:
356357
print("Warning: not all classes in the genus were found")
357358
return isom_classes
358359

360+
359361
def orbits_lines_mod_p(self, p):
360362
r"""
361363
Let `(L, q)` be a lattice. This returns representatives of the

src/sage/quadratic_forms/quadratic_form__siegel_product.py

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
Siegel Products
44
"""
55

6-
#*****************************************************************************
6+
# ****************************************************************************
77
# This program is free software: you can redistribute it and/or modify
88
# it under the terms of the GNU General Public License as published by
99
# the Free Software Foundation, either version 2 of the License, or
1010
# (at your option) any later version.
11-
# http://www.gnu.org/licenses/
12-
#*****************************************************************************
11+
# https://www.gnu.org/licenses/
12+
# ****************************************************************************
1313

1414
from sage.arith.misc import (bernoulli,
1515
fundamental_discriminant,
@@ -21,16 +21,17 @@
2121
from sage.rings.integer_ring import ZZ
2222
from sage.rings.rational_field import QQ
2323

24-
#/*! \brief Computes the product of all local densities for comparison with independently computed Eisenstein coefficients.
24+
# /*! \brief Computes the product of all local densities for comparison with independently computed Eisenstein coefficients.
2525
# *
2626
# * \todo We fixed the generic factors to compensate for using the matrix of 2Q, but we need to document this better! =)
2727
# */
2828

29-
#/////////////////////////////////////////////////////////////////
30-
#///
31-
#/////////////////////////////////////////////////////////////////
29+
# /////////////////////////////////////////////////////////////////
30+
# ///
31+
# /////////////////////////////////////////////////////////////////
32+
33+
# mpq_class Matrix_mpz::siegel_product(mpz_class u) const {
3234

33-
#mpq_class Matrix_mpz::siegel_product(mpz_class u) const {
3435

3536
def siegel_product(self, u):
3637
"""
@@ -124,15 +125,15 @@ def siegel_product(self, u):
124125
f = abs(d1)
125126

126127
# DIAGNOSTIC
127-
#cout << " mpz_class(-1)^m = " << (mpz_class(-1)^m) << " and d = " << d << endl;
128-
#cout << " f = " << f << " and d1 = " << d1 << endl;
128+
# cout << " mpz_class(-1)^m = " << (mpz_class(-1)^m) << " and d = " << d << endl;
129+
# cout << " f = " << f << " and d1 = " << d1 << endl;
129130

130131
genericfactor = m / QQ(sqrt(f*d)) \
131132
* ((u/2) ** (m-1)) * (f ** m) \
132133
/ abs(QuadraticBernoulliNumber(m, d1)) \
133134
* (2 ** m) # This last factor compensates for using the matrix of 2*Q
134135

135-
##return genericfactor
136+
# return genericfactor
136137

137138
# Omit the generic factors in S and compute them separately
138139
omit = 1
@@ -141,9 +142,9 @@ def siegel_product(self, u):
141142
S_divisors = prime_divisors(S)
142143

143144
# DIAGNOSTIC
144-
#cout << "\n S is " << S << endl;
145-
#cout << " The Prime divisors of S are :";
146-
#PrintV(S_divisors);
145+
# cout << "\n S is " << S << endl;
146+
# cout << " The Prime divisors of S are :";
147+
# PrintV(S_divisors);
147148

148149
for p in S_divisors:
149150
Q_normal = self.local_normal_form(p)
@@ -158,36 +159,36 @@ def siegel_product(self, u):
158159
verbose(" Q_normal is \n" + str(Q_normal) + "\n")
159160
verbose(" Q_normal = \n" + str(Q_normal))
160161
verbose(" p = " + str(p) + "\n")
161-
verbose(" u = " +str(u) + "\n")
162+
verbose(" u = " + str(u) + "\n")
162163
verbose(" include = " + str(include) + "\n")
163164

164165
include *= Q_normal.local_density(p, u)
165166

166167
# DIAGNOSTIC
167-
#cout << " Including the p = " << p << " factor: " << local_density(Q_normal, p, u) << endl;
168+
# cout << " Including the p = " << p << " factor: " << local_density(Q_normal, p, u) << endl;
168169

169170
# DIAGNOSTIC
170171
verbose(" --- Exiting loop \n")
171172

172-
#// **************** Important *******************
173-
#// Additional fix (only included for n=4) to deal
174-
#// with the power of 2 introduced at the real place
175-
#// by working with Q instead of 2*Q. This needs to
176-
#// be done for all other n as well...
177-
#/*
178-
#if (n==4)
173+
# // **************** Important *******************
174+
# // Additional fix (only included for n=4) to deal
175+
# // with the power of 2 introduced at the real place
176+
# // by working with Q instead of 2*Q. This needs to
177+
# // be done for all other n as well...
178+
# /*
179+
# if (n==4)
179180
# genericfactor = 4 * genericfactor;
180-
#*/
181+
# */
181182

182183
# DIAGNOSTIC
183-
#cout << endl;
184-
#cout << " generic factor = " << genericfactor << endl;
185-
#cout << " omit = " << omit << endl;
186-
#cout << " include = " << include << endl;
187-
#cout << endl;
184+
# cout << endl;
185+
# cout << " generic factor = " << genericfactor << endl;
186+
# cout << " omit = " << omit << endl;
187+
# cout << " include = " << include << endl;
188+
# cout << endl;
188189

189190
# DIAGNOSTIC
190-
#// cout << "siegel_product Break 3. " << endl;
191+
# // cout << "siegel_product Break 3. " << endl;
191192

192193
# Return the final factor (and divide by 2 if n=2)
193194
if n == 2:

src/sage/quadratic_forms/special_values.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def gamma__exact(n):
9191

9292
raise TypeError("you must give an integer or half-integer argument")
9393

94+
9495
# ------------- The Riemann Zeta Function --------------
9596

9697
def zeta__exact(n):
@@ -159,6 +160,7 @@ def zeta__exact(n):
159160
elif n == 0:
160161
return QQ((-1, 2))
161162

163+
162164
# ---------- Dirichlet L-functions with quadratic characters ----------
163165

164166
def QuadraticBernoulliNumber(k, d):
@@ -232,7 +234,7 @@ def quadratic_L_function__exact(n, d):
232234
- [Was1997]_
233235
"""
234236
if n <= 0:
235-
return QuadraticBernoulliNumber(1-n,d)/(n-1)
237+
return QuadraticBernoulliNumber(1-n, d)/(n-1)
236238
elif n >= 1:
237239
# Compute the kind of critical values (p10)
238240
if kronecker_symbol(fundamental_discriminant(d), -1) == 1:
@@ -255,7 +257,7 @@ def quadratic_L_function__exact(n, d):
255257
ans *= (2*pi/f)**n
256258
ans *= GS # Evaluate the Gauss sum here! =0
257259
ans *= QQ.one()/(2 * I**delta)
258-
ans *= QuadraticBernoulliNumber(n,d)/factorial(n)
260+
ans *= QuadraticBernoulliNumber(n, d)/factorial(n)
259261
return ans
260262
else:
261263
if delta == 0:
@@ -314,6 +316,6 @@ def quadratic_L_function__numerical(n, d, num_terms=1000):
314316

315317
d1 = fundamental_discriminant(d)
316318
ans = R.zero()
317-
for i in range(1,num_terms):
318-
ans += R(kronecker_symbol(d1,i) / R(i)**n)
319+
for i in range(1, num_terms):
320+
ans += R(kronecker_symbol(d1, i) / R(i)**n)
319321
return ans

0 commit comments

Comments
 (0)