Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some pep8 in elliptic curves #35677

Merged
merged 3 commits into from
Jun 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions src/sage/schemes/elliptic_curves/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def hilbert_class_polynomial(D, algorithm=None):
h = len(rqf) # class number
c1 = 3.05682737291380 # log(2*10.63)
c2 = sum([1/RR(qf[0]) for qf in rqf], RR(0))
prec = c2*RR(3.142)*RR(D).abs().sqrt() + h*c1 # bound on log
prec = c2 * RR(3.142) * RR(D).abs().sqrt() + h * c1 # bound on log
prec = prec * 1.45 # bound on log_2 (1/log(2) = 1.44..)
prec = 10 + prec.ceil() # allow for rounding error

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

h = f.degree()
h2list = [d for d in h.divisors() if (d-h)%2 == 0 and d.prime_to_m_part(2) == 1]
h2list = [d for d in h.divisors()
if (d-h) % 2 == 0 and d.prime_to_m_part(2) == 1]
pmin = 33 * (h**2 * (RR(h+2).log().log()+2)**2).ceil()
# Guarantees 4*p > |D| for fundamental D under GRH
p = pmin-1
Expand All @@ -262,7 +263,7 @@ def is_HCP(f, check_monic_irreducible=True):
continue
if not fp.is_squarefree():
continue
if d<h and d not in h2list:
if d < h and d not in h2list:
return zero
jp = fp.any_root(degree=-1, assume_squarefree=True)
E = EllipticCurve(j=jp)
Expand Down Expand Up @@ -317,14 +318,15 @@ def OrderClassNumber(D0,h0,f):
ps = f.prime_divisors()
from sage.misc.misc_c import prod
from sage.arith.misc import kronecker as kronecker_symbol
n = (f // prod(ps)) * prod(p-kronecker_symbol(D0,p) for p in ps)
n = (f // prod(ps)) * prod(p - kronecker_symbol(D0, p) for p in ps)
if D0 == -3:
#assert h0 == 1 and n%3==0
return n//3
# assert h0 == 1 and n % 3 == 0
return n // 3
if D0 == -4:
#assert h0 == 1 and n%2==0
return n//2
return n*h0
# assert h0 == 1 and n % 2 == 0
return n // 2
return n * h0


@cached_function
def cm_j_invariants(K, proof=None):
Expand Down Expand Up @@ -766,10 +768,10 @@ def discriminants_with_bounded_class_number(hmax, B=None, proof=None):

# Easy case where we have already computed and cached the relevant values
if hDf_dict and hmax <= max(hDf_dict):
T = {h:Dflist for h,Dflist in hDf_dict.items() if h<=hmax}
T = {h:Dflist for h,Dflist in hDf_dict.items() if h <= hmax}
if B:
for h in T:
T[h] = [Df for Df in T[h] if Df[0].abs()*Df[1]**2<=B]
T[h] = [Df for Df in T[h] if Df[0].abs()*Df[1]**2 <= B]
return T

# imports that are needed only for this function
Expand Down Expand Up @@ -820,7 +822,7 @@ def discriminants_with_bounded_class_number(hmax, B=None, proof=None):
for D0,f in Dflist:
h_dict[D0*f**2] = h
if not count:
Dflist = [Df for Df in Dflist if Df[0].abs()*Df[1]**2<=B]
Dflist = [Df for Df in Dflist if Df[0].abs()*Df[1]**2 <= B]
T[h] = set(Dflist)

# We do not need to certify the class number from :pari:`qfbclassno` for discriminants under 2*10^10
Expand All @@ -831,7 +833,7 @@ def discriminants_with_bounded_class_number(hmax, B=None, proof=None):
if not D.is_discriminant():
continue
D0 = D.squarefree_part()
if D0%4 !=1:
if D0 % 4 != 1:
D0 *= 4
f = (D//D0).isqrt()

Expand Down Expand Up @@ -983,16 +985,16 @@ def is_cm_j_invariant(j, algorithm='CremonaSutherland', method=None):
D = is_HCP(jpol, check_monic_irreducible=False)
if D:
D0 = D.squarefree_part()
if D0%4 !=1:
if D0 % 4 != 1:
D0 *= 4
f = ZZ(D//D0).isqrt()
return (True, (D0,f))
f = ZZ(D // D0).isqrt()
return (True, (D0, f))
else:
return (False, None)

h = jpol.degree()
if algorithm in ['exhaustive', 'old']:
if h>100:
if h > 100:
raise NotImplementedError("CM data only available for class numbers up to 100")
for d,f in cm_orders(h):
if jpol == hilbert_class_polynomial(d*f**2):
Expand Down Expand Up @@ -1020,8 +1022,8 @@ def is_cm_j_invariant(j, algorithm='CremonaSutherland', method=None):
from sage.schemes.elliptic_curves.constructor import EllipticCurve
E = EllipticCurve(j=j).integral_model()
D = E.discriminant()
prime_bound = 1000 # test primes of degree 1 up to this norm
max_primes = 20 # test at most this many primes
prime_bound = 1000 # test primes of degree 1 up to this norm
max_primes = 20 # test at most this many primes
num_prime = 0
cmd = 0
cmf = 0
Expand All @@ -1045,8 +1047,8 @@ def is_cm_j_invariant(j, algorithm='CremonaSutherland', method=None):
if cmd: # we have a candidate CM field already
break
else: # we need to try more primes
max_primes *=2
if D.valuation(P)>0: # skip bad primes
max_primes *= 2
if D.valuation(P) > 0: # skip bad primes
continue
aP = E.reduction(P).trace_of_frobenius()
if aP == 0: # skip supersingular primes
Expand Down
20 changes: 10 additions & 10 deletions src/sage/schemes/elliptic_curves/constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,14 +696,14 @@ def coefficients_from_j(j, minimal_twist=True):
if K not in _Fields:
K = K.fraction_field()

char=K.characteristic()
if char==2:
char = K.characteristic()
if char == 2:
if j == 0:
return Sequence([0, 0, 1, 0, 0], universe=K)
else:
return Sequence([1, 0, 0, 0, 1/j], universe=K)
if char == 3:
if j==0:
if j == 0:
return Sequence([0, 0, 0, 1, 0], universe=K)
else:
return Sequence([0, j, 0, 0, -j**2], universe=K)
Expand All @@ -717,7 +717,7 @@ def coefficients_from_j(j, minimal_twist=True):
return Sequence([0, 0, 0, -1, 0], universe=K) # 32a2

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

n = j.numerator()
Expand All @@ -729,7 +729,7 @@ def coefficients_from_j(j, minimal_twist=True):
from sage.sets.set import Set
for p in Set(n.prime_divisors()+m.prime_divisors()):
e = min(a4.valuation(p)//2,a6.valuation(p)//3)
if e>0:
if e > 0:
p = p**e
a4 /= p**2
a6 /= p**3
Expand All @@ -754,7 +754,7 @@ def coefficients_from_j(j, minimal_twist=True):
return Sequence([0, 0, 0, 0, 1], universe=K)
if j == 1728:
return Sequence([0, 0, 0, 1, 0], universe=K)
k=j-1728
k = j-1728
return Sequence([0, 0, 0, -3*j*k, -2*j*k**2], universe=K)


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

hessian = Matrix([[F.derivative(v1, v2) for v1 in R.gens()] for v2 in R.gens()]).det()
if P and hessian(P)==0:
if P and hessian(P) == 0:
flex_point = P
else:
flexes = C.intersection(Curve(hessian)).rational_points()
Expand Down Expand Up @@ -1174,11 +1174,11 @@ def EllipticCurve_from_cubic(F, P=None, morphism=True):
if not P:
raise ValueError('A point must be given when the cubic has no rational flexes')
L = tangent_at_smooth_point(C,P)
Qlist = [Q for Q in C.intersection(Curve(L)).rational_points() if C(Q)!=CP]
Qlist = [Q for Q in C.intersection(Curve(L)).rational_points() if C(Q) != CP]
# assert Qlist
P2 = C(Qlist[0])
L2 = tangent_at_smooth_point(C,P2)
Qlist = [Q for Q in C.intersection(Curve(L2)).rational_points() if C(Q)!=P2]
Qlist = [Q for Q in C.intersection(Curve(L2)).rational_points() if C(Q) != P2]
# assert Qlist
P3 = C(Qlist[0])

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

L = Curve(tangent_at_smooth_point(C,P))
Qlist = [Q for Q in C.intersection(L).rational_points() if Q!=P]
Qlist = [Q for Q in C.intersection(L).rational_points() if Q != P]
if Qlist:
return Qlist[0]
return P
Expand Down
4 changes: 2 additions & 2 deletions src/sage/schemes/elliptic_curves/ec_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def rank(self, rank, tors=0, n=10, labels=False):
[]
"""
from sage.env import ELLCURVE_DATA_DIR
data = os.path.join(ELLCURVE_DATA_DIR, 'rank%s'%rank)
data = os.path.join(ELLCURVE_DATA_DIR, 'rank%s' % rank)
try:
f = open(data)
except IOError:
Expand All @@ -151,7 +151,7 @@ def rank(self, rank, tors=0, n=10, labels=False):
# NOTE: only change this bound below after checking/fixing
# the Cremona labels in the elliptic_curves package!
if N <= 400000:
label = '%s%s%s'%(N, iso, num)
label = '%s%s%s' % (N, iso, num)
else:
label = None

Expand Down
24 changes: 12 additions & 12 deletions src/sage/schemes/elliptic_curves/ell_curve_isogeny.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,13 +483,13 @@ def compute_codomain_kohel(E, kernel):

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

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

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

s1 = -psi_2tor[n-1]
s2 = psi_2tor[n-2]
s3 = -psi_2tor[n-3]
s1 = -psi_2tor[n - 1]
s2 = psi_2tor[n - 2]
s3 = -psi_2tor[n - 3]

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

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

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

s1 = -psi[n-1] if n >= 1 else 0
s2 = psi[n-2] if n >= 2 else 0
s3 = -psi[n-3] if n >= 3 else 0
s1 = -psi[n - 1] if n >= 1 else 0
s2 = psi[n - 2] if n >= 2 else 0
s3 = -psi[n - 3] if n >= 3 else 0

# initializing these allows us to calculate E2.
v, w = compute_vw_kohel_odd(b2, b4, b6, s1, s2, s3, n)
Expand Down Expand Up @@ -1893,7 +1893,7 @@ def __init_from_kernel_list(self, kernel_gens):
to Elliptic Curve defined by y^2 = x^3 + 80816485163488178037199320944019099858815874115367810482828676054000067654558381377552245721755005198633191074893*x + 301497584865165444049833326660609767433467459033532853758006118022998267706948164646650354324860226263546558337993
over Finite Field of size 461742260113997803268895001173557974278278194575766957660028841364655249961609425998827452443620996655395008156411
"""
if self.__check :
if self.__check:
for P in kernel_gens:
if not P.has_finite_order():
raise ValueError("given kernel contains point of infinite order")
Expand Down Expand Up @@ -2337,7 +2337,7 @@ def __init_even_kernel_polynomial(self, E, psi_G):
(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)
"""
# check if the polynomial really divides the two_torsion_polynomial
if self.__check and E.division_polynomial(2, x=self.__poly_ring.gen()) % psi_G != 0 :
if self.__check and E.division_polynomial(2, x=self.__poly_ring.gen()) % psi_G != 0:
raise ValueError(f"the polynomial {psi_G} does not define a finite subgroup of {E}")

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

elif n == 3:
s1 = -psi_G[n-1]
s2 = psi_G[n-2]
s3 = -psi_G[n-3]
s1 = -psi_G[n - 1]
s2 = psi_G[n - 2]
s3 = -psi_G[n - 3]

psi_G_pr = psi_G.derivative()
psi_G_prpr = psi_G_pr.derivative()
Expand Down
Loading