Skip to content

Commit eca1c9e

Browse files
author
Release Manager
committed
gh-35677: Some pep8 in elliptic curves <!-- Please provide a concise, informative and self-explanatory title. --> <!-- Don't put issue numbers in the title. Put it in the Description below. --> <!-- For example, instead of "Fixes #12345", use "Add a new method to multiply two integers" --> ### 📚 Description Fixing a few pep8 warnings (E222, E203, etc) in `schemes/ellipticcurves` <!-- Describe your changes here in detail. --> <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. It should be `[x]` not `[x ]`. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #35677 Reported by: Frédéric Chapoton Reviewer(s): Travis Scrimshaw
2 parents e950129 + cab8cb1 commit eca1c9e

28 files changed

+471
-467
lines changed

src/sage/schemes/elliptic_curves/cm.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def hilbert_class_polynomial(D, algorithm=None):
157157
h = len(rqf) # class number
158158
c1 = 3.05682737291380 # log(2*10.63)
159159
c2 = sum([1/RR(qf[0]) for qf in rqf], RR(0))
160-
prec = c2*RR(3.142)*RR(D).abs().sqrt() + h*c1 # bound on log
160+
prec = c2 * RR(3.142) * RR(D).abs().sqrt() + h * c1 # bound on log
161161
prec = prec * 1.45 # bound on log_2 (1/log(2) = 1.44..)
162162
prec = 10 + prec.ceil() # allow for rounding error
163163

@@ -242,7 +242,8 @@ def is_HCP(f, check_monic_irreducible=True):
242242
from sage.rings.finite_rings.finite_field_constructor import GF
243243

