# Ticket #5674: twist.patch

File twist.patch, 25.2 KB (added by cremona, 12 years ago)

apply to 3.4.1.apha0 + #4667 patches

• ## sage/schemes/elliptic_curves/all.py

```# HG changeset patch
# User John Cremona <john.cremona@gmail.com>
# Date 1238759297 -3600
# Node ID 3fa8b641e0fe5afd6bb7e02d410fd1d65c93b9d3
# Parent  653655f60cc4b06809628ab06e56002e3d64e70c
[mq]: twist

diff -r 653655f60cc4 -r 3fa8b641e0fe sage/schemes/elliptic_curves/all.py```
 a #***************************************************************************** from constructor import (EllipticCurve, EllipticCurve_from_c4c6, EllipticCurve_from_cubic) EllipticCurve_from_j, EllipticCurve_from_cubic) from ell_generic import is_EllipticCurve, Hasse_bounds
• ## sage/schemes/elliptic_curves/constructor.py

`diff -r 653655f60cc4 -r 3fa8b641e0fe sage/schemes/elliptic_curves/constructor.py`
 a over R with given a-invariants. Here R can be an arbitrary ring. Note that addition need not be defined. - EllipticCurve(j): Return an elliptic curve with j-invariant `j`. `j`.  Warning: this is deprecated.  Use ``EllipticCurve_from_j(j)`` instead. EXAMPLES: We illustrate creating elliptic curves. sage: E(0) (0 : 1 : 0) """ # TODO - - implement #sage: E = EllipticCurve(ZZ, [0, 0,1,-1,0]) #sage: E #Elliptic Curve defined by y^2 + y = x^3 - x over Integer Ring #Of course, arithmetic on elliptic curves over Z need not be defined: #sage: P = E([0,0]) #sage: P + P + P + P #(2, -3) #sage: P + P + P + P + P #Traceback (most recent call last): #... #ArithmeticError: Point (1/4, -5/8) is not on curve. # import ell_generic, ell_finite_field, ell_number_field, ell_rational_field, ell_padic_field  # here to avoid circular includes if isinstance(x, SymbolicEquation): return ell_rational_field.EllipticCurve_rational_field(x) if rings.is_RingElement(x) and y is None: from sage.misc.misc import deprecation deprecation("'EllipticCurve(j)' is deprecated; use 'EllipticCurve_from_j(j)' instead.") # Fixed for all characteristics and cases by John Cremona j=x F=j.parent().fraction_field() char=F.characteristic() print "constructin an elliptic curve from j = ",j if char==2: if j==0: return EllipticCurve(F, [ 0, 0, 1, 0, 0 ]) K = K.fraction_field() return EllipticCurve([-K(c4)/K(48), -K(c6)/K(864)]) def EllipticCurve_from_j(j): """ Return an elliptic curve with given `j`-invariant. EXAMPLES:: sage: E = EllipticCurve_from_j(0); E; E.j_invariant(); E.label() Elliptic Curve defined by y^2 + y = x^3 over Rational Field 0 '27a3' sage: E = EllipticCurve_from_j(1728); E; E.j_invariant(); E.label() Elliptic Curve defined by y^2 = x^3 - x over Rational Field 1728 '32a2' sage: E = EllipticCurve_from_j(1); E; E.j_invariant() Elliptic Curve defined by y^2 + x*y = x^3 + 36*x + 3455 over Rational Field 1 """ try: K = j.parent() except AttributeError: K = rings.RationalField() if not rings.is_Field(K): K = K.fraction_field() char=K.characteristic() if char==2: if j == 0: return EllipticCurve(K, [ 0, 0, 1, 0, 0 ]) else: return EllipticCurve(K, [ 1, 0, 0, 0, 1/j ]) if char == 3: if j==0: return EllipticCurve(K, [ 0, 0, 0, 1, 0 ]) else: return EllipticCurve(K, [ 0, j, 0, 0, -j**2 ]) if K is rings.RationalField(): # we construct the minimal twist, i.e. the curve with minimal # conductor with this j_invariant: if j == 0: return EllipticCurve(K, [ 0, 0, 1, 0, 0 ]) # 27a3 if j == 1728: return EllipticCurve(K, [ 0, 0, 0, -1, 0 ]) # 32a2 n = j.numerator() m = n-1728*j.denominator() a4 = -3*n*m a6 = -2*n*m**2 # Now E=[0,0,0,a4,a6] has j-invariant j=n/d 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: p  = p**e a4 /= p**2 a6 /= p**3 # Now E=[0,0,0,a4,a6] is minimal at all p != 2,3 tw = [-1,2,-2,3,-3,6,-6] E1 = EllipticCurve([0,0,0,a4,a6]) Elist = [E1] + [E1.quadratic_twist(t) for t in tw] crv_cmp = lambda E,F: cmp(E.conductor(),F.conductor()) Elist.sort(cmp=crv_cmp) return Elist[0] # defaults for all other fields: if j == 0: return EllipticCurve(K, [ 0, 0, 0, 0, 1 ]) if j == 1728: return EllipticCurve(K, [ 0, 0, 0, 1, 0 ]) k=j-1728 return EllipticCurve(K, [0,0,0,-3*j*k, -2*j*k**2]) def EllipticCurve_from_cubic(F, P): r""" Given a nonsingular homogenous cubic polynomial F over `\mathbb{Q}` in three variables x, y, z and a projective solution P=[a,b,c] to F(P)=0, find the minimal Weierstrass equation of the elliptic curve over `\mathbb{Q}` that is isomorphic to the curve defined by `F=0`. `\mathbb{Q}` in three variables x, y, z and a projective solution P=[a,b,c] to F(P)=0, find the minimal Weierstrass equation of the elliptic curve over `\mathbb{Q}` that is isomorphic to the curve defined by `F=0`. .. note::
• ## sage/schemes/elliptic_curves/ell_finite_field.py

`diff -r 653655f60cc4 -r 3fa8b641e0fe sage/schemes/elliptic_curves/ell_finite_field.py`
 a from ell_generic import Hasse_bounds from ell_field import EllipticCurve_field from constructor import EllipticCurve from constructor import EllipticCurve, EllipticCurve_from_j from sage.schemes.hyperelliptic_curves.hyperelliptic_finite_field import HyperellipticCurve_finite_field import sage.rings.ring as ring from sage.rings.all import Integer, ZZ, PolynomialRing, ComplexField, FiniteField, GF, polygen jkj=kj.gen() if j_deg>1 else j_pol.roots(multiplicities=False)[0] # recursive call which will do all the real work: Ej = EllipticCurve(jkj) Ej = EllipticCurve_from_j(jkj) N=Ej.cardinality(extension_degree=d//j_deg) # if curve ia a (quadratic) twist of the "standard" one: if not self.is_isomorphic(EllipticCurve(j)): N=2*(q+1)-N if not self.is_isomorphic(EllipticCurve_from_j(j)): N=2*(q+1)-N self._order = N return self._order
• ## sage/schemes/elliptic_curves/ell_generic.py

`diff -r 653655f60cc4 -r 3fa8b641e0fe sage/schemes/elliptic_curves/ell_generic.py`
`diff -r 653655f60cc4 -r 3fa8b641e0fe sage/schemes/elliptic_curves/ell_rational_field.py`
`diff -r 653655f60cc4 -r 3fa8b641e0fe sage/schemes/elliptic_curves/weierstrass_morphism.py`