Ticket #13100: trac13100-elliptic.patch
File trac13100-elliptic.patch, 7.4 KB (added by , 11 years ago) |
---|
-
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 b 32 32 from sage.symbolic.expression import is_SymbolicEquation 33 33 34 34 35 def EllipticCurve(x=None, y=None, j=None ):35 def EllipticCurve(x=None, y=None, j=None, minimal_twist=True): 36 36 r""" 37 37 There are several ways to construct an elliptic curve: 38 38 … … 58 58 Note that addition need not be defined. 59 59 60 60 61 - EllipticCurve(j): Return an elliptic curve with j-invariant 62 `j`. Warning: this is deprecated. Use ``EllipticCurve_from_j(j)`` 63 or ``EllipticCurve(j=j)`` instead. 61 - EllipticCurve(j=j0) or EllipticCurve_from_j(j0): Return an 62 elliptic curve with j-invariant `j0`. 64 63 65 64 In each case above where the input is a list of length 2 or 5, one 66 65 can instead give a 2 or 5-tuple instead. … … 146 145 Elliptic Curve defined by y^2 = x^3 + x + 1 over Finite Field of size 5 147 146 2 148 147 149 See trac #6657:: 148 See trac #6657:: 150 149 151 150 sage: EllipticCurve(GF(144169),j=1728) 152 151 Elliptic Curve defined by y^2 = x^3 + x over Finite Field of size 144169 153 152 153 By default, when a rational value of `j` is given, the constructed 154 curve is a minimal twist (minimal conductor for curves with that 155 `j`-invariant). This can be changed by setting the optional 156 parameter ``minimal_twist``, which is True by default, to False:: 157 158 159 sage: EllipticCurve(j=100) 160 Elliptic Curve defined by y^2 = x^3 + x^2 + 3392*x + 307888 over Rational Field 161 sage: E =EllipticCurve(j=100); E 162 Elliptic Curve defined by y^2 = x^3 + x^2 + 3392*x + 307888 over Rational Field 163 sage: E.conductor() 164 33129800 165 sage: E.j_invariant() 166 100 167 sage: E =EllipticCurve(j=100, minimal_twist=False); E 168 Elliptic Curve defined by y^2 = x^3 + 488400*x - 530076800 over Rational Field 169 sage: E.conductor() 170 298168200 171 sage: E.j_invariant() 172 100 173 174 Without this option, constructing the curve could take a long time 175 since both `j` and `j-1728` have to be factored to compute the 176 minimal twist (see :trac:`13100`):: 177 178 sage: E = EllipticCurve_from_j(2^256+1,minimal_twist=False) 179 sage: E.j_invariant() == 2^256+1 180 True 154 181 155 182 TESTS:: 156 183 157 184 sage: R = ZZ['u', 'v'] 158 185 sage: EllipticCurve(R, [1,1]) 159 186 Elliptic Curve defined by y^2 = x^3 + x + 1 over Multivariate Polynomial Ring in u, v … … 227 254 sage: E = EllipticCurve([1..5]) 228 255 sage: EllipticCurve(E.a_invariants()) 229 256 Elliptic Curve defined by y^2 + x*y + 3*y = x^3 + 2*x^2 + 4*x + 5 over Rational Field 257 258 See :trac:`11773`:: 259 260 sage: E = EllipticCurve() 261 Traceback (most recent call last): 262 ... 263 TypeError: invalid input to EllipticCurve constructor 264 230 265 """ 231 266 import ell_generic, ell_field, ell_finite_field, ell_number_field, ell_rational_field, ell_padic_field # here to avoid circular includes 232 267 … … 235 270 if rings.is_Ring(x): 236 271 try: 237 272 j = x(j) 238 except (ZeroDivisionError, ValueError, TypeError): 273 except (ZeroDivisionError, ValueError, TypeError): 239 274 raise ValueError, "First parameter must be a ring containing %s"%j 240 275 else: 241 276 raise ValueError, "First parameter (if present) must be a ring when j is specified" 242 return EllipticCurve_from_j(j )277 return EllipticCurve_from_j(j, minimal_twist) 243 278 244 assert x is not None 279 if x is None: 280 raise TypeError, "invalid input to EllipticCurve constructor" 245 281 246 282 if is_SymbolicEquation(x): 247 283 x = x.lhs() - x.rhs() … … 304 340 305 341 if isinstance(x, unicode): 306 342 x = str(x) 307 343 308 344 if isinstance(x, str): 309 345 return ell_rational_field.EllipticCurve_rational_field(x) 310 346 311 347 if rings.is_RingElement(x) and y is None: 312 from sage.misc.misc import deprecation 313 deprecation("'EllipticCurve(j)' is deprecated; use 'EllipticCurve_from_j(j)' or 'EllipticCurve(j=j)' instead.") 314 # Fixed for all characteristics and cases by John Cremona 315 j=x 316 F=j.parent().fraction_field() 317 char=F.characteristic() 318 if char==2: 319 if j==0: 320 return EllipticCurve(F, [ 0, 0, 1, 0, 0 ]) 321 else: 322 return EllipticCurve(F, [ 1, 0, 0, 0, 1/j ]) 323 if char==3: 324 if j==0: 325 return EllipticCurve(F, [ 0, 0, 0, 1, 0 ]) 326 else: 327 return EllipticCurve(F, [ 0, j, 0, 0, -j**2 ]) 328 if j == 0: 329 return EllipticCurve(F, [ 0, 0, 0, 0, 1 ]) 330 if j == 1728: 331 return EllipticCurve(F, [ 0, 0, 0, 1, 0 ]) 332 k=j-1728 333 return EllipticCurve(F, [0,0,0,-3*j*k, -2*j*k**2]) 348 raise TypeError, "invalid input to EllipticCurve constructor" 334 349 335 350 if not isinstance(x, (list, tuple)): 336 351 raise TypeError, "invalid input to EllipticCurve constructor" … … 379 394 K = K.fraction_field() 380 395 return EllipticCurve([-K(c4)/K(48), -K(c6)/K(864)]) 381 396 382 def EllipticCurve_from_j(j ):397 def EllipticCurve_from_j(j, minimal_twist=True): 383 398 """ 384 399 Return an elliptic curve with given `j`-invariant. 385 400 401 INPUT: 402 403 - ``j`` -- an element of some field. 404 405 - ``minimal_twist`` (boolean, default True) -- If True and ``j`` is in `\QQ`, the curve returned is a 406 minimal twist, i.e. has minimal conductor. If `j` is not in `\QQ` this parameter is ignored. 407 408 OUTPUT: 409 410 (elliptic curve) An elliptic curve with `j`-invariant `j`. 411 386 412 EXAMPLES:: 387 413 388 414 sage: E = EllipticCurve_from_j(0); E; E.j_invariant(); E.label() … … 399 425 Elliptic Curve defined by y^2 + x*y = x^3 + 36*x + 3455 over Rational Field 400 426 1 401 427 428 The ``minimal_twist`` parameter (ignored except over `\QQ` and 429 True by default) controls whether or not a minimal twist is 430 computed:: 431 432 sage: EllipticCurve_from_j(100) 433 Elliptic Curve defined by y^2 = x^3 + x^2 + 3392*x + 307888 over Rational Field 434 sage: _.conductor() 435 33129800 436 sage: EllipticCurve_from_j(100, minimal_twist=False) 437 Elliptic Curve defined by y^2 = x^3 + 488400*x - 530076800 over Rational Field 438 sage: _.conductor() 439 298168200 440 441 Since computing the minimal twist requires factoring both `j` and 442 `j-1728` the following example would take a long time without 443 setting `minimal_twist` to False:: 444 445 sage: E = EllipticCurve_from_j(2^256+1,minimal_twist=False) 446 sage: E.j_invariant() == 2^256+1 447 True 448 402 449 """ 403 450 try: 404 451 K = j.parent() … … 428 475 if j == 1728: 429 476 return EllipticCurve(K, [ 0, 0, 0, -1, 0 ]) # 32a2 430 477 478 if not minimal_twist: 479 k=j-1728 480 return EllipticCurve(K, [0,0,0,-3*j*k, -2*j*k**2]) 481 431 482 n = j.numerator() 432 483 m = n-1728*j.denominator() 433 484 a4 = -3*n*m