244244
h = f.degree()
245-
h2list = [d for d in h.divisors() if (d-h)%2 == 0 and d.prime_to_m_part(2) == 1]
245+
h2list = [d for d in h.divisors()
246+
if (d-h) % 2 == 0 and d.prime_to_m_part(2) == 1]
246247
pmin = 33 * (h**2 * (RR(h+2).log().log()+2)**2).ceil()
247248
# Guarantees 4*p > |D| for fundamental D under GRH
248249
p = pmin-1
@@ -262,7 +263,7 @@ def is_HCP(f, check_monic_irreducible=True):
262263
continue
263264
if not fp.is_squarefree():
264265
continue
265-
if d<h and d not in h2list:
266+
if d < h and d not in h2list:
266267
return zero
267268
jp = fp.any_root(degree=-1, assume_squarefree=True)
268269
E = EllipticCurve(j=jp)
@@ -317,14 +318,15 @@ def OrderClassNumber(D0,h0,f):
317318
ps = f.prime_divisors()
318319
from sage.misc.misc_c import prod
319320
from sage.arith.misc import kronecker as kronecker_symbol
320-
n = (f // prod(ps)) * prod(p-kronecker_symbol(D0,p) for p in ps)
321+
n = (f // prod(ps)) * prod(p - kronecker_symbol(D0, p) for p in ps)
321322
if D0 == -3:
322-
#assert h0 == 1 and n%3==0
323-
return n//3
323+
# assert h0 == 1 and n % 3 == 0
324+
return n // 3
324325
if D0 == -4:
325-
#assert h0 == 1 and n%2==0
326-
return n//2
327-
return n*h0
326+
# assert h0 == 1 and n % 2 == 0
327+
return n // 2
328+
return n * h0
329+
328330

329331
@cached_function
330332
def cm_j_invariants(K, proof=None):
@@ -768,10 +770,10 @@ def discriminants_with_bounded_class_number(hmax, B=None, proof=None):
768770

769771
# Easy case where we have already computed and cached the relevant values
770772
if hDf_dict and hmax <= max(hDf_dict):
771-
T = {h:Dflist for h,Dflist in hDf_dict.items() if h<=hmax}
773+
T = {h:Dflist for h,Dflist in hDf_dict.items() if h <= hmax}
772774
if B:
773775
for h in T:
774-
T[h] = [Df for Df in T[h] if Df[0].abs()*Df[1]**2<=B]
776+
T[h] = [Df for Df in T[h] if Df[0].abs()*Df[1]**2 <= B]
775777
return T
776778

777779
# imports that are needed only for this function
@@ -822,7 +824,7 @@ def discriminants_with_bounded_class_number(hmax, B=None, proof=None):
822824
for D0,f in Dflist:
823825
h_dict[D0*f**2] = h
824826
if not count:
825-
Dflist = [Df for Df in Dflist if Df[0].abs()*Df[1]**2<=B]
827+
Dflist = [Df for Df in Dflist if Df[0].abs()*Df[1]**2 <= B]
826828
T[h] = set(Dflist)
827829

828830
# We do not need to certify the class number from :pari:`qfbclassno` for discriminants under 2*10^10
@@ -833,7 +835,7 @@ def discriminants_with_bounded_class_number(hmax, B=None, proof=None):
833835
if not D.is_discriminant():
834836
continue
835837
D0 = D.squarefree_part()
836-
if D0%4 !=1:
838+
if D0 % 4 != 1:
837839
D0 *= 4
838840
f = (D//D0).isqrt()
839841

@@ -986,16 +988,16 @@ def is_cm_j_invariant(j, algorithm='CremonaSutherland', method=None):
986988
D = is_HCP(jpol, check_monic_irreducible=False)
987989
if D:
988990
D0 = D.squarefree_part()
989-
if D0%4 !=1:
991+
if D0 % 4 != 1:
990992
D0 *= 4
991-
f = ZZ(D//D0).isqrt()
992-
return (True, (D0,f))
993+
f = ZZ(D // D0).isqrt()
994+
return (True, (D0, f))
993995
else:
994996
return (False, None)
995997

996998
h = jpol.degree()
997999
if algorithm in ['exhaustive', 'old']:
998-
if h>100:
1000+
if h > 100:
9991001
raise NotImplementedError("CM data only available for class numbers up to 100")
10001002
for d,f in cm_orders(h):
10011003
if jpol == hilbert_class_polynomial(d*f**2):
@@ -1023,8 +1025,8 @@ def is_cm_j_invariant(j, algorithm='CremonaSutherland', method=None):
10231025
from sage.schemes.elliptic_curves.constructor import EllipticCurve
10241026
E = EllipticCurve(j=j).integral_model()
10251027
D = E.discriminant()
1026-
prime_bound = 1000 # test primes of degree 1 up to this norm
1027-
max_primes = 20 # test at most this many primes
1028+
prime_bound = 1000 # test primes of degree 1 up to this norm
1029+
max_primes = 20 # test at most this many primes
10281030
num_prime = 0
10291031
cmd = 0
10301032
cmf = 0
@@ -1048,8 +1050,8 @@ def is_cm_j_invariant(j, algorithm='CremonaSutherland', method=None):
10481050
if cmd: # we have a candidate CM field already
10491051
break
10501052
else: # we need to try more primes
1051-
max_primes *=2
1052-
if D.valuation(P)>0: # skip bad primes
1053+
max_primes *= 2
1054+
if D.valuation(P) > 0: # skip bad primes
10531055
continue
10541056
aP = E.reduction(P).trace_of_frobenius()
10551057
if aP == 0: # skip supersingular primes

src/sage/schemes/elliptic_curves/constructor.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -696,14 +696,14 @@ def coefficients_from_j(j, minimal_twist=True):
696696
if K not in _Fields:
697697
K = K.fraction_field()
698698

699-
char=K.characteristic()
700-
if char==2:
699+
char = K.characteristic()
700+
if char == 2:
701701
if j == 0:
702702
return Sequence([0, 0, 1, 0, 0], universe=K)
703703
else:
704704
return Sequence([1, 0, 0, 0, 1/j], universe=K)
705705
if char == 3:
706-
if j==0:
706+
if j == 0:
707707
return Sequence([0, 0, 0, 1, 0], universe=K)
708708
else:
709709
return Sequence([0, j, 0, 0, -j**2], universe=K)
@@ -717,7 +717,7 @@ def coefficients_from_j(j, minimal_twist=True):
717717
return Sequence([0, 0, 0, -1, 0], universe=K) # 32a2
718718

719719
if not minimal_twist:
720-
k=j-1728
720+
k = j-1728
721721
return Sequence([0, 0, 0, -3*j*k, -2*j*k**2], universe=K)
722722

723723
n = j.numerator()
@@ -729,7 +729,7 @@ def coefficients_from_j(j, minimal_twist=True):
729729
from sage.sets.set import Set
730730
for p in Set(n.prime_divisors()+m.prime_divisors()):
731731
e = min(a4.valuation(p)//2,a6.valuation(p)//3)
732-
if e>0:
732+
if e > 0:
733733
p = p**e
734734
a4 /= p**2
735735
a6 /= p**3
@@ -754,7 +754,7 @@ def coefficients_from_j(j, minimal_twist=True):
754754
return Sequence([0, 0, 0, 0, 1], universe=K)
755755
if j == 1728:
756756
return Sequence([0, 0, 0, 1, 0], universe=K)
757-
k=j-1728
757+
k = j-1728
758758
return Sequence([0, 0, 0, -3*j*k, -2*j*k**2], universe=K)
759759

760760

@@ -1112,7 +1112,7 @@ def EllipticCurve_from_cubic(F, P=None, morphism=True):
11121112
# Test whether P is a flex; if not test whether there are any rational flexes:
11131113

11141114
hessian = Matrix([[F.derivative(v1, v2) for v1 in R.gens()] for v2 in R.gens()]).det()
1115-
if P and hessian(P)==0:
1115+
if P and hessian(P) == 0:
11161116
flex_point = P
11171117
else:
11181118
flexes = C.intersection(Curve(hessian)).rational_points()
@@ -1174,11 +1174,11 @@ def EllipticCurve_from_cubic(F, P=None, morphism=True):
11741174
if not P:
11751175
raise ValueError('A point must be given when the cubic has no rational flexes')
11761176
L = tangent_at_smooth_point(C,P)
1177-
Qlist = [Q for Q in C.intersection(Curve(L)).rational_points() if C(Q)!=CP]
1177+
Qlist = [Q for Q in C.intersection(Curve(L)).rational_points() if C(Q) != CP]
11781178
# assert Qlist
11791179
P2 = C(Qlist[0])
11801180
L2 = tangent_at_smooth_point(C,P2)
1181-
Qlist = [Q for Q in C.intersection(Curve(L2)).rational_points() if C(Q)!=P2]
1181+
Qlist = [Q for Q in C.intersection(Curve(L2)).rational_points() if C(Q) != P2]
11821182
# assert Qlist
11831183
P3 = C(Qlist[0])
11841184

@@ -1345,7 +1345,7 @@ def chord_and_tangent(F, P):
13451345
raise TypeError('{} does not define a point on a projective curve over {} defined by {}'.format(P,K,F))
13461346

13471347
L = Curve(tangent_at_smooth_point(C,P))
1348-
Qlist = [Q for Q in C.intersection(L).rational_points() if Q!=P]
1348+
Qlist = [Q for Q in C.intersection(L).rational_points() if Q != P]
13491349
if Qlist:
13501350
return Qlist[0]
13511351
return P

src/sage/schemes/elliptic_curves/ec_database.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def rank(self, rank, tors=0, n=10, labels=False):
133133
[]
134134
"""
135135
from sage.env import ELLCURVE_DATA_DIR
136-
data = os.path.join(ELLCURVE_DATA_DIR, 'rank%s'%rank)
136+
data = os.path.join(ELLCURVE_DATA_DIR, 'rank%s' % rank)
137137
try:
138138
f = open(data)
139139
except IOError:
@@ -151,7 +151,7 @@ def rank(self, rank, tors=0, n=10, labels=False):
151151
# NOTE: only change this bound below after checking/fixing
152152
# the Cremona labels in the elliptic_curves package!
153153
if N <= 400000:
154-
label = '%s%s%s'%(N, iso, num)
154+
label = '%s%s%s' % (N, iso, num)
155155
else:
156156
label = None
157157

src/sage/schemes/elliptic_curves/ell_curve_isogeny.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -483,13 +483,13 @@ def compute_codomain_kohel(E, kernel):
483483

484484
v, w = compute_vw_kohel_even_deg1(x0, y0, a1, a2, a4)
485485

486-
elif n == 3: # psi_2tor is the full 2-division polynomial
486+
elif n == 3: # psi_2tor is the full 2-division polynomial
487487

488488
b2, b4, _, _ = E.b_invariants()
489489

490-
s1 = -psi_2tor[n-1]
491-
s2 = psi_2tor[n-2]
492-
s3 = -psi_2tor[n-3]
490+
s1 = -psi_2tor[n - 1]
491+
s2 = psi_2tor[n - 2]
492+
s3 = -psi_2tor[n - 3]
493493

494494
v, w = compute_vw_kohel_even_deg3(b2, b4, s1, s2, s3)
495495

@@ -499,9 +499,9 @@ def compute_codomain_kohel(E, kernel):
499499

500500
b2, b4, b6, _ = E.b_invariants()
501501

502-
s1 = -psi[n-1] if n >= 1 else 0
503-
s2 = psi[n-2] if n >= 2 else 0
504-
s3 = -psi[n-3] if n >= 3 else 0
502+
s1 = -psi[n - 1] if n >= 1 else 0
503+
s2 = psi[n - 2] if n >= 2 else 0
504+
s3 = -psi[n - 3] if n >= 3 else 0
505505

506506
# initializing these allows us to calculate E2.
507507
v, w = compute_vw_kohel_odd(b2, b4, b6, s1, s2, s3, n)
@@ -1895,7 +1895,7 @@ def __init_from_kernel_list(self, kernel_gens):
18951895
to Elliptic Curve defined by y^2 = x^3 + 80816485163488178037199320944019099858815874115367810482828676054000067654558381377552245721755005198633191074893*x + 301497584865165444049833326660609767433467459033532853758006118022998267706948164646650354324860226263546558337993
18961896
over Finite Field of size 461742260113997803268895001173557974278278194575766957660028841364655249961609425998827452443620996655395008156411
18971897
"""
1898-
if self.__check :
1898+
if self.__check:
18991899
for P in kernel_gens:
19001900
if not P.has_finite_order():
19011901
raise ValueError("given kernel contains point of infinite order")
@@ -2339,7 +2339,7 @@ def __init_even_kernel_polynomial(self, E, psi_G):
23392339
(x^7 + 5*x^6 + 2*x^5 + 6*x^4 + 3*x^3 + 5*x^2 + 6*x + 3, (x^9 + 4*x^8 + 2*x^7 + 4*x^3 + 2*x^2 + x + 6)*y, 1, 6, 3, 4)
23402340
"""
23412341
# check if the polynomial really divides the two_torsion_polynomial
2342-
if self.__check and E.division_polynomial(2, x=self.__poly_ring.gen()) % psi_G != 0 :
2342+
if self.__check and E.division_polynomial(2, x=self.__poly_ring.gen()) % psi_G != 0:
23432343
raise ValueError(f"the polynomial {psi_G} does not define a finite subgroup of {E}")
23442344

23452345
n = psi_G.degree() # 1 or 3
@@ -2365,9 +2365,9 @@ def __init_even_kernel_polynomial(self, E, psi_G):
23652365
omega = (y*psi_G**2 - v*(a1*psi_G + (y - y0)))*psi_G
23662366

23672367
elif n == 3:
2368-
s1 = -psi_G[n-1]
2369-
s2 = psi_G[n-2]
2370-
s3 = -psi_G[n-3]
2368+
s1 = -psi_G[n - 1]
2369+
s2 = psi_G[n - 2]
2370+
s3 = -psi_G[n - 3]
23712371

23722372
psi_G_pr = psi_G.derivative()
23732373
psi_G_prpr = psi_G_pr.derivative()

0 commit comments

Comments
 (0)