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  
    411411 
    412412        INPUT: 
    413413            prec -- The precision of quantities calculated for the 
    414                     returned curve (in decimal digits).  if None, defaults 
     414                    returned curve (in decimal digits).  If None, defaults 
    415415                    to factor * the precision of the largest cached curve 
    416416                    (or 10 if none yet computed) 
    417             factor -- the factor to increase the precision over the 
     417            factor -- The factor by which to increase the precision over the 
    418418                      maximum previously computed precision.  Only used if 
    419419                      prec (which gives an explicit precision) is None. 
    420420                 
     
    429429            [1, -2, -3, 2, -2, 6, -1, 0, 6, 4] 
    430430 
    431431            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 
    433435            sage: e.type() 
    434436            't_VEC' 
    435437            sage: e[:5] 
    436438            [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: 
    440457                L = self._pari_curve.keys() 
    441458                L.sort() 
    442459                if factor == 1: 
    443460                    return self._pari_curve[L[-1]] 
    444461                else: 
    445462                    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                 pass 
    450         try: 
    451             return self._pari_curve[prec] 
    452         except AttributeError: 
    453             prec = 10 
    454             self._pari_curve = {} 
    455         except KeyError: 
    456             pass 
    457463        self._pari_curve[prec] = pari(self.a_invariants()).ellinit(precision=prec) 
    458464        return self._pari_curve[prec] 
    459465 
    460     def pari_mincurve(self, prec = None): 
     466    def pari_mincurve(self, prec = None, factor = 1): 
    461467        """ 
    462468        Return the PARI curve corresponding to a minimal model 
    463469        for this elliptic curve. 
    464470 
    465471        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. 
    470479 
    471480        EXAMPLES: 
    472481            sage: E = EllipticCurve(RationalField(), ['1/3', '2/3']) 
     
    478487            sage: e.ellglobalred() 
    479488            [47232, [1, 0, 0, 0], 2] 
    480489        """ 
    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: 
    483503                L = self._pari_mincurve.keys() 
    484504                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]) 
    495509        e = self.pari_curve(prec) 
    496510        mc, change = e.ellminimalmodel() 
    497511        self._pari_mincurve[prec] = mc 
  • a/sage/schemes/elliptic_curves/period_lattice.py

    old new  
    4141        sage: E.period_lattice().basis() 
    4242        (2.993458646231959629832009979452508177797583791370132985340523378563250356987, 2.451389381986790060854224831866525225349617289144796614656471406129152899999*I)    # 32-bit 
    4343        (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 
    4451        """ 
    4552        return tuple(self.E.pari_curve(prec).omega().python(precision=prec)) 
    4653