diff --git a/src/sage/schemes/elliptic_curves/cm.py b/src/sage/schemes/elliptic_curves/cm.py index 57f8744dc80..a70c09f79bd 100644 --- a/src/sage/schemes/elliptic_curves/cm.py +++ b/src/sage/schemes/elliptic_curves/cm.py @@ -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 @@ -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 @@ -262,7 +263,7 @@ def is_HCP(f, check_monic_irreducible=True): continue if not fp.is_squarefree(): continue - if d100: + 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): @@ -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 @@ -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 diff --git a/src/sage/schemes/elliptic_curves/constructor.py b/src/sage/schemes/elliptic_curves/constructor.py index 15bdb273259..eae54a05fcd 100644 --- a/src/sage/schemes/elliptic_curves/constructor.py +++ b/src/sage/schemes/elliptic_curves/constructor.py @@ -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) @@ -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() @@ -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 @@ -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) @@ -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() @@ -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]) @@ -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 diff --git a/src/sage/schemes/elliptic_curves/ec_database.py b/src/sage/schemes/elliptic_curves/ec_database.py index 375e01fa93a..043c287ec7e 100644 --- a/src/sage/schemes/elliptic_curves/ec_database.py +++ b/src/sage/schemes/elliptic_curves/ec_database.py @@ -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: @@ -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 diff --git a/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py b/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py index 9e1d9473081..6e09633afb4 100644 --- a/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py +++ b/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py @@ -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) @@ -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) @@ -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") @@ -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 @@ -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() diff --git a/src/sage/schemes/elliptic_curves/ell_field.py b/src/sage/schemes/elliptic_curves/ell_field.py index 457ab8f7e78..ae0c0073a9c 100644 --- a/src/sage/schemes/elliptic_curves/ell_field.py +++ b/src/sage/schemes/elliptic_curves/ell_field.py @@ -155,7 +155,7 @@ def quadratic_twist(self, D=None): # degree is odd we can take D=1; otherwise it suffices to # consider odd powers of a generator. D = K(1) - if K.degree()%2==0: + if K.degree() % 2 == 0: D = K.gen() a = D**2 while (x**2 + x + D).roots(): @@ -172,26 +172,26 @@ def quadratic_twist(self, D=None): raise ValueError("twisting parameter D must be specified over infinite fields.") else: try: - D=K(D) + D = K(D) except ValueError: raise ValueError("twisting parameter D must be in the base field.") - if char!=2 and D.is_zero(): + if char != 2 and D.is_zero(): raise ValueError("twisting parameter D must be nonzero when characteristic is not 2") - if char!=2: - b2,b4,b6,b8=self.b_invariants() + if char != 2: + b2,b4,b6,b8 = self.b_invariants() # E is isomorphic to [0,b2,0,8*b4,16*b6] return EllipticCurve(K,[0,b2*D,0,8*b4*D**2,16*b6*D**3]) # now char==2 - if self.j_invariant() !=0: # iff a1!=0 - a1,a2,a3,a4,a6=self.ainvs() - E0=self.change_weierstrass_model(a1,a3/a1,0,(a1**2*a4+a3**2)/a1**3) + if self.j_invariant() != 0: # iff a1!=0 + a1,a2,a3,a4,a6 = self.ainvs() + E0 = self.change_weierstrass_model(a1,a3/a1,0,(a1**2*a4+a3**2)/a1**3) # which has the form = [1,A2,0,0,A6] - assert E0.a1()==K(1) - assert E0.a3()==K(0) - assert E0.a4()==K(0) + assert E0.a1() == K(1) + assert E0.a3() == K(0) + assert E0.a4() == K(0) return EllipticCurve(K,[1,E0.a2()+D,0,0,E0.a6()]) else: raise ValueError("Quadratic twist not implemented in char 2 when j=0") @@ -229,8 +229,8 @@ def two_torsion_rank(self): sage: EllipticCurve('15a1').two_torsion_rank() 2 """ - f=self.division_polynomial(rings.Integer(2)) - n=len(f.roots())+1 + f = self.division_polynomial(rings.Integer(2)) + n = len(f.roots())+1 return rings.Integer(n).ord(rings.Integer(2)) def quartic_twist(self, D): @@ -258,22 +258,22 @@ def quartic_twist(self, D): sage: E.is_isomorphic(E1, GF(13^4,'a')) # optional - sage.rings.finite_rings True """ - K=self.base_ring() - char=K.characteristic() - D=K(D) + K = self.base_ring() + char = K.characteristic() + D = K(D) - if char==2 or char==3: + if char == 2 or char == 3: raise ValueError("Quartic twist not defined in chars 2,3") - if self.j_invariant() !=K(1728): + if self.j_invariant() != K(1728): raise ValueError("Quartic twist not defined when j!=1728") if D.is_zero(): raise ValueError("quartic twist requires a nonzero argument") - c4,c6=self.c_invariants() + c4,c6 = self.c_invariants() # E is isomorphic to [0,0,0,-27*c4,0] - assert c6==0 + assert c6 == 0 return EllipticCurve(K,[0,0,0,-27*c4*D,0]) def sextic_twist(self, D): @@ -303,22 +303,22 @@ def sextic_twist(self, D): sage: E.is_isomorphic(E1, GF(13^6,'a')) # optional - sage.rings.finite_rings True """ - K=self.base_ring() - char=K.characteristic() - D=K(D) + K = self.base_ring() + char = K.characteristic() + D = K(D) - if char==2 or char==3: + if char == 2 or char == 3: raise ValueError("Sextic twist not defined in chars 2,3") - if self.j_invariant() !=K(0): + if self.j_invariant() != K(0): raise ValueError("Sextic twist not defined when j!=0") if D.is_zero(): raise ValueError("Sextic twist requires a nonzero argument") - c4,c6=self.c_invariants() + c4,c6 = self.c_invariants() # E is isomorphic to [0,0,0,0,-54*c6] - assert c4==0 + assert c4 == 0 return EllipticCurve(K,[0,0,0,0,-54*c6*D]) def is_quadratic_twist(self, other): @@ -420,7 +420,7 @@ def is_quadratic_twist(self, other): zero = K.zero() if not K == F.base_ring(): return zero - j=E.j_invariant() + j = E.j_invariant() if j != F.j_invariant(): return zero @@ -429,12 +429,12 @@ def is_quadratic_twist(self, other): return rings.ZZ(1) return K.one() - char=K.characteristic() + char = K.characteristic() - if char==2: + if char == 2: raise NotImplementedError("not implemented in characteristic 2") - elif char==3: - if j==0: + elif char == 3: + if j == 0: raise NotImplementedError("not implemented in characteristic 3 for curves of j-invariant 0") D = E.b2()/F.b2() @@ -443,18 +443,18 @@ def is_quadratic_twist(self, other): c4E,c6E = E.c_invariants() c4F,c6F = F.c_invariants() - if j==0: + if j == 0: um = c6E/c6F - x=rings.polygen(K) - ulist=(x**3-um).roots(multiplicities=False) + x = rings.polygen(K) + ulist = (x**3-um).roots(multiplicities=False) if not ulist: D = zero else: D = ulist[0] - elif j==1728: - um=c4E/c4F - x=rings.polygen(K) - ulist=(x**2-um).roots(multiplicities=False) + elif j == 1728: + um = c4E/c4F + x = rings.polygen(K) + ulist = (x**2-um).roots(multiplicities=False) if not ulist: D = zero else: @@ -519,18 +519,18 @@ def is_quartic_twist(self, other): zero = K.zero() if not K == F.base_ring(): return zero - j=E.j_invariant() - if j != F.j_invariant() or j!=K(1728): + j = E.j_invariant() + if j != F.j_invariant() or j != K(1728): return zero if E.is_isomorphic(F): return K.one() - char=K.characteristic() + char = K.characteristic() - if char==2: + if char == 2: raise NotImplementedError("not implemented in characteristic 2") - elif char==3: + elif char == 3: raise NotImplementedError("not implemented in characteristic 3") else: # now char!=2,3: @@ -588,18 +588,18 @@ def is_sextic_twist(self, other): zero = K.zero() if not K == F.base_ring(): return zero - j=E.j_invariant() + j = E.j_invariant() if j != F.j_invariant() or not j.is_zero(): return zero if E.is_isomorphic(F): return K.one() - char=K.characteristic() + char = K.characteristic() - if char==2: + if char == 2: raise NotImplementedError("not implemented in characteristic 2") - elif char==3: + elif char == 3: raise NotImplementedError("not implemented in characteristic 3") else: # now char!=2,3: @@ -1757,7 +1757,7 @@ def hasse_invariant(self): R = k['x'] x = R.gen() E = self.short_weierstrass_model() - f=(x**3+E.a4()*x+E.a6())**((p-1)//2) + f = (x**3+E.a4()*x+E.a6())**((p-1)//2) return f.coefficients(sparse=False)[p-1] def isogeny_ell_graph(self, l, directed=True, label_by_j=False): diff --git a/src/sage/schemes/elliptic_curves/ell_finite_field.py b/src/sage/schemes/elliptic_curves/ell_finite_field.py index 67311df1789..cd1e9c1733c 100644 --- a/src/sage/schemes/elliptic_curves/ell_finite_field.py +++ b/src/sage/schemes/elliptic_curves/ell_finite_field.py @@ -146,7 +146,7 @@ def _points_via_group_structure(self): ni = G.generator_orders() ngens = G.ngens() - H0=[self(0)] + H0 = [self(0)] if ngens == 0: # trivial group return H0 for m in range(1,ni[0]): @@ -155,7 +155,7 @@ def _points_via_group_structure(self): return H0 # else noncyclic group - H1=[self(0)] + H1 = [self(0)] for m in range(1,ni[1]): H1.append(H1[-1]+pts[1]) return [P+Q for P in H0 for Q in H1] @@ -207,10 +207,10 @@ def points(self): from sage.structure.sequence import Sequence k = self.base_ring() - if k.is_prime_field() and k.order()>50: + if k.is_prime_field() and k.order() > 50: v = self._points_via_group_structure() else: - v =self._points_fast_sqrt() + v = self._points_fast_sqrt() v.sort() self.__points = Sequence(v, immutable=True) return self.__points @@ -1498,7 +1498,7 @@ def height_above_floor(self, ell, e): phi = gen_to_sage(pari.polmodular(ell),{'x':X, 'y':Y}) j1 = phi([x,j]).roots(multiplicities=False) nj1 = len(j1) - on_floor = self.two_torsion_rank() < 2 if ell==2 else nj1 <= ell + on_floor = self.two_torsion_rank() < 2 if ell == 2 else nj1 <= ell if on_floor: return 0 if e == 1 or nj1 != ell+1: # double roots can only happen at the surface @@ -1569,11 +1569,11 @@ def endomorphism_discriminant_from_class_number(self, h): raise ValueError("Elliptic curve ({}) must be ordinary".format(self)) D1 = self.frobenius_discriminant() D0 = D1.squarefree_part() - if D0%4 !=1: + if D0 % 4 != 1: D0 *= 4 v = ZZ(D1//D0).isqrt() h0 = D0.class_number() - if h%h0: + if h % h0: raise ValueError("Incorrect class number {}".format(h)) from sage.schemes.elliptic_curves.cm import OrderClassNumber cs = [v//f for f in v.divisors() if OrderClassNumber(D0,h0,f) == h] # cofactors c=v/f compatible with h(f**2D0)=h @@ -1754,7 +1754,7 @@ def twists(self): twists = None if not j: twists = curves_with_j_0(K) - elif j==1728: + elif j == 1728: twists = curves_with_j_1728(K) if twists: # i.e. if j=0 or 1728 # replace the one isomorphic to self with self and move to front @@ -1823,19 +1823,19 @@ def curves_with_j_0(K): if not K.is_finite(): raise ValueError("field must be finite") p = K.characteristic() - if p==2: + if p == 2: return curves_with_j_0_char2(K) - if p==3: + if p == 3: return curves_with_j_0_char3(K) q = K.cardinality() - if q%3==2: + if q % 3 == 2: # Then we only have two quadratic twists (and -3 is non-square) return [EllipticCurve(K, [0,a]) for a in [1,-27]] # Now we have genuine sextic twists, find D generating K* mod 6th powers q2 = (q-1)//2 q3 = (q-1)//3 D = K.gen() - while not D or D**q2 == 1 or D**q3==1: + while not D or D**q2 == 1 or D**q3 == 1: D = K.random_element() return [EllipticCurve(K, [0,D**i]) for i in range(6)] @@ -1880,12 +1880,12 @@ def curves_with_j_1728(K): if not K.is_finite(): raise ValueError("field must be finite") p = K.characteristic() - if p==2: + if p == 2: return curves_with_j_0_char2(K) - if p==3: + if p == 3: return curves_with_j_0_char3(K) q = K.cardinality() - if q%4==3: + if q % 4 == 3: return [EllipticCurve(K, [a,0]) for a in [1,-1]] # Now we have genuine quartic twists, find D generating K* mod 4th powers q2 = (q-1)//2 @@ -1954,8 +1954,10 @@ def curves_with_j_0_char2(K): """ if not K.is_finite() or K.characteristic() != 2: raise ValueError("field must be finite of characteristic 2") - if K.degree()%2: - return [EllipticCurve(K,[0,0,1,0,0]), EllipticCurve(K,[0,0,1,1,0]), EllipticCurve(K,[0,0,1,1,1])] + if K.degree() % 2: + return [EllipticCurve(K, [0, 0, 1, 0, 0]), + EllipticCurve(K, [0, 0, 1, 1, 0]), + EllipticCurve(K, [0, 0, 1, 1, 1])] # find a,b,c,d,e such that # a is not a cube, i.e. a**((q-1)//3)!=1 # Tr(b)=1 @@ -1965,13 +1967,13 @@ def curves_with_j_0_char2(K): a = b = c = d = e = None x = polygen(K) q3 = (K.cardinality()-1)//3 - while not a or a**q3==1: + while not a or a**q3 == 1: a = K.random_element() asq = a*a while not b or not b.trace(): b = K.random_element() c = K.one() # OK if degree is 2 mod 4 - if K.degree()%4 == 0: + if K.degree() % 4 == 0: while (x**4+x+c).roots(): c = K.random_element() while not d or (x**2+a*x+d).roots(): @@ -2048,7 +2050,7 @@ def curves_with_j_0_char3(K): while not b or not b.trace(): b = K.random_element() - if K.degree()%2: + if K.degree() % 2: return [EllipticCurve(K, a4a6) for a4a6 in [[1,0], [-1,0], [-1,b], [-1,-b]]] @@ -2201,7 +2203,7 @@ def supersingular_j_polynomial(p, use_cache=True): raise ValueError("p (=%s) should be a prime number" % p) J = polygen(GF(p),'j') - if p<13: + if p < 13: return J.parent().one() if use_cache: fill_ss_j_dict() @@ -2209,7 +2211,7 @@ def supersingular_j_polynomial(p, use_cache=True): return J.parent()(supersingular_j_polynomials[p]) from sage.misc.misc_c import prod - m=(p-1)//2 + m = (p-1)//2 X,T = PolynomialRing(GF(p),2,names=['X','T']).gens() H = sum(binomial(m, i) ** 2 * T ** i for i in range(m + 1)) F = T**2 * (T-1)**2 * X - 256*(T**2-T+1)**3 diff --git a/src/sage/schemes/elliptic_curves/ell_modular_symbols.py b/src/sage/schemes/elliptic_curves/ell_modular_symbols.py index d2f92b789c8..11c0bc4b978 100644 --- a/src/sage/schemes/elliptic_curves/ell_modular_symbols.py +++ b/src/sage/schemes/elliptic_curves/ell_modular_symbols.py @@ -219,7 +219,7 @@ def _repr_(self): Modular symbol with sign -1 over Rational Field attached to Elliptic Curve defined by y^2 + y = x^3 + x^2 over Rational Field """ - return "Modular symbol with sign %s over %s attached to %s"%( + return "Modular symbol with sign %s over %s attached to %s" % ( self._sign, self._base_ring, self._E) class ModularSymbolECLIB(ModularSymbol): @@ -333,11 +333,11 @@ def __init__(self, E, sign, nap=1000): raise TypeError('sign must -1 or 1') self._sign = ZZ(sign) self._E = E - self._scaling = 1 if E.discriminant()>0 else ZZ(1)/2 + self._scaling = 1 if E.discriminant() > 0 else ZZ(1)/2 self._implementation = "eclib" self._base_ring = QQ # The ECModularSymbol class must be initialized with sign=0 to compute minus symbols - self._modsym = ECModularSymbol(E, int(sign==1), nap) + self._modsym = ECModularSymbol(E, int(sign == 1), nap) self.cache = {True: {}, False: {}} def _call_with_caching(self, r, base_at_infinity=True): @@ -468,7 +468,7 @@ def __init__(self, E, sign, normalize="L_ratio"): self._scaling = 1 self._e = self._modsym.dual_eigenvector() else : - raise ValueError("no normalization %s known for modular symbols"%normalize) + raise ValueError("no normalization %s known for modular symbols" % normalize) def _find_scaling_L_ratio(self): r""" @@ -553,7 +553,7 @@ def _find_scaling_L_ratio(self): if at0 != 0 : l1 = self.__lalg__(1) if at0 != l1: - verbose('scale modular symbols by %s'%(l1/at0)) + verbose('scale modular symbols by %s' % (l1/at0)) self._scaling = l1/at0 else : # if [0] = 0, we can still hope to scale it correctly by considering twists of E @@ -565,7 +565,7 @@ def _find_scaling_L_ratio(self): D = Dlist[j] # the following line checks if the twist of the newform of E by D is a newform # this is to avoid that we 'twist back' - if all( valuation(E.conductor(),ell)<= valuation(D,ell) for ell in prime_divisors(D) ) : + if all( valuation(E.conductor(),ell) <= valuation(D,ell) for ell in prime_divisors(D) ) : at0 = sum([kronecker_symbol(D,u) * self(ZZ(u)/D) for u in range(1,abs(D))]) j += 1 if j == 30 and at0 == 0: # curves like "121b1", "225a1", "225e1", "256a1", "256b1", "289a1", "361a1", "400a1", "400c1", "400h1", "441b1", "441c1", "441d1", "441f1 .. will arrive here @@ -574,7 +574,7 @@ def _find_scaling_L_ratio(self): else : l1 = self.__lalg__(D) if at0 != l1: - verbose('scale modular symbols by %s found at D=%s '%(l1/at0,D), level=2) + verbose('scale modular symbols by %s found at D=%s ' % (l1/at0,D), level=2) self._scaling = l1/at0 else : # that is when sign = -1 @@ -584,7 +584,7 @@ def _find_scaling_L_ratio(self): while j < 30 and at0 == 0 : # computes [0]+ for the twist of E by D until one value is non-zero D = Dlist[j] - if all( valuation(E.conductor(),ell)<= valuation(D,ell) for ell in prime_divisors(D) ) : + if all( valuation(E.conductor(),ell) <= valuation(D,ell) for ell in prime_divisors(D) ) : at0 = - sum([kronecker_symbol(D,u) * self(ZZ(u)/D) for u in range(1,abs(D))]) j += 1 if j == 30 and at0 == 0: # no more hope for a normalization @@ -593,7 +593,7 @@ def _find_scaling_L_ratio(self): else : l1 = self.__lalg__(D) if at0 != l1: - verbose('scale modular symbols by %s'%(l1/at0)) + verbose('scale modular symbols by %s' % (l1/at0)) self._scaling = l1/at0 def __lalg__(self, D): diff --git a/src/sage/schemes/elliptic_curves/ell_rational_field.py b/src/sage/schemes/elliptic_curves/ell_rational_field.py index 420a6c7cc77..824149ca204 100644 --- a/src/sage/schemes/elliptic_curves/ell_rational_field.py +++ b/src/sage/schemes/elliptic_curves/ell_rational_field.py @@ -104,13 +104,13 @@ Z = IntegerRing() IR = rings.RealIntervalField(20) -_MAX_HEIGHT=21 +_MAX_HEIGHT = 21 # complex multiplication dictionary: # CMJ is a dict of pairs (j,D) where j is a rational CM j-invariant # and D is the corresponding quadratic discriminant -CMJ={ 0: -3, 54000: -12, -12288000: -27, 1728: -4, 287496: -16, +CMJ = { 0: -3, 54000: -12, -12288000: -27, 1728: -4, 287496: -16, -3375: -7, 16581375: -28, 8000: -8, -32768: -11, -884736: -19, -884736000: -43, -147197952000: -67, -262537412640768000: -163} @@ -539,7 +539,7 @@ def conductor(self, algorithm="pari"): try: return self.__conductor_gp except AttributeError: - self.__conductor_gp = Integer(gp.eval('ellglobalred(ellinit(%s,0))[1]'%list(self.a_invariants()))) + self.__conductor_gp = Integer(gp.eval('ellglobalred(ellinit(%s,0))[1]' % list(self.a_invariants()))) return self.__conductor_gp elif algorithm == "mwrank": @@ -565,11 +565,11 @@ def conductor(self, algorithm="pari"): N3 = self.conductor("gp") N4 = self.conductor("generic") if N1 != N2 or N2 != N3 or N2 != N4: - raise ArithmeticError("PARI, mwrank, gp and Sage compute different conductors (%s,%s,%s,%s) for %s"%( + raise ArithmeticError("PARI, mwrank, gp and Sage compute different conductors (%s,%s,%s,%s) for %s" % ( N1, N2, N3, N4, self)) return N1 else: - raise ValueError("algorithm %r is not known"%algorithm) + raise ValueError("algorithm %r is not known" % algorithm) #################################################################### # Access to PARI curves related to this curve. @@ -711,13 +711,13 @@ def database_curve(self): try: return self.__database_curve except AttributeError: - verbose_verbose("Looking up %s in the database."%self) + verbose_verbose("Looking up %s in the database." % self) D = sage.databases.cremona.CremonaDatabase() ainvs = list(self.minimal_model().ainvs()) try: self.__database_curve = D.elliptic_curve_from_ainvs(ainvs) except RuntimeError: - raise RuntimeError("Elliptic curve %s not in the database."%self) + raise RuntimeError("Elliptic curve %s not in the database." % self) return self.__database_curve def Np(self, p): @@ -910,7 +910,7 @@ def anlist(self, n, python_ints=False): n = int(n) e = self.pari_mincurve() if n >= 2147483648: - raise RuntimeError("anlist: n (=%s) must be < 2147483648."%n) + raise RuntimeError("anlist: n (=%s) must be < 2147483648." % n) v = [0] + e.ellan(n, python_ints=True) if not python_ints: @@ -1535,7 +1535,7 @@ def analytic_rank(self, algorithm="pari", leading_coefficient=False): from sage.lfunctions.lcalc import lcalc return lcalc.analytic_rank(L=self) except TypeError as msg: - raise RuntimeError("unable to compute analytic rank using rubinstein algorithm (%s)"%msg) + raise RuntimeError("unable to compute analytic rank using rubinstein algorithm (%s)" % msg) elif algorithm == 'sympow': if leading_coefficient: raise NotImplementedError("Cannot compute leading coefficient using sympow") @@ -1561,7 +1561,7 @@ def analytic_rank(self, algorithm="pari", leading_coefficient=False): raise RuntimeError("Bug in analytic_rank; algorithms don't agree! (E=%s)" % self) return list(S)[0] else: - raise ValueError("algorithm %s not defined"%algorithm) + raise ValueError("algorithm %s not defined" % algorithm) def analytic_rank_upper_bound(self, max_Delta=None, @@ -1917,7 +1917,7 @@ def simon_two_descent(self, verbose=0, lim1=5, lim3=50, limtriv=3, two_selmer_rank = t[1] pts = t[2] if rank_low_bd == two_selmer_rank - self.two_torsion_rank(): - if verbose>0: + if verbose > 0: print("Rank determined successfully, saturating...") gens = self.saturation(pts)[0] if len(gens) == rank_low_bd: @@ -2095,7 +2095,7 @@ def rank(self, use_database=True, verbose=False, # true rank rank_bound = self.analytic_rank_upper_bound() if rank_bound <= 1: - verbose_verbose("rank %s due to zero sum bound and parity"%rank_bound) + verbose_verbose("rank %s due to zero sum bound and parity" % rank_bound) rank = Integer(rank_bound) self.__rank = (rank, proof) return rank @@ -2113,7 +2113,7 @@ def rank(self, use_database=True, verbose=False, else: Lprime, err = self.lseries().deriv_at1(prec) if abs(Lprime) > err + R(0.0001): # definitely doesn't vanish - verbose_verbose("rank 1 because L'(E,1)=%s"%Lprime) + verbose_verbose("rank 1 because L'(E,1)=%s" % Lprime) rank = Integer(1) self.__rank = (rank, proof) return rank @@ -2144,7 +2144,7 @@ def rank(self, use_database=True, verbose=False, X = self.mwrank() if 'determined unconditionally' not in X or 'only a lower bound of' in X: if proof: - X= "".join(X.split("\n")[-4:-2]) + X = "".join(X.split("\n")[-4:-2]) print(X) raise RuntimeError('rank not provably correct') else: @@ -2162,7 +2162,7 @@ def rank(self, use_database=True, verbose=False, match = 'found points of rank' i = X.find(match) if i == -1: - raise RuntimeError("%s\nbug -- tried to find 'Rank =' or 'found points of rank' in mwrank output but couldn't."%X) + raise RuntimeError("%s\nbug -- tried to find 'Rank =' or 'found points of rank' in mwrank output but couldn't." % X) j = i + X[i:].find('\n') rank = Integer(X[i+len(match)+1:j]) self.__rank = (rank, proof) @@ -2320,7 +2320,7 @@ def _compute_gens(self, proof, verbose_verbose("Rank = 1, so using direct search.") h = 6 while h <= rank1_search: - verbose_verbose("Trying direct search up to height %s"%h) + verbose_verbose("Trying direct search up to height %s" % h) G = self.point_search(h, verbose) G = [P for P in G if P.order() == oo] if G: @@ -2636,7 +2636,7 @@ def saturation(self, points, verbose=False, max_prime=-1, min_prime=2): if not isinstance(P, ell_point.EllipticCurvePoint_field): P = self(P) elif P.curve() != self: - raise ArithmeticError("point (=%s) must be %s."%(P,self)) + raise ArithmeticError("point (=%s) must be %s." % (P,self)) minimal = True if not self.is_minimal(): @@ -2773,7 +2773,7 @@ def h_oo(x): elif algorithm == 'mwrank': return self.mwrank_curve().silverman_bound() else: - raise ValueError("unknown algorithm '%s'"%algorithm) + raise ValueError("unknown algorithm '%s'" % algorithm) def point_search(self, height_limit, verbose=False, rank_bound=None): r""" @@ -3180,10 +3180,10 @@ def tamagawa_exponent(self, p): if not arith.is_prime(p): raise ArithmeticError("p must be prime") cp = self.tamagawa_number(p) - if not cp==4: + if not cp == 4: return cp ks = self.kodaira_type(p) - if ks._roman==1 and ks._n%2==0 and ks._starred: + if ks._roman == 1 and ks._n % 2 == 0 and ks._starred: return 2 return 4 @@ -3763,7 +3763,7 @@ def modular_degree(self, algorithm='sympow', M=1): from sage.interfaces.magma import magma m = rings.Integer(magma(self).ModularDegree()) else: - raise ValueError("unknown algorithm %s"%algorithm) + raise ValueError("unknown algorithm %s" % algorithm) self.__modular_degree = m return m @@ -3884,7 +3884,7 @@ def congruence_number(self, M=1): 1 """ # Case 1: M==1 - if M==1: + if M == 1: try: return self.__congruence_number except AttributeError: @@ -3996,7 +3996,7 @@ def reduction(self,p): raise AttributeError("p must be prime.") disc = self.discriminant() if not disc.valuation(p) == 0: - local_data=self.local_data(p) + local_data = self.local_data(p) if local_data.has_good_reduction(): return local_data.minimal_model().change_ring(rings.GF(p)) raise AttributeError("The curve must have good reduction at p.") @@ -4285,7 +4285,7 @@ def cm_discriminant(self): try: return ZZ(CMJ[self.j_invariant()]) except KeyError: - raise ValueError("%s does not have CM"%self) + raise ValueError("%s does not have CM" % self) def has_rational_cm(self, field=None): r""" @@ -4367,7 +4367,7 @@ def has_rational_cm(self, field=None): except ValueError: return False try: - if field.characteristic()==0: + if field.characteristic() == 0: D = field(D) return D.is_square() raise ValueError("Error in has_rational_cm: %s is not an extension field of QQ" % field) @@ -4726,9 +4726,9 @@ def isogenies_prime_degree(self, l=None): if l.is_prime(proof=False): return isogenies_sporadic_Q(self, l) else: - raise ValueError("%s is not prime."%l) + raise ValueError("%s is not prime." % l) except AttributeError: - raise ValueError("%s is not prime."%l) + raise ValueError("%s is not prime." % l) if l is None: isogs = isogenies_prime_degree_genus_0(self) if isogs: @@ -5375,8 +5375,8 @@ def supersingular_primes(self, B): v = self.aplist(max(B, 3)) P = rings.prime_range(max(B,3)+1) N = self.conductor() - return [P[i] for i in [0,1] if P[i] <= B and v[i]%P[i]==0 and N%P[i] != 0] + \ - [P[i] for i in range(2,len(v)) if v[i] == 0 and N%P[i] != 0] + return [P[i] for i in [0,1] if P[i] <= B and v[i] % P[i] == 0 and N % P[i] != 0] + \ + [P[i] for i in range(2,len(v)) if v[i] == 0 and N % P[i] != 0] def ordinary_primes(self, B): """ @@ -6004,7 +6004,7 @@ def point_preprocessing(free,tor): P = free[i0] for i in range(r): if not free_id[i]: - if i==i0: + if i == i0: newfree[i] = 2*newfree[i] else: newfree[i] += P @@ -6039,9 +6039,9 @@ def point_preprocessing(free,tor): RR = R prec = RR.precision() ei = pol.roots(RR,multiplicities=False) - while len(ei)<3: - prec*=2 - RR=RealField(prec) + while len(ei) < 3: + prec *= 2 + RR = RealField(prec) ei = pol.roots(RR,multiplicities=False) e1,e2,e3 = ei if r >= 1: #preprocessing of mw_base only necessary if rank > 0 @@ -6072,9 +6072,9 @@ def point_preprocessing(free,tor): h_E = self.height() w1, w2 = self.period_lattice().basis() mu = R(disc).abs().log() / 6 - if j!=0: + if j != 0: mu += max(R(1),R(j).abs().log()) / 6 - if b2!=0: + if b2 != 0: mu += max(R(1),R(b2).abs().log()) mu += log(R(2)) else: @@ -6100,7 +6100,7 @@ def point_preprocessing(free,tor): mod_h_list.append(max(mw_base[i].height(),h_E,c7*mw_base_log[i]**2)) c9_help_list.append((mod_h_list[i]).sqrt()/mw_base_log[i]) c9 = e/c7.sqrt() * min(c9_help_list) - n=r+1 + n = r+1 c10 = R(2 * 10**(8+7*n) * R((2/e)**(2 * n**2)) * (n+1)**(4 * n**2 + 10 * n) * log(c9)**(-2*n - 1) * misc.prod(mod_h_list)) top = Z(128) # arbitrary first upper bound @@ -6210,7 +6210,7 @@ def point_preprocessing(free,tor): print(L) sys.stdout.flush() - if len(tors_points)>1: + if len(tors_points) > 1: x_int_points_t = set() for x in x_int_points: P = self.lift_x(x) @@ -6386,7 +6386,7 @@ def S_integral_points(self, S, mw_base='auto', both_signs=False, verbose=False, if not self.is_integral(): raise ValueError("S_integral_points() can only be called on an integral model") if not all(self.is_p_minimal(s) for s in S): - raise ValueError("%s must be p-minimal for all primes in S"%self) + raise ValueError("%s must be p-minimal for all primes in S" % self) try: len_S = len(S) @@ -6430,11 +6430,11 @@ def reduction_at(p): m = copy(M.identity_matrix()) for i in range(r): try: - m[i, r] = Z((beta[indexp][i])%pc) + m[i, r] = Z((beta[indexp][i]) % pc) except ZeroDivisionError: #If Inverse doesn't exist, change denominator (which is only approx) val_nu = (beta[indexp][i]).numerator() val_de = (beta[indexp][i]).denominator() - m[i, r] = Z((val_nu/(val_de+1))%pc) + m[i, r] = Z((val_nu/(val_de+1)) % pc) m[r,r] = max(Z(1), pc) #LLL - implemented in sage - operates on rows not on columns @@ -6489,8 +6489,8 @@ def S_integral_points_with_bounded_mw_coeffs(): denominator. """ from sage.groups.generic import multiples - xs=set() - N=H_q + xs = set() + N = H_q def test(P): """ @@ -6509,7 +6509,7 @@ def test_with_T(R): test(R+T) # For small rank and small H_q perform simple search - if r==1 and N<=10: + if r == 1 and N <= 10: for P in multiples(mw_base[0],N+1): test_with_T(P) return xs @@ -6519,7 +6519,7 @@ def test_with_T(R): # stops when (0,0,...,0) is reached because after that, only inverse points of # previously tested points would be tested - E0=E(0) + E0 = E(0) ni = [-N for i in range(r)] mw_baseN = [-N*P for P in mw_base] Pi = [0 for j in range(r)] @@ -6528,7 +6528,7 @@ def test_with_T(R): Pi[i] = Pi[i-1] + mw_baseN[i] while True: - if all(n==0 for n in ni): + if all(n == 0 for n in ni): test_with_T(E0) break @@ -6537,11 +6537,11 @@ def test_with_T(R): # increment indices and stored points i0 = r-1 - while ni[i0]==N: + while ni[i0] == N: ni[i0] = -N i0 -= 1 ni[i0] += 1 - if all(n==0 for n in ni[0:i0+1]): + if all(n == 0 for n in ni[0:i0+1]): Pi[i0] = E0 else: Pi[i0] += mw_base[i0] @@ -6579,7 +6579,7 @@ def S_integral_x_coords_with_abs_bounded_by(abs_bound): and search for integral points on the scaled model. """ x_min = min(self.two_division_polynomial().roots(R,multiplicities=False)) - x_min_neg = bool(x_min<0) + x_min_neg = bool(x_min < 0) x_min_pos = not x_min_neg log_ab = R(abs_bound.log()) alpha = [(log_ab/R(log(p,e))).floor() for p in S] @@ -6617,11 +6617,11 @@ def S_integral_x_coords_with_abs_bounded_by(abs_bound): for n in arith.xsrange(n_min,n_max+1): tmp = n/de # to save time, do not check de is the exact denominator if E.is_x_coord(tmp): - xs+=[tmp] + xs += [tmp] if not pos_n_only: if n <= neg_n_max: if E.is_x_coord(-tmp): - xs+=[-tmp] + xs += [-tmp] return set(xs) #<------------------------------------------------------------------------- @@ -6631,7 +6631,7 @@ def S_integral_x_coords_with_abs_bounded_by(abs_bound): E = self tors_points = E.torsion_points() - if (r==0):#only Torsionpoints to consider + if (r == 0):#only Torsionpoints to consider int_points = [P for P in tors_points if not P.is_zero()] int_points = [P for P in int_points if P[0].is_S_integral(S)] if not both_signs: @@ -6665,9 +6665,9 @@ def S_integral_x_coords_with_abs_bounded_by(abs_bound): RR = R prec = RR.precision() ei = pol.roots(RR,multiplicities=False) - while len(ei)<3: - prec*=2 - RR=RealField(prec) + while len(ei) < 3: + prec *= 2 + RR = RealField(prec) ei = pol.roots(RR,multiplicities=False) e1,e2,e3 = ei elif disc < 0: # one real component => 1 root in RR (=: e3), @@ -6715,21 +6715,21 @@ def S_integral_x_coords_with_abs_bounded_by(abs_bound): mw_base_log = [(pts.elliptic_logarithm().abs())*(len_tors/w1) for pts in mw_base] mw_base_p_log = [] beta = [] - mp=[] + mp = [] tmp = 0 for p in S: Np = E.Np(p) cp = E.tamagawa_exponent(p) mp_temp = Z(len_tors).lcm(cp*Np) mp.append(mp_temp) #only necessary because of verbose below - p_prec=30+E.discriminant().valuation(p) - p_prec_ok=False + p_prec = 30+E.discriminant().valuation(p) + p_prec_ok = False while not p_prec_ok: if verbose: print("p=", p, ": trying with p_prec = ", p_prec) try: mw_base_p_log.append([mp_temp*(pts.padic_elliptic_logarithm(p,absprec=p_prec)) for pts in mw_base]) - p_prec_ok=True + p_prec_ok = True except ValueError: p_prec *= 2 #reorder mw_base_p: last value has minimal valuation at p @@ -6748,7 +6748,7 @@ def S_integral_x_coords_with_abs_bounded_by(abs_bound): except ValueError: # e.g. mw_base_p_log[tmp]==[0]: can occur e.g. [?]'172c6, S=[2] beta.append([0] for j in range(r)) - tmp +=1 + tmp += 1 if verbose: print('mw_base', mw_base) @@ -6775,7 +6775,7 @@ def S_integral_x_coords_with_abs_bounded_by(abs_bound): while break_cond < 0.9: #reduction at infinity - bound_list=[] + bound_list = [] c = R((H_q**n)*100) m = copy(M.identity_matrix()) for i in range(r): @@ -6865,7 +6865,7 @@ def S_integral_x_coords_with_abs_bounded_by(abs_bound): print(L) sys.stdout.flush() - if len(tors_points)>1: + if len(tors_points) > 1: x_S_int_points_t = set() for x in x_S_int_points: P = E.lift_x(x) @@ -6984,7 +6984,7 @@ def integral_points_with_bounded_mw_coeffs(E, mw_base, N, x_bound): True """ from sage.groups.generic import multiples - xs=set() + xs = set() tors_points = E.torsion_points() r = len(mw_base) @@ -7007,7 +7007,7 @@ def use_t(R): # We use a naive method when the number of possibilities is small: - if r==1 and N<=10: + if r == 1 and N <= 10: for P in multiples(mw_base[0],N+1): use_t(P) return xs @@ -7040,7 +7040,7 @@ def is_approx_integral(rx): Rgens = [ER.lift_x(P[0]) for P in mw_base] for i in range(r): - if abs(Rgens[i][1]-mw_base[i][1])>abs((-Rgens[i])[1]-mw_base[i][1]): + if abs(Rgens[i][1]-mw_base[i][1]) > abs((-Rgens[i])[1]-mw_base[i][1]): Rgens[i] = -Rgens[i] # the ni loop through all tuples (a1,a2,...,ar) with @@ -7070,13 +7070,13 @@ def is_approx_integral(rx): # increment indices and stored points i0 = r-1 - while ni[i0]==N: + while ni[i0] == N: ni[i0] = -N i0 -= 1 ni[i0] += 1 # The next lines are to prevent rounding error: (-P)+P behaves # badly for real points! - if all(n==0 for n in ni[0:i0+1]): + if all(n == 0 for n in ni[0:i0+1]): RPi[i0] = ER0 else: RPi[i0] += Rgens[i0] diff --git a/src/sage/schemes/elliptic_curves/ell_wp.py b/src/sage/schemes/elliptic_curves/ell_wp.py index 820b9050a22..462899d33f2 100644 --- a/src/sage/schemes/elliptic_curves/ell_wp.py +++ b/src/sage/schemes/elliptic_curves/ell_wp.py @@ -142,7 +142,7 @@ def weierstrass_p(E, prec=20, algorithm=None): if algorithm == "pari": if 0 < p <= prec + 2: - raise ValueError("for computing the Weierstrass p-function via pari, the characteristic (%s) of the underlying field must be greater than prec + 2 = %s"%(p,prec+2)) + raise ValueError("for computing the Weierstrass p-function via pari, the characteristic (%s) of the underlying field must be greater than prec + 2 = %s" % (p,prec+2)) return compute_wp_pari(E, prec) # quadratic and fast algorithms require short Weierstrass model @@ -153,11 +153,11 @@ def weierstrass_p(E, prec=20, algorithm=None): if algorithm == "quadratic": if 0 < p <= prec + 2: - raise ValueError("for computing the Weierstrass p-function via the quadratic algorithm, the characteristic (%s) of the underlying field must be greater than prec + 2 = %s"%(p,prec+2)) + raise ValueError("for computing the Weierstrass p-function via the quadratic algorithm, the characteristic (%s) of the underlying field must be greater than prec + 2 = %s" % (p,prec+2)) wp = compute_wp_quadratic(k, A, B, prec) elif algorithm == "fast": if 0 < p <= prec + 4: - raise ValueError("for computing the Weierstrass p-function via the fast algorithm, the characteristic (%s) of the underlying field must be greater than prec + 4 = %s"%(p,prec+4)) + raise ValueError("for computing the Weierstrass p-function via the fast algorithm, the characteristic (%s) of the underlying field must be greater than prec + 4 = %s" % (p,prec+4)) wp = compute_wp_fast(k, A, B, prec) else: raise ValueError("unknown algorithm for computing the Weierstrass p-function") @@ -341,14 +341,12 @@ def solve_linear_differential_system(a, b, c, alpha): sage: f(0) == alpha # optional - sage.rings.finite_rings True """ - a_recip = 1/a - B = b * a_recip - C = c * a_recip + a_recip = 1 / a + B = b * a_recip + C = c * a_recip int_B = B.integral() J = int_B.exp() - J_recip = 1/J + J_recip = 1 / J CJ = C * J int_CJ = CJ.integral() - f = J_recip * (alpha + int_CJ) - - return f + return J_recip * (alpha + int_CJ) diff --git a/src/sage/schemes/elliptic_curves/formal_group.py b/src/sage/schemes/elliptic_curves/formal_group.py index 3bf8ae2474f..7949eb94bcf 100644 --- a/src/sage/schemes/elliptic_curves/formal_group.py +++ b/src/sage/schemes/elliptic_curves/formal_group.py @@ -551,7 +551,7 @@ def group_law(self, prec=10): # note that the following formula differs from the one in Silverman page 119. # See github issue 9646 for the explanation and justification. t3 = -t1 - t2 - \ - (a1*lam + a3*lam2 + a2*nu + 2*a4*lam*nu + 3*a6*lam2*nu)/ \ + (a1*lam + a3*lam2 + a2*nu + 2*a4*lam*nu + 3*a6*lam2*nu) / \ (1 + a2*lam + a4*lam2 + a6*lam3) inv = self.inverse(prec) diff --git a/src/sage/schemes/elliptic_curves/gal_reps.py b/src/sage/schemes/elliptic_curves/gal_reps.py index ca9a3e1753c..1b8d2ad64fd 100644 --- a/src/sage/schemes/elliptic_curves/gal_reps.py +++ b/src/sage/schemes/elliptic_curves/gal_reps.py @@ -352,7 +352,7 @@ def reducible_primes(self): if j in sporadic_j: # includes all CM j-invariants R = [sporadic_j[j]] else: - R = [l for l in [2,3,5,7,13] if len(E.isogenies_prime_degree(l))>0] + R = [l for l in [2,3,5,7,13] if len(E.isogenies_prime_degree(l)) > 0] self.__reducible_primes = R return R @@ -462,9 +462,9 @@ def _is_surjective(self, p, A): sage: rho._is_surjective(5,1000) """ T = self._E.torsion_subgroup().order() - if T % p == 0 and p != 2 : + if T % p == 0 and p != 2: # we could probably determine the group structure directly - self.__image_type[p] = "The image is meta-cyclic inside a Borel subgroup as there is a %s-torsion point on the curve."%p + self.__image_type[p] = "The image is meta-cyclic inside a Borel subgroup as there is a %s-torsion point on the curve." % p return False R = rings.PolynomialRing(self._E.base_ring(), 'x') @@ -472,7 +472,7 @@ def _is_surjective(self, p, A): if p == 2: # E is isomorphic to [0,b2,0,8*b4,16*b6] - b2,b4,b6,b8=self._E.b_invariants() + b2,b4,b6,b8 = self._E.b_invariants() f = x**3 + b2*x**2 + 8*b4*x + 16*b6 if not f.is_irreducible(): if len(f.roots()) > 2: @@ -578,7 +578,7 @@ def _is_surjective(self, p, A): if s != 0 and s not in signs: signs.append(s) if len(signs) == 2 and exclude_exceptional_image: - self.__image_type[p] = "The image is all of GL_2(F_%s)."%p + self.__image_type[p] = "The image is all of GL_2(F_%s)." % p return True #,None if A == -1: # we came in from is reducible. Now go out with False @@ -675,19 +675,19 @@ def non_surjective(self, A=1000): p0 = arith.next_prime(p0+1) C2 = (sqrt(p0)+1)**8 C = max(C1,C2) - verbose("j is not integral -- Serre's bound is %s"%C) + verbose("j is not integral -- Serre's bound is %s" % C) C3 = 1 + 4*sqrt(6)*int(N)/3 * sqrt(misc.mul([1+1.0/int(p) for p,_ in arith.factor(N)])) C = min(C,C3) - verbose("conductor = %s, and bound is %s"%(N,C)) + verbose("conductor = %s, and bound is %s" % (N,C)) else: # Cojocaru's bound (depends on the conductor) C = 1 + 4*sqrt(6)*int(N)/3 * sqrt(misc.mul([1+1.0/int(p) for p,_ in arith.factor(N)])) - verbose("conductor = %s, and bound is %s"%(N,C)) + verbose("conductor = %s, and bound is %s" % (N,C)) B = [] p = 2 while p <= C: t = self.is_surjective(p, A=A) - verbose("(%s,%s)"%(p,t)) + verbose("(%s,%s)" % (p,t)) # both False and None will be appended here. if not t: B.append(p) @@ -833,7 +833,7 @@ def image_type(self, p): # check if the rep is reducible if self.is_reducible(p): - self.__image_type[p] = "The image is contained in a Borel subgroup as there is a %s-isogeny."%p + self.__image_type[p] = "The image is contained in a Borel subgroup as there is a %s-isogeny." % p return self.__image_type[p] # if we are then the image of rho is not surjective and not contained in a Borel subgroup @@ -843,10 +843,10 @@ def image_type(self, p): # or the image in PGL_2 is one of the three exceptional groups A_4 S_4 A_5 non_split_str = "The image is contained in the normalizer of a non-split Cartan group." - split_str = "The image is contained in the normalizer of a split Cartan group." - s4_str = "The image in PGL_2(F_%s) is the exceptional group S_4."%p - a4_str = "The image in PGL_2(F_%s) is the exceptional group A_4."%p - a5_str = "The image in PGL_2(F_%s) is the exceptional group A_5."%p + split_str = "The image is contained in the normalizer of a split Cartan group." + s4_str = "The image in PGL_2(F_%s) is the exceptional group S_4." % p + a4_str = "The image in PGL_2(F_%s) is the exceptional group A_4." % p + a5_str = "The image in PGL_2(F_%s) is the exceptional group A_5." % p # we first treat p=3 and 5 separately. p=2 has already been done. @@ -989,25 +989,25 @@ def image_type(self, p): u = k(a_ell)**2 * k(ell)**(-1) if (u not in ex_setp) and could_be_exc == 1: # it can not be in the exceptional - verbose("the image cannot be exceptional, found u=%s"%u, level=2) + verbose("the image cannot be exceptional, found u=%s" % u, level=2) could_be_exc = 0 if a_ell != 0 and arith.kronecker(a_ell**2 - 4*ell,p) == 1 and could_be_non_split == 1: # it can not be in the normalizer of the non-split Cartan - verbose("the image cannot be non-split, found u=%s"%u, level=2) + verbose("the image cannot be non-split, found u=%s" % u, level=2) could_be_non_split = 0 if a_ell != 0 and arith.kronecker(a_ell**2 - 4*ell,p) == -1 and could_be_split == 1: # it can not be in the normalizer of the split Cartan - verbose("the image cannot be split, found u=%s"%u, level=2) + verbose("the image cannot be split, found u=%s" % u, level=2) could_be_split = 0 assert could_be_exc + could_be_split + could_be_non_split > 0, "bug in image_type." if could_be_exc + could_be_split + could_be_non_split == 1: # it is only one of the three cases: - if could_be_split == 1 : + if could_be_split == 1: self.__image_type[p] = split_str return self.__image_type[p] - if could_be_non_split == 1 : + if could_be_non_split == 1: self.__image_type[p] = non_split_str return self.__image_type[p] if could_be_exc == 1: @@ -1015,7 +1015,7 @@ def image_type(self, p): could_be_a4 = 1 could_be_s4 = 1 could_be_a5 = 1 - if p % 5 != 1 and p % 5 != 4 : + if p % 5 != 1 and p % 5 != 4: could_be_a5 = 0 # elements of order 5 # bug corrected see trac 14577 R = k['X'] @@ -1031,7 +1031,7 @@ def image_type(self, p): # it can not be A4 not A5 as they have no elements of order 4 could_be_a4 = 0 could_be_a5 = 0 - if u in el5 : + if u in el5: # it can not be A4 or S4 as they have no elements of order 5 could_be_a4 = 0 could_be_s4 = 0 @@ -1050,7 +1050,7 @@ def image_type(self, p): return self.__image_type[p] else: - self.__image_type[p] = "The image in PGL_2(F_%s) is an exceptional group A_4, S_4 or A_5, but we could not determine which one."%p + self.__image_type[p] = "The image in PGL_2(F_%s) is an exceptional group A_4, S_4 or A_5, but we could not determine which one." % p return self.__image_type[p] # If all fails, we probably have a fairly small group and we can try to detect it using the galois_group @@ -1058,7 +1058,7 @@ def image_type(self, p): K = self._E.division_field(p, 'z') d = K.absolute_degree() - verbose("field of degree %s. try to compute Galois group"%(d), level=2) + verbose("field of degree %s. try to compute Galois group" % (d), level=2) # If the degree is too big, we have no chance at the Galois # group. K.galois_group calls is_galois which used to rely on # pari's Galois group computations, so degree < 12 @@ -1067,7 +1067,7 @@ def image_type(self, p): raise Exception() G = K.galois_group() except Exception: - self.__image_type[p] = "The image is a group of order %s."%d + self.__image_type[p] = "The image is a group of order %s." % d return self.__image_type[p] else: @@ -1075,7 +1075,7 @@ def image_type(self, p): ab = "" else: ab = "non-" - self.__image_type[p] = "The image is a " + ab + "abelian group of order %s."%G.order() + self.__image_type[p] = "The image is a " + ab + "abelian group of order %s." % G.order() return self.__image_type[p] ## everything failed : diff --git a/src/sage/schemes/elliptic_curves/gal_reps_number_field.py b/src/sage/schemes/elliptic_curves/gal_reps_number_field.py index c9dc54d2668..10b92bc9978 100644 --- a/src/sage/schemes/elliptic_curves/gal_reps_number_field.py +++ b/src/sage/schemes/elliptic_curves/gal_reps_number_field.py @@ -542,7 +542,7 @@ def Frobenius_filter(E, L, patience=100): L.remove(2) include_2 = not E.division_polynomial(2).is_irreducible() - K_is_Q = (K==QQ) + K_is_Q = (K == QQ) from sage.arith.misc import primes from sage.rings.infinity import infinity @@ -557,7 +557,7 @@ def primes_iter(): yield P numP = 0 for P in primes_iter(): - if not L or numP==patience: # stop if no primes are left, or patience is exhausted + if not L or numP == patience: # stop if no primes are left, or patience is exhausted break numP += 1 @@ -798,7 +798,7 @@ def deg_one_primes_iter(K, principal_only=False): # imaginary quadratic fields have no principal primes of norm < disc / 4 start = K.discriminant().abs() // 4 if principal_only and K.signature() == (0,1) else 2 - K_is_Q = (K==QQ) + K_is_Q = (K == QQ) for p in primes(start=start, stop=Infinity): if K_is_Q: @@ -859,23 +859,23 @@ def _semistable_reducible_primes(E, verbose=False): while len(precomp) < 2: P = next(deg_one_primes) p = P.norm() - if p != last_p and (d==1 or P.ramification_index() == 1) and E.has_good_reduction(P): + if p != last_p and (d == 1 or P.ramification_index() == 1) and E.has_good_reduction(P): precomp.append(P) last_p = p Px, Py = precomp x, y = [PP.gens_reduced()[0] for PP in precomp] - EmodPx = E.reduction(Px) if d>1 else E.reduction(x) - EmodPy = E.reduction(Py) if d>1 else E.reduction(y) + EmodPx = E.reduction(Px) if d > 1 else E.reduction(x) + EmodPy = E.reduction(Py) if d > 1 else E.reduction(y) fxpol = EmodPx.frobenius_polynomial() fypol = EmodPy.frobenius_polynomial() fx12pol = fxpol.adams_operator(12) # roots are 12th powers of those of fxpol fy12pol = fypol.adams_operator(12) - px = x.norm() if d>1 else x - py = y.norm() if d>1 else x + px = x.norm() if d > 1 else x + py = y.norm() if d > 1 else x Zx = fxpol.parent() - xpol = x.charpoly() if d>1 else Zx([-x,1]) - ypol = y.charpoly() if d>1 else Zx([-y,1]) + xpol = x.charpoly() if d > 1 else Zx([-x,1]) + ypol = y.charpoly() if d > 1 else Zx([-y,1]) if verbose: print("Finished precomp, x={} (p={}), y={} (p={})".format(x,px,y,py)) @@ -938,7 +938,7 @@ def _semistable_reducible_primes(E, verbose=False): # has CM and computing the set of CM j-invariants of K to check. # TODO: Is this the best value for this parameter? - while div==0 and patience>0: + while div == 0 and patience > 0: P = next(deg_one_primes) # a prime of K not K_rel while E.has_bad_reduction(P): P = next(deg_one_primes) @@ -954,7 +954,7 @@ def _semistable_reducible_primes(E, verbose=False): div2 = Integer(xpol.resultant(fpol.adams_operator(12)) // x.norm()**12) if div2: div = div2.isqrt() - assert div2==div**2 + assert div2 == div**2 if verbose: print("...div = {}".format(div)) else: @@ -1324,7 +1324,7 @@ def remove_primes(B): B1 = B1.prime_to_m_part(p) return B1 ll = primes(5,max_l) # iterator - while B!=1 and len(ells)= 2: print(cmd) - s = gp.eval('ans=%s;'%cmd) + s = gp.eval('ans=%s;' % cmd) if s.find(" *** ") != -1: - raise RuntimeError("\n%s\nAn error occurred while running Simon's 2-descent program"%s) + raise RuntimeError("\n%s\nAn error occurred while running Simon's 2-descent program" % s) if verbose > 0: print(s) v = gp.eval('ans') - if v=='ans': # then the call to ellQ_ellrank() or bnfellrank() failed + if v == 'ans': # then the call to ellQ_ellrank() or bnfellrank() failed raise RuntimeError("An error occurred while running Simon's 2-descent program") if verbose >= 2: print("v = %s" % v) diff --git a/src/sage/schemes/elliptic_curves/heegner.py b/src/sage/schemes/elliptic_curves/heegner.py index d8ba886fe2c..71e620c643a 100644 --- a/src/sage/schemes/elliptic_curves/heegner.py +++ b/src/sage/schemes/elliptic_curves/heegner.py @@ -521,7 +521,7 @@ def quadratic_field(self): with sqrt_minus_7 = 2.645751311064591?*I """ D = self.__D - var = 'sqrt_minus_%s'%(-D) + var = 'sqrt_minus_%s' % (-D) return number_field.QuadraticField(D,var) @cached_method @@ -743,10 +743,10 @@ def _repr_(self): 'Galois group of Ring class field extension of QQ[sqrt(-7)] of conductor 5' """ if self.base_field() != QQ: - s = " over %s"%self.base_field() + s = " over %s" % self.base_field() else: s = '' - return "Galois group of %s%s"%(self.field(), s) + return "Galois group of %s%s" % (self.field(), s) def field(self): """ @@ -1060,7 +1060,7 @@ def _alpha_to_p1_element(self, alpha): n = gcd(w) w /= n c = P1.N() - w = P1.normalize(ZZ(w[0])%c, ZZ(w[1])%c) + w = P1.normalize(ZZ(w[0]) % c, ZZ(w[1]) % c) if w == (0,0): w = (1,0) return w @@ -1390,7 +1390,7 @@ def _repr_(self): sage: conj._repr_() 'Complex conjugation automorphism of Ring class field extension of QQ[sqrt(-7)] of conductor 5' """ - return "Complex conjugation automorphism of %s"%self.domain() + return "Complex conjugation automorphism of %s" % self.domain() ## def __mul__(self, right): ## """ @@ -1616,7 +1616,7 @@ def _repr_(self): sage: s._repr_() 'Class field automorphism defined by x^2 + 45*y^2' """ - return "Class field automorphism defined by %s"%self.__quadratic_form + return "Class field automorphism defined by %s" % self.__quadratic_form def __mul__(self, right): """ @@ -1684,7 +1684,7 @@ def ideal(self): c = M.conductor() sqrtD = K.gen() (A,B,C) = f - if A%c == 0: + if A % c == 0: A, C = C, A return K.fractional_ideal([A, (-B+c*sqrtD)/2]) @@ -1807,7 +1807,7 @@ def _repr_(self): sage: H._repr_() 'Heegner point of level 389, discriminant -7, and conductor 5' """ - return "Heegner point of level %s, discriminant %s, and conductor %s"%( + return "Heegner point of level %s, discriminant %s, and conductor %s" % ( self.__N, self.__D, self.__c) def __hash__(self): @@ -2051,7 +2051,7 @@ def _repr_(self): sage: heegner_points(389)._repr_() 'Set of all Heegner points on X_0(389)' """ - return "Set of all Heegner points on X_0(%s)"%self.level() + return "Set of all Heegner points on X_0(%s)" % self.level() def reduce_mod(self, ell): r""" @@ -2155,7 +2155,7 @@ def __init__(self, N, D): HeegnerPoints.__init__(self, N) D = ZZ(D) if not satisfies_weak_heegner_hypothesis(N,D): - raise ValueError("D (=%s) must satisfy the weak Heegner hypothesis for N (=%s)"%(D,N)) + raise ValueError("D (=%s) must satisfy the weak Heegner hypothesis for N (=%s)" % (D,N)) self.__D = D def __eq__(self, other): @@ -2197,7 +2197,7 @@ def _repr_(self): sage: heegner_points(389,-7)._repr_() 'Set of all Heegner points on X_0(389) associated to QQ[sqrt(-7)]' """ - return "Set of all Heegner points on X_0(%s) associated to QQ[sqrt(%s)]"%( + return "Set of all Heegner points on X_0(%s) associated to QQ[sqrt(%s)]" % ( self.level(), self.discriminant()) def discriminant(self): @@ -2224,7 +2224,7 @@ def quadratic_field(self): with sqrt_minus_7 = 2.645751311064591?*I """ D = self.__D - var = 'sqrt_minus_%s'%(-D) + var = 'sqrt_minus_%s' % (-D) return number_field.QuadraticField(D,var) def kolyvagin_conductors(self, r=None, n=10, E=None, m=None): @@ -2448,7 +2448,7 @@ def _repr_(self): sage: H = heegner_points(37,-7,5); H._repr_() 'All Heegner points of conductor 5 on X_0(37) associated to QQ[sqrt(-7)]' """ - return "All Heegner points of conductor %s on X_0(%s) associated to QQ[sqrt(%s)]"%( + return "All Heegner points of conductor %s on X_0(%s) associated to QQ[sqrt(%s)]" % ( self.conductor(), self.level(), self.discriminant()) def conductor(self): @@ -2563,7 +2563,7 @@ def betas(self): N = self.level() R = Integers(4*N) m = 2*N - return tuple(sorted( set([a%m for a in R(D).sqrt(all=True)]) )) + return tuple(sorted( set([a % m for a in R(D).sqrt(all=True)]) )) @cached_method def points(self, beta=None): @@ -2721,7 +2721,7 @@ def __init__(self, N, D, c=ZZ(1), f=None, check=True): if c.gcd(N) != 1: raise ValueError("conductor c (=%s) must be coprime to N (=%s)" % (c, N)) if not satisfies_weak_heegner_hypothesis(N, D): - raise ValueError("N (=%s) and D (=%s) must satisfy the Heegner hypothesis"%(N, D)) + raise ValueError("N (=%s) and D (=%s) must satisfy the Heegner hypothesis" % (N, D)) if f is not None: if isinstance(f, tuple): if len(f) != 3: @@ -2741,7 +2741,7 @@ def __init__(self, N, D, c=ZZ(1), f=None, check=True): raise TypeError("f must be a 3-tuple, quadratic form, or element of the upper half plane") A, B, C = f if B*B - 4*A*C != D*c*c: - raise ValueError("f (=%s) must have discriminant %s"%(f, D*c*c)) + raise ValueError("f (=%s) must have discriminant %s" % (f, D*c*c)) HeegnerPoint.__init__(self, N, D, c) if f is None: # We know that N|A, so A = N is optimal. @@ -2797,11 +2797,11 @@ def _repr_(self): 'Heegner point 5/74*sqrt(-7) - 11/74 of discriminant -7 and conductor 5 on X_0(37)' """ c = self.conductor() - s = " and conductor %s"%c if c != 1 else "" + s = " and conductor %s" % c if c != 1 else "" N = self.level() D = self.discriminant() - tau = repr(self.tau()).replace('sqrt_minus_%s'%(-D),'sqrt(%s)'%D) - return "Heegner point %s of discriminant %s%s on X_0(%s)"%(tau, D, s, N) + tau = repr(self.tau()).replace('sqrt_minus_%s' % (-D),'sqrt(%s)' % D) + return "Heegner point %s of discriminant %s%s on X_0(%s)" % (tau, D, s, N) def atkin_lehner_act(self, Q=None): r""" @@ -3114,9 +3114,9 @@ def _repr_(self): sage: P._repr_() 'Heegner point of discriminant -7 and conductor 97 on elliptic curve of conductor 389' """ - s = " and conductor %s"%self.conductor() if self.conductor() != 1 else "" + s = " and conductor %s" % self.conductor() if self.conductor() != 1 else "" N = self.__E.conductor() - return "Heegner point of discriminant %s%s on elliptic curve of conductor %s"%(self.discriminant(), s, N) + return "Heegner point of discriminant %s%s on elliptic curve of conductor %s" % (self.discriminant(), s, N) def heegner_point_on_X0N(self): r""" @@ -3771,7 +3771,7 @@ def _square_roots_mod_2N_of_D_mod_4N(self): N = self.__E.conductor() R = Integers(4*N) m = 2*N - return sorted( set([a%m for a in R(self.discriminant()).sqrt(all=True)]) ) + return sorted( set([a % m for a in R(self.discriminant()).sqrt(all=True)]) ) def _trace_numerical_conductor_1(self, prec=53): """ @@ -3862,7 +3862,7 @@ def _good_tau_representatives(self): s = s.lift() f = (a*N, b+2*N*s, ZZ( ((b + 2*N*s)**2 - D)/(4*a*N)) ) for d in divs: - Q = d * prod(p**k for p,k in N.factor() if (b-beta)%(p**k)!=0) + Q = d * prod(p**k for p,k in N.factor() if (b-beta) % (p**k) != 0) g = self._qf_atkin_lehner_act(Q, f) gbar = (ZZ(g[0]/N), -g[1], g[2]*N) g = self._qf_reduce(g) @@ -4529,7 +4529,7 @@ def __init__(self, kolyvagin_point, n): n = gcd([(p+1).gcd(E.ap(p)) for p in c.prime_divisors()]) if not kolyvagin_point.satisfies_kolyvagin_hypothesis(n): - raise ValueError("Kolyvagin point does not satisfy Kolyvagin hypothesis for %s"%n) + raise ValueError("Kolyvagin point does not satisfy Kolyvagin hypothesis for %s" % n) self.__kolyvagin_point = kolyvagin_point self.__n = n @@ -4641,7 +4641,7 @@ def _repr_(self): sage: t._repr_() 'Kolyvagin cohomology class c(5) in H^1(K,E[2])' """ - return "Kolyvagin cohomology class c(%s) in H^1(K,E[%s])"%( + return "Kolyvagin cohomology class c(%s) in H^1(K,E[%s])" % ( self.conductor(), self.n()) @@ -4729,7 +4729,7 @@ def _repr_(self): sage: heegner_points(11).reduce_mod(13)._repr_() 'Heegner points on X_0(11) over F_13' """ - return "Heegner points on X_0(%s) over F_%s"%( + return "Heegner points on X_0(%s) over F_%s" % ( self.__level, self.__ell) def level(self): @@ -5002,7 +5002,7 @@ def heegner_divisor(self, D, c=ZZ(1)): if a > 0: reps = Q.representation_vector_list(n+1)[-1] k = len([r for r in reps if gcd(r) == 1]) - assert k%2 == 0 + assert k % 2 == 0 v[i] += k // 2 return B(v) @@ -5072,12 +5072,12 @@ def modp_splitting_data(self, p): """ p = ZZ(p) if not p.is_prime(): - raise ValueError("p (=%s) must be prime"%p) + raise ValueError("p (=%s) must be prime" % p) if p == 2: raise ValueError("p must be odd") Q = self.quaternion_algebra() if Q.discriminant() % p == 0: - raise ValueError("p (=%s) must be an unramified prime"%p) + raise ValueError("p (=%s) must be an unramified prime" % p) i, j, k = Q.gens() F = GF(p) i2 = F(i*i) @@ -5181,7 +5181,7 @@ def cyclic_subideal_p1(self, I, c): V = V.intersection(phi(B[i]).kernel()) b = V.basis() assert len(b) == 1, "common kernel must have dimension 1" - uv = P1.normalize(ZZ(b[0][0])%c, ZZ(b[0][1])%c) + uv = P1.normalize(ZZ(b[0][0]) % c, ZZ(b[0][1]) % c) ans[uv] = J assert len(ans) == c+1 return ans @@ -5555,7 +5555,7 @@ def modp_dual_elliptic_curve_factor(self, E, p, bound=10): raise ValueError("conductor of E must equal level of self") p = ZZ(p) if not p.is_prime(): - raise ValueError("p (=%s) must be prime"%p) + raise ValueError("p (=%s) must be prime" % p) bad = self.__level * self.__ell V = None @@ -5563,7 +5563,7 @@ def modp_dual_elliptic_curve_factor(self, E, p, bound=10): B = self.brandt_module() F = GF(p) while q <= bound and (V is None or V.dimension() > 2): - verbose("q = %s"%q) + verbose("q = %s" % q) if bad % q != 0: T = B._compute_hecke_matrix_directly(q).change_ring(F).transpose() if V is None: @@ -6075,8 +6075,8 @@ def _repr_(self): sage: f = H.optimal_embeddings(-7, 2, R)[1]; f._repr_() 'Embedding sending 2*sqrt(-7) to -5*i + k' """ - a = '%ssqrt(%s)'%('%s*'%self.__c if self.__c > 1 else '', self.__D) - return "Embedding sending %s to %s"%(a, self.__beta) + a = '%ssqrt(%s)' % ('%s*' % self.__c if self.__c > 1 else '', self.__D) + return "Embedding sending %s to %s" % (a, self.__beta) def conjugate(self): """ @@ -6580,13 +6580,13 @@ def heegner_point_height(self, D, prec=2, check_rank=True): """ if not self.satisfies_heegner_hypothesis(D): - raise ArithmeticError("Discriminant (=%s) must be a fundamental discriminant that satisfies the Heegner hypothesis."%D) + raise ArithmeticError("Discriminant (=%s) must be a fundamental discriminant that satisfies the Heegner hypothesis." % D) if check_rank and self.rank() >= 2: return ZZ(0) if D == -3 or D == -4: - raise ArithmeticError("Discriminant (=%s) must not be -3 or -4."%D) + raise ArithmeticError("Discriminant (=%s) must not be -3 or -4." % D) eps = self.root_number() L1_vanishes = self.lseries().L1_vanishes() @@ -6736,7 +6736,7 @@ def heegner_index(self, D, min_p=2, prec=5, descent_second_limit=12, True """ if not self.satisfies_heegner_hypothesis(D): - raise ArithmeticError("Discriminant (=%s) must be a fundamental discriminant that satisfies the Heegner hypothesis."%D) + raise ArithmeticError("Discriminant (=%s) must be a fundamental discriminant that satisfies the Heegner hypothesis." % D) if check_rank and self.rank() >= 2: return rings.infinity @@ -6751,7 +6751,7 @@ def heegner_index(self, D, min_p=2, prec=5, descent_second_limit=12, # Heegner point on the twist. ht = h0/2 - verbose('Height of heegner point = %s'%ht, tm) + verbose('Height of heegner point = %s' % ht, tm) if self.root_number() == 1: F = self.quadratic_twist(D) @@ -6759,11 +6759,11 @@ def heegner_index(self, D, min_p=2, prec=5, descent_second_limit=12, F = self # Now rank(F) > 0 h = ht.upper() - verbose("Heegner height bound = %s"%h) + verbose("Heegner height bound = %s" % h) B = F.CPS_height_bound() - verbose("CPS bound = %s"%B) + verbose("CPS bound = %s" % B) c = h/(min_p**2) + B - verbose("Search would have to be up to height = %s"%c) + verbose("Search would have to be up to height = %s" % c) from .ell_rational_field import _MAX_HEIGHT @@ -6780,7 +6780,7 @@ def heegner_index(self, D, min_p=2, prec=5, descent_second_limit=12, if z.is_divisible_by(2): a = 2 else: - FK_even_tor_pts = [T for T in FK.torsion_subgroup().gens() if T.order()%2==0] + FK_even_tor_pts = [T for T in FK.torsion_subgroup().gens() if T.order() % 2 == 0] if len(FK_even_tor_pts) == 2: FK_even_tor_pts.append(sum(FK_even_tor_pts)) for T in FK_even_tor_pts: @@ -6805,7 +6805,7 @@ def heegner_index(self, D, min_p=2, prec=5, descent_second_limit=12, if z.is_divisible_by(2): a = 2 else: - FK_even_tor_pts = [T for T in FK.torsion_subgroup().gens() if T.order()%2==0] + FK_even_tor_pts = [T for T in FK.torsion_subgroup().gens() if T.order() % 2 == 0] if len(FK_even_tor_pts) == 2: FK_even_tor_pts.append(sum(FK_even_tor_pts)) for T in FK_even_tor_pts: @@ -6905,9 +6905,9 @@ def heegner_index_bound(self, D=0, prec=5, max_height=None): return 0, D, False F = self.quadratic_twist(D) h = ht.upper() - verbose("Heegner height bound = %s"%h) + verbose("Heegner height bound = %s" % h) B = F.CPS_height_bound() - verbose("CPS bound = %s"%B) + verbose("CPS bound = %s" % B) if self.two_torsion_rank() == 0: H = h else: @@ -6921,13 +6921,13 @@ def heegner_index_bound(self, D=0, prec=5, max_height=None): if p > 100: break p = next_prime(p) - verbose("Using p = %s"%p) + verbose("Using p = %s" % p) if c > max_height: - verbose("No information by searching only up to max_height (=%s)."%c) + verbose("No information by searching only up to max_height (=%s)." % c) return -1, D, False - verbose("Searching up to height = %s"%c) + verbose("Searching up to height = %s" % c) eps = 10e-5 def _bound(P): @@ -6942,15 +6942,15 @@ def _bound(P): IR = rings.RealIntervalField(20) # todo: 20? h = IR(reg-eps,reg+eps) ind2 = ht/(h/2) - verbose("index squared = %s"%ind2) + verbose("index squared = %s" % ind2) ind = ind2.sqrt() - verbose("index = %s"%ind) + verbose("index = %s" % ind) # Compute upper bound on square root of index. if ind.absolute_diameter() < 1: t, i = ind.is_int() if t: # unique integer in interval, so we've found exact index squared. return prime_divisors(i), D, i - raise RuntimeError("Unable to compute bound for e=%s, D=%s (try increasing precision)"%(self, D)) + raise RuntimeError("Unable to compute bound for e=%s, D=%s (try increasing precision)" % (self, D)) # First try a quick search, in case we get lucky and find # a generator. @@ -7004,7 +7004,7 @@ def _heegner_index_in_EK(self, D): """ # check conditions, then use cache if possible. if not self.satisfies_heegner_hypothesis(D): - raise ValueError("D (=%s) must satisfy the Heegner hypothesis"%D) + raise ValueError("D (=%s) must satisfy the Heegner hypothesis" % D) try: return self.__heegner_index_in_EK[D] except AttributeError: @@ -7151,7 +7151,7 @@ def heegner_sha_an(self, D, prec=53): """ # check conditions, then return from cache if possible. if not self.satisfies_heegner_hypothesis(D): - raise ValueError("D (=%s) must satisfy the Heegner hypothesis"%D) + raise ValueError("D (=%s) must satisfy the Heegner hypothesis" % D) try: return self.__heegner_sha_an[(D, prec)] except AttributeError: diff --git a/src/sage/schemes/elliptic_curves/height.py b/src/sage/schemes/elliptic_curves/height.py index e9eb837d30e..318aa85caa0 100644 --- a/src/sage/schemes/elliptic_curves/height.py +++ b/src/sage/schemes/elliptic_curves/height.py @@ -511,7 +511,7 @@ def nonneg_region(f): () """ roots = sorted(f.roots()) - sign_changes = [r for r,e in roots if e%2 == 1] + sign_changes = [r for r,e in roots if e % 2 == 1] if (f.leading_coefficient() * (-1)**f.degree()) > 0: sign_changes = [-infinity] + sign_changes if f.leading_coefficient() > 0: @@ -552,15 +552,16 @@ def inf_max_abs(f, g, D): sage: max(abs(f(r0)), abs(g(r0))) 425.638201706391 """ - xs = f.roots() + f.derivative().roots() + xs = f.roots() + f.derivative().roots() xs += g.roots() + g.derivative().roots() - xs += (f-g).roots() + (f+g).roots() - xs = [r for r,e in xs if r in D] # ignore multiplicities and points outside D + xs += (f - g).roots() + (f + g).roots() + xs = [r for r, _ in xs if r in D] # ignore multiplicities and points outside D xs += D.finite_endpoints() # include endpoints of intervals if xs: - return min([max(abs(f(r)), abs(g(r))) for r in xs]) + return min(max(abs(f(r)), abs(g(r))) for r in xs) return infinity + def min_on_disk(f, tol, max_iter=10000): r""" Returns the minimum of a real-valued complex function on a square. diff --git a/src/sage/schemes/elliptic_curves/hom_composite.py b/src/sage/schemes/elliptic_curves/hom_composite.py index a117e2e87d0..b449fe77e41 100644 --- a/src/sage/schemes/elliptic_curves/hom_composite.py +++ b/src/sage/schemes/elliptic_curves/hom_composite.py @@ -474,7 +474,7 @@ def _repr_(self): from itertools import groupby degs = [phi.degree() for phi in self._phis] grouped = [(d, sum(1 for _ in g)) for d,g in groupby(degs)] - degs_str = '*'.join(str(d) + (f'^{e}' if e>1 else '') for d,e in grouped) + degs_str = '*'.join(str(d) + (f'^{e}' if e > 1 else '') for d,e in grouped) return f'Composite morphism of degree {self._degree} = {degs_str}:' \ f'\n From: {self._domain}' \ f'\n To: {self._codomain}' diff --git a/src/sage/schemes/elliptic_curves/hom_velusqrt.py b/src/sage/schemes/elliptic_curves/hom_velusqrt.py index 15863173c4f..b60e551d876 100644 --- a/src/sage/schemes/elliptic_curves/hom_velusqrt.py +++ b/src/sage/schemes/elliptic_curves/hom_velusqrt.py @@ -455,7 +455,7 @@ def _hI_resultant(self, poly, rems=None): if rems is None: rems = self.hItree.remainders(poly) r = prod(rems) - s = -1 if len(self.hItree)%2 == 1 == poly.degree() else 1 + s = -1 if len(self.hItree) % 2 == 1 == poly.degree() else 1 assert r.is_constant() return s * r[0] diff --git a/src/sage/schemes/elliptic_curves/isogeny_class.py b/src/sage/schemes/elliptic_curves/isogeny_class.py index 43495d65293..1588ecbe814 100644 --- a/src/sage/schemes/elliptic_curves/isogeny_class.py +++ b/src/sage/schemes/elliptic_curves/isogeny_class.py @@ -227,9 +227,9 @@ def _repr_(self): Elliptic Curve defined by y^2 + (i+1)*x*y + (i+1)*y = x^3 + i*x^2 + (-i+33)*x + (-58*i) over Number Field in i with defining polynomial x^2 + 1 with i = 1*I] """ if self._label: - return "Elliptic curve isogeny class %s"%(self._label) + return "Elliptic curve isogeny class %s" % (self._label) else: - return "Isogeny class of %r"%(self.E) + return "Isogeny class of %r" % (self.E) def __contains__(self, x): """ @@ -853,9 +853,9 @@ def add_tup(t): js = [j for j,E3 in enumerate(curves) if E2.is_isomorphic(E3)] if js: # seen codomain already -- up to isomorphism j = js[0] - if phi.codomain()!=curves[j]: + if phi.codomain() != curves[j]: phi = E2.isomorphism_to(curves[j]) * phi - assert phi.domain()==curves[i] and phi.codomain()==curves[j] + assert phi.domain() == curves[i] and phi.codomain() == curves[j] add_tup([i,j,d,phi]) else: curves.append(E2) @@ -885,7 +885,7 @@ def add_tup(t): mat = MatrixSpace(ZZ, ncurves)(0) self._maps = [[0] * ncurves for _ in range(ncurves)] for i,j,l,phi in tuples: - if phi!=0: + if phi != 0: mat[perm[i],perm[j]] = l self._maps[perm[i]][perm[j]] = phi self._mat = fill_isogeny_matrix(mat) @@ -932,16 +932,16 @@ def find_quadratic_form(d, n): for Q in allQs[d]: if Q.solve_integer(n): return Q - raise ValueError("No form of discriminant %d represents %s" %(d,n)) + raise ValueError("No form of discriminant %d represents %s" % (d,n)) mat = self._mat qfmat = [[0 for i in range(ncurves)] for j in range(ncurves)] for i, E1 in enumerate(self.curves): for j, E2 in enumerate(self.curves): - if j1]) + L1 = Set([l for l in ram_l if d.valuation(l) > 1]) L += L1 if verbose: print("upward primes: %s" % L1) @@ -1269,7 +1269,7 @@ def isogeny_degrees_cm(E, verbose=False): # l-1 must divide n/2h: L1 = Set([lm1+1 for lm1 in divs - if (lm1+1).is_prime() and kronecker_symbol(d,lm1+1)==+1]) + if (lm1+1).is_prime() and kronecker_symbol(d,lm1+1) == +1]) L += L1 if verbose: print("downward split primes: %s" % L1) @@ -1278,7 +1278,7 @@ def isogeny_degrees_cm(E, verbose=False): # l+1 must divide n/2h: L1 = Set([lp1-1 for lp1 in divs - if (lp1-1).is_prime() and kronecker_symbol(d,lp1-1)==-1]) + if (lp1-1).is_prime() and kronecker_symbol(d,lp1-1) == -1]) L += L1 if verbose: print("downward inert primes: %s" % L1) diff --git a/src/sage/schemes/elliptic_curves/isogeny_small_degree.py b/src/sage/schemes/elliptic_curves/isogeny_small_degree.py index 28b4a8ebcca..30312da99a6 100644 --- a/src/sage/schemes/elliptic_curves/isogeny_small_degree.py +++ b/src/sage/schemes/elliptic_curves/isogeny_small_degree.py @@ -204,7 +204,7 @@ def Psi(l, use_stored=True): if l == 3: return X + t + 27 if l == 5: - return X**2 + 2*X*(t**2 + 22*t + 125)+ (t**2 + 22*t + 89) * (t**2 + 22*t + 125) + return X**2 + 2*X*(t**2 + 22*t + 125) + (t**2 + 22*t + 89) * (t**2 + 22*t + 125) if l == 7: return (X**3 + 3*(t**2 + 13*t + 49)*X**2 + 3*(t**2 + 13*t + 33)*(t**2 + 13*t + 49)*X @@ -288,7 +288,7 @@ def isogenies_prime_degree_genus_0(E, l=None, minimal_models=True): to Elliptic Curve defined by y^2 + x*y + y = x^3 - 76*x + 298 over Rational Field] """ if l not in [2, 3, 5, 7, 13, None]: - raise ValueError("%s is not a genus 0 prime."%l) + raise ValueError("%s is not a genus 0 prime." % l) F = E.base_ring() j = E.j_invariant() if F.characteristic() in [2, 3, l]: @@ -327,8 +327,8 @@ def isogenies_prime_degree_genus_0(E, l=None, minimal_models=True): from sage.misc.misc_c import prod psi = Psi(l) X = t - f = R(prod( [p for p,e in jt.factor() if e==3] - +[p for p,e in kt.factor() if e==2])) + f = R(prod( [p for p,e in jt.factor() if e == 3] + + [p for p,e in kt.factor() if e == 2])) kernels = [R(psi(X*T*(j-1728)*t0/f(t0),t0)) for t0 in t_list] kernels = [ker.monic() for ker in kernels] E1 = EllipticCurve([-27*c4,-54*c6]) @@ -555,17 +555,17 @@ def _sporadic_Q_data(j): a4a6 = list(E.ainvs())[3:] L = E.period_lattice() pr = 100 - if ell==163: - pr=1000 - elif ell>30: - pr=300 + if ell == 163: + pr = 1000 + elif ell > 30: + pr = 300 w1, w2 = L.basis(prec=pr) X = polygen(RealField(pr),'X') w = w1 # real period if j in [-121, -24729001, -162677523113838677, QQ(-882216989)/131072]: w = 2*w2-w1 # imaginary period kerpol = prod(([X-L.elliptic_exponential(n*w/ell)[0] for n in range(1,(ell+1)//2)])) - if j==-162677523113838677: + if j == -162677523113838677: kerpolcoeffs = [(37*c.real()).round()/37 for c in list(kerpol)] else: kerpolcoeffs = [c.real().round() for c in list(kerpol)] @@ -908,7 +908,7 @@ def isogenies_5_0(E, minimal_models=True): betas = sorted((x**6-160*a*x**3-80*a**2).roots(multiplicities=False)) if not betas: return [] - gammas = [(beta**2 *(beta**3-140*a))/(120*a) for beta in betas] + gammas = [(beta**2 * (beta**3-140*a))/(120*a) for beta in betas] from sage.rings.number_field.number_field_base import NumberField model = "minimal" if minimal_models and isinstance(F, NumberField) else None isogs = [Ew.isogeny(x**2+beta*x+gamma, model=model) for beta,gamma in zip(betas,gammas)] @@ -1153,7 +1153,7 @@ def isogenies_7_0(E, minimal_models=True): [158428486656000/7*a^3 - 313976217600000, -158428486656000/7*a^3 - 34534529335296000] """ - if E.j_invariant()!=0: + if E.j_invariant() != 0: raise ValueError("j-invariant must be 0.") F = E.base_field() if F.characteristic() in [2,3,7]: @@ -1254,7 +1254,7 @@ def isogenies_7_1728(E, minimal_models=True): sage: E1.is_quadratic_twist(E2) # optional - sage.rings.number_field -1 """ - if E.j_invariant()!=1728: + if E.j_invariant() != 1728: raise ValueError("j_invariant must be 1728 (in base field).") F = E.base_field() if F.characteristic() in [2,3,7]: @@ -1393,7 +1393,7 @@ def isogenies_13_0(E, minimal_models=True): ....: for phi in isogenies_13_0(E)]) 2 """ - if E.j_invariant()!=0: + if E.j_invariant() != 0: raise ValueError("j-invariant must be 0.") F = E.base_field() if F.characteristic() in [2,3,13]: @@ -1538,7 +1538,7 @@ def isogenies_13_1728(E, minimal_models=True): + 2810970361185589/1329760446964992*a^7 - 281503836888046601/8975883017013696*a^5 + 1287313166530075/848061509544*a^3 - 9768837984886039/6925835661276*a)] """ - if E.j_invariant()!=1728: + if E.j_invariant() != 1728: raise ValueError("j-invariant must be 1728.") F = E.base_field() if F.characteristic() in [2, 3, 13]: @@ -1624,7 +1624,7 @@ def _hyperelliptic_isogeny_data(l): ValueError: 37 must be one of [11, 17, 19, 23, 29, 31, 41, 47, 59, 71]. """ if l not in hyperelliptic_primes: - raise ValueError("%s must be one of %s."%(l,hyperelliptic_primes)) + raise ValueError("%s must be one of %s." % (l,hyperelliptic_primes)) data = {} Zu = PolynomialRing(ZZ,'u') Zuv = PolynomialRing(ZZ,['u','v']) @@ -2091,7 +2091,7 @@ def isogenies_prime_degree_genus_plus_0_j0(E, l, minimal_models=True): [Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6] """ if l not in hyperelliptic_primes: - raise ValueError("%s must be one of %s."%(l,hyperelliptic_primes)) + raise ValueError("%s must be one of %s." % (l,hyperelliptic_primes)) F = E.base_field() if E.j_invariant() != 0: raise ValueError(("j-invariant must be 0.")) @@ -2213,7 +2213,7 @@ def isogenies_prime_degree_genus_plus_0_j1728(E, l, minimal_models=True): [(17, 2), (29, 2), (41, 2)] """ if l not in hyperelliptic_primes: - raise ValueError("%s must be one of %s."%(l,hyperelliptic_primes)) + raise ValueError("%s must be one of %s." % (l,hyperelliptic_primes)) F = E.base_ring() if E.j_invariant() != 1728: raise ValueError("j-invariant must be 1728.") @@ -2795,14 +2795,14 @@ def isogenies_prime_degree(E, l, minimal_models=True): with a = 3.316624790355400?*I] """ if not l.is_prime(): - raise ValueError("%s is not prime."%l) - if l==2: + raise ValueError("%s is not prime." % l) + if l == 2: return isogenies_2(E, minimal_models=minimal_models) - if l==3: + if l == 3: return isogenies_3(E, minimal_models=minimal_models) p = E.base_ring().characteristic() - if l==p: + if l == p: return isogenies_prime_degree_general(E,l, minimal_models=minimal_models) if l in [5,7,13] and p not in [2,3]: diff --git a/src/sage/schemes/elliptic_curves/kodaira_symbol.py b/src/sage/schemes/elliptic_curves/kodaira_symbol.py index c8a9f90da4a..b4bbe78b951 100644 --- a/src/sage/schemes/elliptic_curves/kodaira_symbol.py +++ b/src/sage/schemes/elliptic_curves/kodaira_symbol.py @@ -202,14 +202,14 @@ def __init__(self, symbol): else: self._pari = -self._n - 4 self._str = "I" + symbol + "*" - self._latex = "I_{%s}^*"%(symbol) + self._latex = "I_{%s}^*" % (symbol) else: if self._n == 0: self._pari = 1 else: self._pari = self._n + 4 self._str = "I" + symbol - self._latex = "I_{%s}"%(symbol) + self._latex = "I_{%s}" % (symbol) else: raise ValueError("input is not a Kodaira symbol") diff --git a/src/sage/schemes/elliptic_curves/kraus.py b/src/sage/schemes/elliptic_curves/kraus.py index 79b7afa9c2c..29fddb57f6b 100644 --- a/src/sage/schemes/elliptic_curves/kraus.py +++ b/src/sage/schemes/elliptic_curves/kraus.py @@ -379,12 +379,12 @@ def check_Kraus_local_3(c4, c6, P, assume_nonsingular=False, debug=False): return False, 0 e = P.ramification_index() P3 = P**e - if c4.valuation(P)==0: + if c4.valuation(P) == 0: b2 = (-c6*c4.inverse_mod(P3)).mod(P3) if debug: assert test_b2_local(c4,c6,P,b2) return True, b2 - if c6.valuation(P)>=3*e: + if c6.valuation(P) >= 3*e: b2 = c6.parent().zero() if debug: assert test_b2_local(c4,c6,P,b2) @@ -525,7 +525,7 @@ def test_rst_global(c4, c6, r, s, t, debug=False): K = E.base_field() for P in K.primes_above(2)+K.primes_above(3): if not E.is_local_integral_model(P): - print(" -- not integral at P=%s" %P) + print(" -- not integral at P=%s" % P) return False return E @@ -584,7 +584,7 @@ def check_Kraus_local_2(c4, c6, P, a1=None, assume_nonsingular=False): P2 = P**e c4val = c4.valuation(P) - if c4val==0: + if c4val == 0: if a1 is None: flag, t = sqrt_mod_4(-c6,P) if not flag: @@ -618,17 +618,17 @@ def check_Kraus_local_2(c4, c6, P, a1=None, assume_nonsingular=False): P2res = [a1] if a1 else P2.residues() for a1 in P2res: Px = -a1**6+3*a1**2*c4+2*c6 - if Px.valuation(P) >= 4*e : # (i) + if Px.valuation(P) >= 4*e: # (i) flag, a3 = sqrt_mod_4(Px/16,P) # (ii) if flag: a1sq = a1*a1 - if (4*a1sq*Px-(a1sq**2-c4)**2).valuation(P) >= 8*e : # (iii) + if (4*a1sq*Px-(a1sq**2-c4)**2).valuation(P) >= 8*e: # (iii) if test_a1a3_local(c4,c6,P,a1,a3): - return True, a1,a3 + return True, a1, a3 else: raise RuntimeError("check_Kraus_local_2 fails") # end of loop, but no a1 found - return False,0,0 + return False, 0, 0 # Wrapper function for local Kraus check, outsources the real work to # other functions for primes dividing 2 or 3: @@ -688,14 +688,14 @@ def check_Kraus_local(c4, c6, P, assume_nonsingular=False): if not c4c6_nonsingular(c4,c6): return False, None K = c4.parent() - if K(2).valuation(P) >0: + if K(2).valuation(P) > 0: flag, a1, a3 = check_Kraus_local_2(c4,c6,P,None,True) if flag: E = test_a1a3_local(c4,c6,P,a1,a3) if E: return (True, E) return (False, None) - if K(3).valuation(P) >0: + if K(3).valuation(P) > 0: flag, b2 = check_Kraus_local_3(c4,c6,P,True) if flag: E = test_b2_local(c4,c6,P,b2) diff --git a/src/sage/schemes/elliptic_curves/lseries_ell.py b/src/sage/schemes/elliptic_curves/lseries_ell.py index 7f0e4d3e5e5..45db560c861 100644 --- a/src/sage/schemes/elliptic_curves/lseries_ell.py +++ b/src/sage/schemes/elliptic_curves/lseries_ell.py @@ -98,7 +98,7 @@ def _repr_(self): sage: L._repr_() 'Complex L-series of the Elliptic Curve defined by y^2 + y = x^3 - x over Rational Field' """ - return "Complex L-series of the %s"%self.__E + return "Complex L-series of the %s" % self.__E def dokchitser(self, prec=53, max_imaginary_part=0, diff --git a/src/sage/schemes/elliptic_curves/mod5family.py b/src/sage/schemes/elliptic_curves/mod5family.py index 9fe4b2db894..64069c342b7 100644 --- a/src/sage/schemes/elliptic_curves/mod5family.py +++ b/src/sage/schemes/elliptic_curves/mod5family.py @@ -80,7 +80,7 @@ def mod5family(a, b): beta[20] = 30015*(J - 1)**10*(1001 + 634920*J + 3880800*J**2 + 142879744*J**3 - 1168475904*J**4 + 1188919296*J**5 - 143327232*J**6) beta[21] = 100050*(J - 1)**10*(143 + 107250*J + 808368*J**2 + 38518336*J**3 - 451953408*J**4 + 757651968*J**5 - 367276032*J**6) beta[22] = 450225*(J - 1)**11*(-13 - 11440*J - 117216*J**2 - 6444800*J**3 + 94192384*J**4 - 142000128*J**5 + 95551488*J**6) - beta[23] = 156600*(J - 1)**11*(-13 - 13299*J - 163284*J**2 - 11171552*J**3 + 217203840*J**4 - 474406656*J**5 + 747740160*J**6 - 429981696*J**7) + beta[23] = 156600*(J - 1)**11*(-13 - 13299*J - 163284*J**2 - 11171552*J**3 + 217203840*J**4 - 474406656*J**5 + 747740160*J**6 - 429981696*J**7) beta[24] = 6525*(J - 1)**12*(91 + 107536*J + 1680624*J**2 + 132912128*J**3 - 3147511552*J**4 + 6260502528*J**5 - 21054173184*J**6 + 10319560704*J**7) beta[25] = 1566*(J - 1)**12*(91 + 123292*J + 2261248*J**2 + 216211904*J**3 - diff --git a/src/sage/schemes/elliptic_curves/padic_lseries.py b/src/sage/schemes/elliptic_curves/padic_lseries.py index 74581cd2479..f264ca20434 100644 --- a/src/sage/schemes/elliptic_curves/padic_lseries.py +++ b/src/sage/schemes/elliptic_curves/padic_lseries.py @@ -444,7 +444,7 @@ def measure(self, a, n, prec, quadratic_twist=+1, sign=+1): if self._E.conductor() % p == 0: mu = chip**n * z * sum([kronecker_symbol(D,u) * f(a/(p*w)+ZZ(u)/D) for u in range(1,D.abs())]) else: - mu = chip**n * z * sum([kronecker_symbol(D,u) *( f(a/(p*w)+ZZ(u)/D) - chip /alpha * f(a/w+ZZ(u)/D) ) for u in range(1,D.abs())]) + mu = chip**n * z * sum([kronecker_symbol(D,u) * ( f(a/(p*w)+ZZ(u)/D) - chip / alpha * f(a/w+ZZ(u)/D) ) for u in range(1,D.abs())]) return s*mu def alpha(self, prec=20): @@ -868,7 +868,7 @@ def series(self, n=2, quadratic_twist=+1, prec=5, eta=0): raise ValueError("Insufficient precision (%s)" % prec) # check if the conditions on quadratic_twist are satisfied - eta = ZZ(eta) % (self._p- 1) if self._p != 2 else ZZ(eta) % 2 + eta = ZZ(eta) % (self._p - 1) if self._p != 2 else ZZ(eta) % 2 D = ZZ(quadratic_twist) if D != 1: if eta != 0: @@ -876,20 +876,20 @@ def series(self, n=2, quadratic_twist=+1, prec=5, eta=0): if D % 4 == 0: d = D//4 if not d.is_squarefree() or d % 4 == 1: - raise ValueError("quadratic_twist (=%s) must be a fundamental discriminant of a quadratic field"%D) + raise ValueError("quadratic_twist (=%s) must be a fundamental discriminant of a quadratic field" % D) else: if not D.is_squarefree() or D % 4 != 1: - raise ValueError("quadratic_twist (=%s) must be a fundamental discriminant of a quadratic field"%D) + raise ValueError("quadratic_twist (=%s) must be a fundamental discriminant of a quadratic field" % D) if gcd(D,self._p) != 1: - raise ValueError("quadratic twist (=%s) must be coprime to p (=%s) "%(D,self._p)) + raise ValueError("quadratic twist (=%s) must be coprime to p (=%s) " % (D,self._p)) if gcd(D, self._E.conductor()) != 1: for ell in prime_divisors(D): if valuation(self._E.conductor(), ell) > valuation(D, ell): - raise ValueError("cannot twist a curve of conductor (=%s) by the quadratic twist (=%s)."%(self._E.conductor(),D)) + raise ValueError("cannot twist a curve of conductor (=%s) by the quadratic twist (=%s)." % (self._E.conductor(),D)) p = self._p si = 1-2*(eta % 2) - #verbose("computing L-series for p=%s, n=%s, and prec=%s"%(p,n,prec)) + # verbose("computing L-series for p=%s, n=%s, and prec=%s" % (p,n,prec)) if prec == 1: if eta == 0: @@ -915,13 +915,13 @@ def series(self, n=2, quadratic_twist=+1, prec=5, eta=0): bounds = self._prec_bounds(n,prec,sign=si) padic_prec = max(bounds[1:]) + 5 - verbose("using p-adic precision of %s"%padic_prec) + verbose("using p-adic precision of %s" % padic_prec) if p == 2: res_series_prec = min(p**(n-2), prec) else: res_series_prec = min(p**(n-1), prec) - verbose("using series precision of %s"%res_series_prec) + verbose("using series precision of %s" % res_series_prec) ans = self._get_series_from_cache(n, res_series_prec,D,eta) if ans is not None: @@ -942,17 +942,17 @@ def series(self, n=2, quadratic_twist=+1, prec=5, eta=0): a_range = 3 else: teich = self.teichmuller(padic_prec) - gamma = K(1+ p) + gamma = K(1 + p) p_power = p**(n-1) a_range = p - verbose("Now iterating over %s summands"%((p-1)*p_power)) + verbose("Now iterating over %s summands" % ((p-1)*p_power)) verbose_level = get_verbose() count_verb = 0 for j in range(p_power): s = K(0) if verbose_level >= 2 and j/p_power*100 > count_verb + 3: - verbose("%.2f percent done"%(float(j)/p_power*100)) + verbose("%.2f percent done" % (float(j)/p_power*100)) count_verb += 3 for a in range(1,a_range): b = teich[a] * gamma_power @@ -961,7 +961,7 @@ def series(self, n=2, quadratic_twist=+1, prec=5, eta=0): one_plus_T_factor *= 1+T gamma_power *= gamma - verbose("the series before adjusting the precision is %s"%L) + verbose("the series before adjusting the precision is %s" % L) # Now create series but with each coefficient truncated # so it is proven correct: K = Qp(p, padic_prec, print_mode='series') @@ -1052,7 +1052,7 @@ def _c_bound(self, sign=+1): if E.galois_representation().is_irreducible(p): return 0 - if self._implementation=="sage": + if self._implementation == "sage": m = E.modular_symbol_space(sign=1) b = m.boundary_map().codomain() C = b._known_cusps() # all known, since computed the boundary map @@ -1070,7 +1070,7 @@ def _c_bound(self, sign=+1): # else the same reasoning as in _set_denom in numerical # modular symbol. We rely on the fact that p is semistable from sage.databases.cremona import CremonaDatabase - isog = E.isogeny_class() + isog = E.isogeny_class() t = 0 if N <= CremonaDatabase().largest_conductor(): E0 = E.optimal_curve() @@ -1095,7 +1095,7 @@ def _c_bound(self, sign=+1): if p == 2: t += 1 if p == 2 and E0.real_components() == 1: - t += 1 # slanted lattice + t += 1 # slanted lattice # this was the bound for E0 now compare periods # to get the bound for E @@ -1112,7 +1112,7 @@ def _c_bound(self, sign=+1): if E0.real_components() == 1: om0 *= 2 m = max(isog.matrix().list()) - q = (om/om0 *m).round()/m + q = (om/om0 * m).round()/m t += valuation(q,p) return max(t,0) @@ -1227,7 +1227,7 @@ def series(self, n=3, quadratic_twist=+1, prec=5, eta=0): if D % 4 == 0: d = D//4 if not d.is_squarefree() or d % 4 == 1: - raise ValueError("quadratic_twist (=%s) must be a fundamental discriminant of a quadratic field"%D) + raise ValueError("quadratic_twist (=%s) must be a fundamental discriminant of a quadratic field" % D) else: if not D.is_squarefree() or D % 4 != 1: raise ValueError("quadratic_twist (=%s) must be a fundamental discriminant of a quadratic field" % D) @@ -1283,18 +1283,18 @@ def series(self, n=3, quadratic_twist=+1, prec=5, eta=0): a_range = 3 else: teich = self.teichmuller(padic_prec) - gamma = 1+ p + gamma = 1 + p p_power = p**(n-1) a_range = p si = 1-2*(eta % 2) - verbose("Now iterating over %s summands"%((p-1)*p_power)) + verbose("Now iterating over %s summands" % ((p-1)*p_power)) verbose_level = get_verbose() count_verb = 0 for j in range(p_power): s = K(0) if verbose_level >= 2 and j/p_power*100 > count_verb + 3: - verbose("%.2f percent done"%(float(j)/p_power*100)) + verbose("%.2f percent done" % (float(j)/p_power*100)) count_verb += 3 for a in range(1,a_range): b = teich[a] * gamma_power @@ -1393,15 +1393,15 @@ def _poly(self, a): # this should be implemented in elements of Eisenstein rings at some point trac 20248 if a.is_zero(): - return [0,0] + return [0, 0] v, k = a._ntl_rep_abs() K = a.base_ring() pi = K.uniformiser() - v0 = K(v[0]._sage_()) * pi**k - v1 = K(v[1]._sage_()) * pi**k + v0 = K(v[0]._sage_()) * pi**k + v1 = K(v[1]._sage_()) * pi**k alpha = a.parent().gen() - assert v0 + v1*alpha == a - return [ v0, v1 ] + assert v0 + v1 * alpha == a + return [v0, v1] def Dp_valued_series(self, n=3, quadratic_twist=+1, prec=5): r""" @@ -1437,8 +1437,8 @@ def Dp_valued_series(self, n=3, quadratic_twist=+1, prec=5): lps = self.series(n, quadratic_twist=quadratic_twist, prec=prec) # now split up the series in two lps = G + H * alpha - R = lps.base_ring().base_ring() # Qp - QpT , T = PowerSeriesRing(R, 'T', prec).objgen() + R = lps.base_ring().base_ring() # Qp + QpT, T = PowerSeriesRing(R, 'T', prec).objgen() Gli = [] Hli = [] for n in range(lps.prec()): @@ -1449,10 +1449,10 @@ def Dp_valued_series(self, n=3, quadratic_twist=+1, prec=5): H = QpT(Hli, prec) # now compute phi - phi = matrix.matrix([[0,-1/p],[1,E.ap(p)/p]]) - lpv = vector([G + (E.ap(p))*H , - R(p) * H ]) # this is L_p - eps = (1-phi)**(-2) - resu = lpv*eps.transpose() + phi = matrix.matrix([[0, -1 / p], [1, E.ap(p) / p]]) + lpv = vector([G + (E.ap(p)) * H, - R(p) * H]) # this is L_p + eps = (1 - phi)**(-2) + resu = lpv * eps.transpose() return resu def frobenius(self, prec=20, algorithm="mw"): @@ -1484,8 +1484,8 @@ def frobenius(self, prec=20, algorithm="mw"): """ E = self._E p = self._p - if algorithm != "mw" and algorithm !="approx": - raise ValueError("Unknown algorithm %s."%algorithm) + if algorithm != "mw" and algorithm != "approx": + raise ValueError("Unknown algorithm %s." % algorithm) if algorithm == "approx": return self.__phi_bpr(prec=prec) if p < 4 and algorithm == "mw": @@ -1501,24 +1501,24 @@ def frobenius(self, prec=20, algorithm="mw"): fr = matrix.matrix(output_ring,2,2,fr) # return a vector for PARI's ellchangecurve to pass from e1 to e2 - def isom(e1,e2): + def isom(e1, e2): if not e1.is_isomorphic(e2): raise ValueError("Curves must be isomorphic.") - usq = (e1.discriminant()/e2.discriminant()).nth_root(6) + usq = (e1.discriminant() / e2.discriminant()).nth_root(6) u = usq.sqrt() - s = (u * e2.a1() - e1.a1() )/ZZ(2) - r = (usq * e2.a2() - e1.a2() + s**2 + e1.a1()*s)/ZZ(3) - t = (u**3 * e2.a3() - e1.a3() - e1.a1()*r)/ZZ(2) - return [u,r,s,t] + s = (u * e2.a1() - e1.a1()) / ZZ(2) + r = (usq * e2.a2() - e1.a2() + s**2 + e1.a1()*s) / ZZ(3) + t = (u**3 * e2.a3() - e1.a3() - e1.a1()*r) / ZZ(2) + return [u, r, s, t] - v = isom(E,Ew) + v = isom(E, Ew) u = v[0] r = v[1] # change basis - A = matrix.matrix([[u,-r/u],[0,1/u]]) + A = matrix.matrix([[u, -r/u], [0, 1/u]]) frn = A * fr * A**(-1) - return 1/p*frn + return 1 / p*frn def __phi_bpr(self, prec=0): r""" @@ -1571,31 +1571,33 @@ def __phi_bpr(self, prec=0): for k in range(1,prec+1): # this is the equation eq[0]*x+eq[1]*y+eq[2] == 0 # such that delta_ = delta + d^dpr*x ... - eq = [(p**dpr*cs[k]) % p**k,(-p**dga*ds[k]) % p**k , (delta*cs[k]-gamma*ds[k]-cs[k-1]) % p**k ] + eq = [(p**dpr*cs[k]) % p**k, + (-p**dga*ds[k]) % p**k, + (delta*cs[k]-gamma*ds[k]-cs[k-1]) % p**k] verbose("valuations : %s" % ([x.valuation(p) for x in eq])) - v = min([x.valuation(p) for x in eq]) + v = min(x.valuation(p) for x in eq) if v == infinity: - verbose("no new information at step k=%s"%k) + verbose("no new information at step k=%s" % k) else: eq = [ZZ(x/p**v) for x in eq] - verbose("renormalised eq mod p^%s is now %s"%(k-v,eq)) + verbose("renormalised eq mod p^%s is now %s" % (k-v,eq)) if eq[0].valuation(p) == 0: l = min(eq[1].valuation(p),k-v) if l == 0: - verbose("not uniquely determined at step k=%s"%k) + verbose("not uniquely determined at step k=%s" % k) else: ainv = eq[0].inverse_mod(p**l) delta = delta - eq[2]*ainv*p**dpr dpr = dpr + l delta = delta % p**dpr - verbose("delta_prec increased to %s\n delta is now %s"%(dpr,delta)) + verbose("delta_prec increased to %s\n delta is now %s" % (dpr,delta)) elif eq[1].valuation(p) == 0: l = min(eq[0].valuation(p),k-v) ainv = eq[1].inverse_mod(p**l) gamma = gamma - eq[2]*ainv*p**dga dga = dga + l gamma = gamma % p**dga - verbose("gamma_prec increased to %s\n gamma is now %s"%(dga,gamma)) + verbose("gamma_prec increased to %s\n gamma is now %s" % (dga,gamma)) else: raise RuntimeError("Bug: no delta or gamma can exist") @@ -1603,7 +1605,7 @@ def __phi_bpr(self, prec=0): R = Qp(p,max(dpr,dga)+1) delta = R(delta,absprec=dpr) gamma = R(gamma,absprec=dga) - verbose("result delta = %s\n gamma = %s\n check : %s"%(delta,gamma, [Qp(p,k)(delta * cs[k] - gamma * ds[k] - cs[k-1]) for k in range(1,prec+1)] )) + verbose("result delta = %s\n gamma = %s\n check : %s" % (delta,gamma, [Qp(p,k)(delta * cs[k] - gamma * ds[k] - cs[k-1]) for k in range(1,prec+1)] )) a = delta c = -gamma d = E.ap(p) - a @@ -1685,15 +1687,15 @@ def height(P,check=True): tt = R(tt) zz = elog(tt) - homega = -zz**2/n**2 + homega = -zz**2 / n**2 - eQ = denominator(Q[1])/denominator(Q[0]) + eQ = denominator(Q[1]) / denominator(Q[0]) si = self.bernardi_sigma_function(prec=prec+4) - heta = 2 * log(si(zz)/eQ) / n**2 + heta = 2 * log(si(zz)/eQ) / n**2 - R = Qp(p,prec) + R = Qp(p, prec) - return vector([-R(heta),R(homega)]) + return vector([-R(heta), R(homega)]) return height @@ -1720,12 +1722,12 @@ def Dp_valued_regulator(self, prec=20, v1=0, v2=0): p = self._p E = self._E - h = self.Dp_valued_height(prec=prec) + h = self.Dp_valued_height(prec=prec) # this is the height_{v} (P) for a v in D_p - def hv(vec,P): + def hv(vec, P): hP = h(P) - return - vec[0]*hP[1] +vec[1]*hP[0] + return - vec[0]*hP[1] + vec[1]*hP[0] # def hvpairing(vec,P,Q): # return (hv(vec, P+Q) - hv(vec,P)-hv(vec,Q))/2 @@ -1748,7 +1750,7 @@ def regv(vec): point_height = [hv(vec, P) for P in basis] for i in range(rk): for j in range(i+1, rk): - M[i, j] = M[j, i] = (hv(vec,basis[i] + basis[j])- point_height[i] - point_height[j] )/2 + M[i, j] = M[j, i] = (hv(vec,basis[i] + basis[j]) - point_height[i] - point_height[j] )/2 for i in range(rk): M[i, i] = point_height[i] diff --git a/src/sage/schemes/elliptic_curves/padics.py b/src/sage/schemes/elliptic_curves/padics.py index 8dc75a35a43..30587d1cfa5 100644 --- a/src/sage/schemes/elliptic_curves/padics.py +++ b/src/sage/schemes/elliptic_curves/padics.py @@ -317,7 +317,7 @@ def padic_regulator(self, p, prec=20, height=None, check_hypotheses=True): p = Integer(p) # this is assumed in code below if check_hypotheses: if not p.is_prime(): - raise ValueError("p = (%s) must be prime"%p) + raise ValueError("p = (%s) must be prime" % p) if p == 2: raise ValueError("p must be odd") # todo if self.conductor() % (p**2) == 0: @@ -715,7 +715,7 @@ def padic_height(self, p, prec=20, sigma=None, check_hypotheses=True): """ if check_hypotheses: if not p.is_prime(): - raise ValueError("p = (%s) must be prime"%p) + raise ValueError("p = (%s) must be prime" % p) if p == 2: raise ValueError("p must be odd") # todo if self.conductor() % (p**2) == 0: @@ -867,7 +867,7 @@ def padic_height_via_multiply(self, p, prec=20, E2=None, check_hypotheses=True): """ if check_hypotheses: if not p.is_prime(): - raise ValueError("p = (%s) must be prime"%p) + raise ValueError("p = (%s) must be prime" % p) if p == 2: raise ValueError("p must be odd") # todo if self.conductor() % p == 0: @@ -1122,7 +1122,7 @@ def padic_sigma(self, p, N=20, E2=None, check=False, check_hypotheses=True): sigma = sigma.padded_list(N+1) - sigma[0] = K(0, N +1) + sigma[0] = K(0, N + 1) sigma[1] = K(1, N) for n in range(2, N+1): sigma[n] = K(sigma[n].lift(), N - n + 1) diff --git a/src/sage/schemes/elliptic_curves/period_lattice.py b/src/sage/schemes/elliptic_curves/period_lattice.py index 1c767699fb5..615ae86bb60 100644 --- a/src/sage/schemes/elliptic_curves/period_lattice.py +++ b/src/sage/schemes/elliptic_curves/period_lattice.py @@ -236,7 +236,7 @@ def __init__(self, E, embedding=None): self.real_flag = 0 if real: self.real_flag = +1 - if embedding(E.discriminant())<0: + if embedding(E.discriminant()) < 0: self.real_flag = -1 # The following algebraic data associated to E and the @@ -320,9 +320,8 @@ def __repr__(self): Defn: a |--> 1.259921049894873? """ if self.E.base_field() is QQ: - return "Period lattice associated to %s"%(self.E) - else: - return "Period lattice associated to %s with respect to the embedding %s"%(self.E, self.embedding) + return "Period lattice associated to %s" % (self.E) + return "Period lattice associated to %s with respect to the embedding %s" % (self.E, self.embedding) def __call__(self, P, prec=None): r""" @@ -663,7 +662,7 @@ def _compute_periods_real(self, prec=None, algorithm='sage'): w1, w2 = E_pari.omega() return R(w1), C(w2) - if algorithm!='sage': + if algorithm != 'sage': raise ValueError("invalid value of 'algorithm' parameter") pi = R.pi() @@ -743,13 +742,13 @@ def _compute_periods_complex(self, prec=None, normalise=True): pi = C.pi() a, b, c = (C(x) for x in self._abc) if (a+b).abs() < (a-b).abs(): - b=-b + b = -b if (a+c).abs() < (a-c).abs(): - c=-c + c = -c w1 = pi/a.agm(b) w2 = pi*C.gen()/a.agm(c) - if (w1/w2).imag()<0: - w2=-w2 + if (w1/w2).imag() < 0: + w2 = -w2 if normalise: w1w2, mat = normalise_periods(w1,w2) return w1w2 @@ -786,7 +785,7 @@ def is_real(self): The lattice is real if it is associated to a real embedding; such lattices are stable under conjugation. """ - return self.real_flag!=0 + return self.real_flag != 0 def is_rectangular(self): r""" @@ -1198,23 +1197,23 @@ def coordinates(self, z, rounding=None): C = ComplexField() z = C(z) except TypeError: - raise TypeError("%s is not a complex number"%z) + raise TypeError("%s is not a complex number" % z) prec = C.precision() from sage.matrix.constructor import Matrix from sage.modules.free_module_element import vector if self.real_flag: - w1,w2 = self.basis(prec) - M = Matrix([[w1,0], list(w2)])**(-1) + w1, w2 = self.basis(prec) + M = Matrix([[w1, 0], list(w2)])**(-1) else: - w1,w2 = self.normalised_basis(prec) + w1, w2 = self.normalised_basis(prec) M = Matrix([list(w1), list(w2)])**(-1) - u,v = vector(z)*M + u, v = vector(z) * M # Now z = u*w1+v*w2 - if rounding=='round': + if rounding == 'round': return u.round(), v.round() - if rounding=='floor': + if rounding == 'floor': return u.floor(), v.floor() - return u,v + return u, v def reduce(self, z): r""" @@ -1275,17 +1274,17 @@ def reduce(self, z): # NB We assume here that when the embedding is real then the # point is also real! - if self.real_flag == 0: + if self.real_flag == 0: return z if self.real_flag == -1: - k = (z.imag()/w2.imag()).round() + k = (z.imag() / w2.imag()).round() z = z-k*w2 - return C(z.real(),0) + return C(z.real(), 0) - if ((2*z.imag()/w2.imag()).round())%2: - return C(z.real(),w2.imag()/2) + if ((2*z.imag()/w2.imag()).round()) % 2: + return C(z.real(), w2.imag() / 2) else: - return C(z.real(),0) + return C(z.real(), 0) def e_log_RC(self, xP, yP, prec=None, reduce=True): r""" @@ -1394,10 +1393,10 @@ def e_log_RC(self, xP, yP, prec=None, reduce=True): if wP.is_zero(): # 2-torsion treated separately w1,w2 = self._compute_periods_complex(prec,normalise=False) - if xP==e1: + if xP == e1: z = w2/2 else: - if xP==e3: + if xP == e3: z = w1/2 else: z = (w1+w2)/2 @@ -1415,15 +1414,15 @@ def e_log_RC(self, xP, yP, prec=None, reduce=True): # but also causes problems (see #10026). It is left in but # commented out below. - if self.real_flag==0: # complex case + if self.real_flag == 0: # complex case a = C((e1-e3).sqrt()) b = C((e1-e2).sqrt()) if (a+b).abs() < (a-b).abs(): - b=-b + b = -b r = C(((xP-e3)/(xP-e2)).sqrt()) - if r.real()<0: - r=-r + if r.real() < 0: + r = -r t = -C(wP)/(2*r*(xP-e2)) # eps controls the end of the loop. Since we aim at a target # precision of prec bits, eps = 2^(-prec) is enough. @@ -1432,20 +1431,20 @@ def e_log_RC(self, xP, yP, prec=None, reduce=True): s = b*r+a a, b = (a+b)/2, (a*b).sqrt() if (a+b).abs() < (a-b).abs(): - b=-b + b = -b r = (a*(r+1)/s).sqrt() if (r.abs()-1).abs() < eps: break - if r.real()<0: - r=-r + if r.real() < 0: + r = -r t *= r z = ((a/t).arctan())/a z = ComplexField(prec)(z) if reduce: - z = self.reduce(z) + z = self.reduce(z) return z - if self.real_flag==-1: # real, connected case + if self.real_flag == -1: # real, connected case z = C(self._abc[0]) # sqrt(e3-e1) a, y, b = z.real(), z.imag(), z.abs() uv = (xP-e1).sqrt() @@ -1457,8 +1456,8 @@ def e_log_RC(self, xP, yP, prec=None, reduce=True): a = R(e3-e1).sqrt() b = R(e3-e2).sqrt() if (a+b).abs() < (a-b).abs(): - b=-b - on_egg = (xP=0.999 and tau.real().abs() <= 0.5 + assert a*d-b*c == 1 + assert tau.abs() >= 0.999 and tau.real().abs() <= 0.5 return tau, [a,b,c,d] @@ -1966,13 +1965,13 @@ def normalise_periods(w1, w2): """ tau = w1/w2 s = +1 - if tau.imag()<0: + if tau.imag() < 0: w2 = -w2 tau = -tau s = -1 tau, abcd = reduce_tau(tau) a, b, c, d = abcd - if s<0: + if s < 0: abcd = (a,-b,c,-d) return (a*w1+b*w2,c*w1+d*w2), abcd diff --git a/src/sage/schemes/elliptic_curves/saturation.py b/src/sage/schemes/elliptic_curves/saturation.py index b76cd5d2ebf..c75972e7f02 100644 --- a/src/sage/schemes/elliptic_curves/saturation.py +++ b/src/sage/schemes/elliptic_curves/saturation.py @@ -492,7 +492,7 @@ def p_saturation(self, Plist, p, sieve=True): # and there is no simple test.) avoid = [self._N, self._D] + [P[0].denominator_ideal().norm() for P in Plist] - cm_test = E.has_rational_cm() and kro(E.cm_discriminant(), p)==-1 + cm_test = E.has_rational_cm() and kro(E.cm_discriminant(), p) == -1 for q in Primes(): if any(q.divides(m) for m in avoid): continue @@ -543,7 +543,7 @@ def p_saturation(self, Plist, p, sieve=True): # point which is certainly a p-multiple # modulo 15 primes Q, and we test if it # actually is a p-multiple: - if len(Rlist)==1: + if len(Rlist) == 1: R = Rlist[0] pts = R.division_points(p) if pts: @@ -650,7 +650,7 @@ def p_projections(Eq, Plist, p, debug=False): m = n.prime_to_m_part(p) # prime-to-p part of order if debug: print("m={}, n={}".format(m,n)) - if m==n: # p-primary part trivial, nothing to do + if m == n: # p-primary part trivial, nothing to do return [] G = Eq.abelian_group() if debug: diff --git a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_generic.py b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_generic.py index 9ab9dfbcb4c..a56fee001cf 100644 --- a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_generic.py +++ b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_generic.py @@ -349,7 +349,7 @@ def odd_degree_model(self): raise ValueError("No odd degree model exists over field of definition") rt = rts[0] x = f.parent().gen() - fnew = f((x*rt + 1)/x).numerator() # move rt to "infinity" + fnew = f((x * rt + 1) / x).numerator() # move rt to "infinity" from .constructor import HyperellipticCurve return HyperellipticCurve(fnew, 0, names=self._names, PP=self._PP)