Skip to content

Commit cab8cb1

Browse files
committed
more pep8 fixes in elliptic curves
1 parent 45ed107 commit cab8cb1

23 files changed

+361
-360
lines changed

src/sage/schemes/elliptic_curves/cm.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def is_HCP(f, check_monic_irreducible=True):
263263
continue
264264
if not fp.is_squarefree():
265265
continue
266-
if d<h and d not in h2list:
266+
if d < h and d not in h2list:
267267
return zero
268268
jp = fp.any_root(degree=-1, assume_squarefree=True)
269269
E = EllipticCurve(j=jp)
@@ -318,14 +318,15 @@ def OrderClassNumber(D0,h0,f):
318318
ps = f.prime_divisors()
319319
from sage.misc.misc_c import prod
320320
from sage.arith.misc import kronecker as kronecker_symbol
321-
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)
322322
if D0 == -3:
323-
#assert h0 == 1 and n%3==0
324-
return n//3
323+
# assert h0 == 1 and n % 3 == 0
324+
return n // 3
325325
if D0 == -4:
326-
#assert h0 == 1 and n%2==0
327-
return n//2
328-
return n*h0
326+
# assert h0 == 1 and n % 2 == 0
327+
return n // 2
328+
return n * h0
329+
329330

330331
@cached_function
331332
def cm_j_invariants(K, proof=None):
@@ -767,10 +768,10 @@ def discriminants_with_bounded_class_number(hmax, B=None, proof=None):
767768

768769
# Easy case where we have already computed and cached the relevant values
769770
if hDf_dict and hmax <= max(hDf_dict):
770-
T = {h:Dflist for h,Dflist in hDf_dict.items() if h<=hmax}
771+
T = {h:Dflist for h,Dflist in hDf_dict.items() if h <= hmax}
771772
if B:
772773
for h in T:
773-
T[h] = [Df for Df in T[h] if Df[0].abs()*Df[1]**2<=B]
774+
T[h] = [Df for Df in T[h] if Df[0].abs()*Df[1]**2 <= B]
774775
return T
775776

776777
# imports that are needed only for this function
@@ -821,7 +822,7 @@ def discriminants_with_bounded_class_number(hmax, B=None, proof=None):
821822
for D0,f in Dflist:
822823
h_dict[D0*f**2] = h
823824
if not count:
824-
Dflist = [Df for Df in Dflist if Df[0].abs()*Df[1]**2<=B]
825+
Dflist = [Df for Df in Dflist if Df[0].abs()*Df[1]**2 <= B]
825826
T[h] = set(Dflist)
826827

827828
# We do not need to certify the class number from :pari:`qfbclassno` for discriminants under 2*10^10
@@ -993,7 +994,7 @@ def is_cm_j_invariant(j, algorithm='CremonaSutherland', method=None):
993994

994995
h = jpol.degree()
995996
if algorithm in ['exhaustive', 'old']:
996-
if h>100:
997+
if h > 100:
997998
raise NotImplementedError("CM data only available for class numbers up to 100")
998999
for d,f in cm_orders(h):
9991000
if jpol == hilbert_class_polynomial(d*f**2):
@@ -1046,8 +1047,8 @@ def is_cm_j_invariant(j, algorithm='CremonaSutherland', method=None):
10461047
if cmd: # we have a candidate CM field already
10471048
break
10481049
else: # we need to try more primes
1049-
max_primes *=2
1050-
if D.valuation(P)>0: # skip bad primes
1050+
max_primes *= 2
1051+
if D.valuation(P) > 0: # skip bad primes
10511052
continue
10521053
aP = E.reduction(P).trace_of_frobenius()
10531054
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_field.py

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def quadratic_twist(self, D=None):
155155
# degree is odd we can take D=1; otherwise it suffices to
156156
# consider odd powers of a generator.
157157
D = K(1)
158-
if K.degree() %2==0:
158+
if K.degree() % 2 == 0:
159159
D = K.gen()
160160
a = D**2
161161
while (x**2 + x + D).roots():
@@ -172,26 +172,26 @@ def quadratic_twist(self, D=None):
172172
raise ValueError("twisting parameter D must be specified over infinite fields.")
173173
else:
174174
try:
175-
D=K(D)
175+
D = K(D)
176176
except ValueError:
177177
raise ValueError("twisting parameter D must be in the base field.")
178178

