Ticket #3954: 3954-pari_curve_caching.patch
| File 3954-pari_curve_caching.patch, 6.7 kB (added by AlexGhitza, 4 months ago) |
|---|
-
a/sage/schemes/elliptic_curves/ell_rational_field.py
old new 411 411 412 412 INPUT: 413 413 prec -- The precision of quantities calculated for the 414 returned curve (in decimal digits). if None, defaults414 returned curve (in decimal digits). If None, defaults 415 415 to factor * the precision of the largest cached curve 416 416 (or 10 if none yet computed) 417 factor -- the factorto increase the precision over the417 factor -- The factor by which to increase the precision over the 418 418 maximum previously computed precision. Only used if 419 419 prec (which gives an explicit precision) is None. 420 420 … … 429 429 [1, -2, -3, 2, -2, 6, -1, 0, 6, 4] 430 430 431 431 sage: E = EllipticCurve(RationalField(), ['1/3', '2/3']) 432 sage: e = E.pari_curve() 432 sage: e = E.pari_curve(prec = 20) 433 sage: E._pari_curve.has_key(20) 434 True 433 435 sage: e.type() 434 436 't_VEC' 435 437 sage: e[:5] 436 438 [0, 0, 0, 1/3, 2/3] 437 """ 438 if prec is None: 439 try: 439 440 This shows that the bug uncovered by trac \#3954 is fixed: 441 sage: E._pari_curve.has_key(20) 442 True 443 """ 444 try: 445 # if the PARI curve has already been computed to this 446 # precision, returned the cached copy 447 return self._pari_curve[prec] 448 except AttributeError: 449 # no PARI curves have been computed for this elliptic curve 450 self._pari_curve = {} 451 if prec is None: 452 prec = 10 453 except KeyError: 454 # PARI curves are cached for this elliptic curve, but they 455 # are not of the requested precision (or prec = None) 456 if prec is None: 440 457 L = self._pari_curve.keys() 441 458 L.sort() 442 459 if factor == 1: 443 460 return self._pari_curve[L[-1]] 444 461 else: 445 462 prec = int(factor * L[-1]) 446 self._pari_curve[prec] = pari(self.a_invariants()).ellinit(precision=prec)447 return self._pari_curve[prec]448 except AttributeError:449 pass450 try:451 return self._pari_curve[prec]452 except AttributeError:453 prec = 10454 self._pari_curve = {}455 except KeyError:456 pass457 463 self._pari_curve[prec] = pari(self.a_invariants()).ellinit(precision=prec) 458 464 return self._pari_curve[prec] 459 465 460 def pari_mincurve(self, prec = None ):466 def pari_mincurve(self, prec = None, factor = 1): 461 467 """ 462 468 Return the PARI curve corresponding to a minimal model 463 469 for this elliptic curve. 464 470 465 471 INPUT: 466 prec -- The precision of quantities calculated for the 467 returned curve (in decimal digits). if None, defaults 468 to the precision of the largest cached curve (or 10 if 469 none yet computed) 472 prec -- The precision of quantities calculated for the 473 returned curve (in decimal digits). If None, defaults 474 to factor * the precision of the largest cached curve 475 (or 10 if none yet computed) 476 factor -- The factor by which to increase the precision over the 477 maximum previously computed precision. Only used if 478 prec (which gives an explicit precision) is None. 470 479 471 480 EXAMPLES: 472 481 sage: E = EllipticCurve(RationalField(), ['1/3', '2/3']) … … 478 487 sage: e.ellglobalred() 479 488 [47232, [1, 0, 0, 0], 2] 480 489 """ 481 if prec is None: 482 try: 490 try: 491 # if the PARI curve has already been computed to this 492 # precision, returned the cached copy 493 return self._pari_mincurve[prec] 494 except AttributeError: 495 # no PARI curves have been computed for this elliptic curve 496 self._pari_mincurve = {} 497 if prec is None: 498 prec = 10 499 except KeyError: 500 # PARI curves are cached for this elliptic curve, but they 501 # are not of the requested precision (or prec = None) 502 if prec is None: 483 503 L = self._pari_mincurve.keys() 484 504 L.sort() 485 return self._pari_mincurve[L[len(L) - 1]] 486 except AttributeError: 487 pass 488 try: 489 return self._pari_mincurve[prec] 490 except AttributeError: 491 prec = 10 492 self._pari_mincurve = {} 493 except KeyError: 494 pass 505 if factor == 1: 506 return self._pari_mincurve[L[-1]] 507 else: 508 prec = int(factor * L[-1]) 495 509 e = self.pari_curve(prec) 496 510 mc, change = e.ellminimalmodel() 497 511 self._pari_mincurve[prec] = mc -
a/sage/schemes/elliptic_curves/period_lattice.py
old new 41 41 sage: E.period_lattice().basis() 42 42 (2.993458646231959629832009979452508177797583791370132985340523378563250356987, 2.451389381986790060854224831866525225349617289144796614656471406129152899999*I) # 32-bit 43 43 (2.99345864623195962983200997945250817779758379137013298534052337856325035698668290412039406739705147343584052710494728819414438723737202525437537667109326, 2.45138938198679006085422483186652522534961728914479661465647140612915289999925689289113212802918108871268421886966184797547519986661675580167893816478303*I) # 64-bit 44 45 This shows that the issue reported at trac \#3954 is fixed: 46 sage: E = EllipticCurve('37a') 47 sage: b1 = E.period_lattice().basis(prec=30) 48 sage: b2 = E.period_lattice().basis(prec=30) 49 sage: b1 == b2 50 True 44 51 """ 45 52 return tuple(self.E.pari_curve(prec).omega().python(precision=prec)) 46 53