# Ticket #13100: trac13100-elliptic.patch

File trac13100-elliptic.patch, 7.4 KB (added by cremona, 7 years ago)

Applies to 5.1.beta3

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

```# HG changeset patch
# User John Cremona <john.cremona@gmail.com>
# Date 1339347560 -3600
# Node ID 485d1dc601e854a70ab98bedec916126eba3b0f2
# Parent  6c345ac8a80ecf9ed03a07896b98c608aa79f1e5
#13100 -- enhancements to elliptic curve constructor

diff --git a/sage/schemes/elliptic_curves/constructor.py b/sage/schemes/elliptic_curves/constructor.py```
 a from sage.symbolic.expression import is_SymbolicEquation def EllipticCurve(x=None, y=None, j=None): def EllipticCurve(x=None, y=None, j=None, minimal_twist=True): r""" There are several ways to construct an elliptic curve: Note that addition need not be defined. - EllipticCurve(j): Return an elliptic curve with j-invariant `j`.  Warning: this is deprecated.  Use ``EllipticCurve_from_j(j)`` or ``EllipticCurve(j=j)`` instead. - EllipticCurve(j=j0) or EllipticCurve_from_j(j0): Return an elliptic curve with j-invariant `j0`. In each case above where the input is a list of length 2 or 5, one can instead give a 2 or 5-tuple instead. Elliptic Curve defined by y^2 = x^3 + x + 1 over Finite Field of size 5 2 See trac #6657:: See trac #6657:: sage: EllipticCurve(GF(144169),j=1728) Elliptic Curve defined by y^2 = x^3 + x over Finite Field of size 144169 By default, when a rational value of `j` is given, the constructed curve is a minimal twist (minimal conductor for curves with that `j`-invariant).  This can be changed by setting the optional parameter ``minimal_twist``, which is True by default, to False:: sage: EllipticCurve(j=100) Elliptic Curve defined by y^2 = x^3 + x^2 + 3392*x + 307888 over Rational Field sage: E =EllipticCurve(j=100); E Elliptic Curve defined by y^2 = x^3 + x^2 + 3392*x + 307888 over Rational Field sage: E.conductor() 33129800 sage: E.j_invariant() 100 sage: E =EllipticCurve(j=100, minimal_twist=False); E Elliptic Curve defined by y^2 = x^3 + 488400*x - 530076800 over Rational Field sage: E.conductor() 298168200 sage: E.j_invariant() 100 Without this option, constructing the curve could take a long time since both `j` and `j-1728` have to be factored to compute the minimal twist (see :trac:`13100`):: sage: E = EllipticCurve_from_j(2^256+1,minimal_twist=False) sage: E.j_invariant() == 2^256+1 True TESTS:: sage: R = ZZ['u', 'v'] sage: EllipticCurve(R, [1,1]) Elliptic Curve defined by y^2 = x^3 + x + 1 over Multivariate Polynomial Ring in u, v sage: E = EllipticCurve([1..5]) sage: EllipticCurve(E.a_invariants()) Elliptic Curve defined by y^2 + x*y + 3*y = x^3 + 2*x^2 + 4*x + 5 over Rational Field See :trac:`11773`:: sage: E = EllipticCurve() Traceback (most recent call last): ... TypeError: invalid input to EllipticCurve constructor """ import ell_generic, ell_field, ell_finite_field, ell_number_field, ell_rational_field, ell_padic_field  # here to avoid circular includes if rings.is_Ring(x): try: j = x(j) except (ZeroDivisionError, ValueError, TypeError): except (ZeroDivisionError, ValueError, TypeError): raise ValueError, "First parameter must be a ring containing %s"%j else: raise ValueError, "First parameter (if present) must be a ring when j is specified" return EllipticCurve_from_j(j) return EllipticCurve_from_j(j, minimal_twist) assert x is not None if x is None: raise TypeError, "invalid input to EllipticCurve constructor" if is_SymbolicEquation(x): x = x.lhs() - x.rhs() if isinstance(x, unicode): x = str(x) if isinstance(x, str): 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)' or 'EllipticCurve(j=j)' instead.") # Fixed for all characteristics and cases by John Cremona j=x F=j.parent().fraction_field() char=F.characteristic() if char==2: if j==0: return EllipticCurve(F, [ 0, 0, 1, 0, 0 ]) else: return EllipticCurve(F, [ 1, 0, 0, 0, 1/j ]) if char==3: if j==0: return EllipticCurve(F, [ 0, 0, 0, 1, 0 ]) else: return EllipticCurve(F, [ 0, j, 0, 0, -j**2 ]) if j == 0: return EllipticCurve(F, [ 0, 0, 0, 0, 1 ]) if j == 1728: return EllipticCurve(F, [ 0, 0, 0, 1, 0 ]) k=j-1728 return EllipticCurve(F, [0,0,0,-3*j*k, -2*j*k**2]) raise TypeError, "invalid input to EllipticCurve constructor" if not isinstance(x, (list, tuple)): raise TypeError, "invalid input to EllipticCurve constructor" K = K.fraction_field() return EllipticCurve([-K(c4)/K(48), -K(c6)/K(864)]) def EllipticCurve_from_j(j): def EllipticCurve_from_j(j, minimal_twist=True): """ Return an elliptic curve with given `j`-invariant. INPUT: - ``j`` -- an element of some field. - ``minimal_twist`` (boolean, default True) -- If True and ``j`` is in `\QQ`, the curve returned is a minimal twist, i.e. has minimal conductor.  If `j` is not in `\QQ` this parameter is ignored. OUTPUT: (elliptic curve) An elliptic curve with `j`-invariant `j`. EXAMPLES:: sage: E = EllipticCurve_from_j(0); E; E.j_invariant(); E.label() Elliptic Curve defined by y^2 + x*y = x^3 + 36*x + 3455 over Rational Field 1 The ``minimal_twist`` parameter (ignored except over `\QQ` and True by default) controls whether or not a minimal twist is computed:: sage: EllipticCurve_from_j(100) Elliptic Curve defined by y^2 = x^3 + x^2 + 3392*x + 307888 over Rational Field sage: _.conductor() 33129800 sage: EllipticCurve_from_j(100, minimal_twist=False) Elliptic Curve defined by y^2 = x^3 + 488400*x - 530076800 over Rational Field sage: _.conductor() 298168200 Since computing the minimal twist requires factoring both `j` and `j-1728` the following example would take a long time without setting `minimal_twist` to False:: sage: E = EllipticCurve_from_j(2^256+1,minimal_twist=False) sage: E.j_invariant() == 2^256+1 True """ try: K = j.parent() if j == 1728: return EllipticCurve(K, [ 0, 0, 0, -1, 0 ]) # 32a2 if not minimal_twist: k=j-1728 return EllipticCurve(K, [0,0,0,-3*j*k, -2*j*k**2]) n = j.numerator() m = n-1728*j.denominator() a4 = -3*n*m