179-
if char!=2 and D.is_zero():
179+
if char != 2 and D.is_zero():
180180
raise ValueError("twisting parameter D must be nonzero when characteristic is not 2")
181181

182-
if char!=2:
183-
b2,b4,b6,b8=self.b_invariants()
182+
if char != 2:
183+
b2,b4,b6,b8 = self.b_invariants()
184184
# E is isomorphic to [0,b2,0,8*b4,16*b6]
185185
return EllipticCurve(K,[0,b2*D,0,8*b4*D**2,16*b6*D**3])
186186

187187
# now char==2
188-
if self.j_invariant() !=0: # iff a1!=0
189-
a1,a2,a3,a4,a6=self.ainvs()
190-
E0=self.change_weierstrass_model(a1,a3/a1,0,(a1**2*a4+a3**2)/a1**3)
188+
if self.j_invariant() != 0: # iff a1!=0
189+
a1,a2,a3,a4,a6 = self.ainvs()
190+
E0 = self.change_weierstrass_model(a1,a3/a1,0,(a1**2*a4+a3**2)/a1**3)
191191
# which has the form = [1,A2,0,0,A6]
192-
assert E0.a1()==K(1)
193-
assert E0.a3()==K(0)
194-
assert E0.a4()==K(0)
192+
assert E0.a1() == K(1)
193+
assert E0.a3() == K(0)
194+
assert E0.a4() == K(0)
195195
return EllipticCurve(K,[1,E0.a2()+D,0,0,E0.a6()])
196196
else:
197197
raise ValueError("Quadratic twist not implemented in char 2 when j=0")
@@ -229,8 +229,8 @@ def two_torsion_rank(self):
229229
sage: EllipticCurve('15a1').two_torsion_rank()
230230
2
231231
"""
232-
f=self.division_polynomial(rings.Integer(2))
233-
n=len(f.roots())+1
232+
f = self.division_polynomial(rings.Integer(2))
233+
n = len(f.roots())+1
234234
return rings.Integer(n).ord(rings.Integer(2))
235235

236236
def quartic_twist(self, D):
@@ -258,22 +258,22 @@ def quartic_twist(self, D):
258258
sage: E.is_isomorphic(E1, GF(13^4,'a')) # optional - sage.rings.finite_rings
259259
True
260260
"""
261-
K=self.base_ring()
262-
char=K.characteristic()
263-
D=K(D)
261+
K = self.base_ring()
262+
char = K.characteristic()
263+
D = K(D)
264264

265-
if char==2 or char==3:
265+
if char == 2 or char == 3:
266266
raise ValueError("Quartic twist not defined in chars 2,3")
267267

268-
if self.j_invariant() !=K(1728):
268+
if self.j_invariant() != K(1728):
269269
raise ValueError("Quartic twist not defined when j!=1728")
270270

271271
if D.is_zero():
272272
raise ValueError("quartic twist requires a nonzero argument")
273273

274-
c4,c6=self.c_invariants()
274+
c4,c6 = self.c_invariants()
275275
# E is isomorphic to [0,0,0,-27*c4,0]
276-
assert c6==0
276+
assert c6 == 0
277277
return EllipticCurve(K,[0,0,0,-27*c4*D,0])
278278

279279
def sextic_twist(self, D):
@@ -303,22 +303,22 @@ def sextic_twist(self, D):
303303
sage: E.is_isomorphic(E1, GF(13^6,'a')) # optional - sage.rings.finite_rings
304304
True
305305
"""
306-
K=self.base_ring()
307-
char=K.characteristic()
308-
D=K(D)
306+
K = self.base_ring()
307+
char = K.characteristic()
308+
D = K(D)
309309

310-
if char==2 or char==3:
310+
if char == 2 or char == 3:
311311
raise ValueError("Sextic twist not defined in chars 2,3")
312312

313-
if self.j_invariant() !=K(0):
313+
if self.j_invariant() != K(0):
314314
raise ValueError("Sextic twist not defined when j!=0")
315315

316316
if D.is_zero():
317317
raise ValueError("Sextic twist requires a nonzero argument")
318318

319-
c4,c6=self.c_invariants()
319+
c4,c6 = self.c_invariants()
320320
# E is isomorphic to [0,0,0,0,-54*c6]
321-
assert c4==0
321+
assert c4 == 0
322322
return EllipticCurve(K,[0,0,0,0,-54*c6*D])
323323

324324
def is_quadratic_twist(self, other):
@@ -420,7 +420,7 @@ def is_quadratic_twist(self, other):
420420
zero = K.zero()
421421
if not K == F.base_ring():
422422
return zero
423-
j=E.j_invariant()
423+
j = E.j_invariant()
424424
if j != F.j_invariant():
425425
return zero
426426

@@ -429,12 +429,12 @@ def is_quadratic_twist(self, other):
429429
return rings.ZZ(1)
430430
return K.one()
431431

432-
char=K.characteristic()
432+
char = K.characteristic()
433433

434-
if char==2:
434+
if char == 2:
435435
raise NotImplementedError("not implemented in characteristic 2")
436-
elif char==3:
437-
if j==0:
436+
elif char == 3:
437+
if j == 0:
438438
raise NotImplementedError("not implemented in characteristic 3 for curves of j-invariant 0")
439439
D = E.b2()/F.b2()
440440

@@ -443,18 +443,18 @@ def is_quadratic_twist(self, other):
443443
c4E,c6E = E.c_invariants()
444444
c4F,c6F = F.c_invariants()
445445

446-
if j==0:
446+
if j == 0:
447447
um = c6E/c6F
448-
x=rings.polygen(K)
449-
ulist=(x**3-um).roots(multiplicities=False)
448+
x = rings.polygen(K)
449+
ulist = (x**3-um).roots(multiplicities=False)
450450
if not ulist:
451451
D = zero
452452
else:
453453
D = ulist[0]
454-
elif j==1728:
455-
um=c4E/c4F
456-
x=rings.polygen(K)
457-
ulist=(x**2-um).roots(multiplicities=False)
454+
elif j == 1728:
455+
um = c4E/c4F
456+
x = rings.polygen(K)
457+
ulist = (x**2-um).roots(multiplicities=False)
458458
if not ulist:
459459
D = zero
460460
else:
@@ -519,18 +519,18 @@ def is_quartic_twist(self, other):
519519
zero = K.zero()
520520
if not K == F.base_ring():
521521
return zero
522-
j=E.j_invariant()
523-
if j != F.j_invariant() or j!=K(1728):
522+
j = E.j_invariant()
523+
if j != F.j_invariant() or j != K(1728):
524524
return zero
525525

526526
if E.is_isomorphic(F):
527527
return K.one()
528528

529-
char=K.characteristic()
529+
char = K.characteristic()
530530

531-
if char==2:
531+
if char == 2:
532532
raise NotImplementedError("not implemented in characteristic 2")
533-
elif char==3:
533+
elif char == 3:
534534
raise NotImplementedError("not implemented in characteristic 3")
535535
else:
536536
# now char!=2,3:
@@ -588,18 +588,18 @@ def is_sextic_twist(self, other):
588588
zero = K.zero()
589589
if not K == F.base_ring():
590590
return zero
591-
j=E.j_invariant()
591+
j = E.j_invariant()
592592
if j != F.j_invariant() or not j.is_zero():
593593
return zero
594594

595595
if E.is_isomorphic(F):
596596
return K.one()
597597

598-
char=K.characteristic()
598+
char = K.characteristic()
599599

600-
if char==2:
600+
if char == 2:
601601
raise NotImplementedError("not implemented in characteristic 2")
602-
elif char==3:
602+
elif char == 3:
603603
raise NotImplementedError("not implemented in characteristic 3")
604604
else:
605605
# now char!=2,3:
@@ -1757,7 +1757,7 @@ def hasse_invariant(self):
17571757
R = k['x']
17581758
x = R.gen()
17591759
E = self.short_weierstrass_model()
1760-
f=(x**3+E.a4()*x+E.a6())**((p-1)//2)
1760+
f = (x**3+E.a4()*x+E.a6())**((p-1)//2)
17611761
return f.coefficients(sparse=False)[p-1]
17621762

17631763
def isogeny_ell_graph(self, l, directed=True, label_by_j=False):

0 commit comments

Comments
 (0)