Ignore:
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • sage/functions/constants.py

    r1097 r1283  
    200200        return R.pi() 
    201201 
     202    def _real_double_(self): 
     203        return sage.rings.all.RD.pi() 
     204 
    202205    def __abs__(self): 
    203206        if self.str()[0] != '-': 
     
    260263        return Integer(2) 
    261264 
     265    def _real_double_(self): 
     266        return sage.rings.all.RD.e() 
     267 
    262268    # This just gives a string in singular anyways, and it's 
    263269    # *REALLY* slow! 
     
    284290    def _mpfr_(self,R): 
    285291        return R('NaN') #??? nan in mpfr: void mpfr_set_nan (mpfr_t x) 
     292 
     293    def _real_double_(self): 
     294        return sage.rings.all.RD.nan() 
    286295 
    287296NaN = NotANumber() 
     
    318327    def __float__(self): 
    319328        return float(0.5)*(float(1.0)+math.sqrt(float(5.0))) 
     329 
     330    def _real_double_(self): 
     331        """ 
     332        EXAMPLES: 
     333            sage: RealDoubleField()(golden_ratio) 
     334            1.61803398874989484820458 
     335        """ 
     336        return sage.rings.all.RDF(1.61803398874989484820458) 
    320337 
    321338    def _mpfr_(self,R):  #is this OK for _mpfr_ ? 
     
    368385        return math.log(2)  
    369386 
     387    def _real_double_(self): 
     388        """ 
     389        EXAMPLES: 
     390            sage: RealDoubleField()(log2) 
     391            0.69314718055994530941723212145817656808   # 64-bit 
     392        """ 
     393        return sage.rings.all.RD.log2() 
     394 
    370395    def _mpfr_(self,R): 
    371396        return R.log2() 
     
    407432        return R.euler_constant() 
    408433 
     434    def _real_double_(self): 
     435        """ 
     436        EXAMPLES: 
     437            sage: RealDoubleField()(euler_gamma) 
     438            0.57721566490153287 
     439        """ 
     440        return sage.rings.all.RD.euler() 
     441 
    409442    def floor(self): 
    410443        return Integer(0) 
     
    432465    def _mpfr_(self, R):   
    433466        return R.catalan_constant()  
     467 
     468    def _real_double_(self): 
     469        """ 
     470        EXAMPLES: 
     471            sage: RealDoubleField()(catalan) 
     472            0.91596559417721901 
     473        """ 
     474        return sage.rings.all.RDF(0.91596559417721901505460351493252) 
     475 
     476    def __float__(self): 
     477        """ 
     478        EXAMPLES: 
     479            sage: float(catalan) 
     480            0.91596559417721901 
     481        """ 
     482        return 0.91596559417721901505460351493252 
    434483 
    435484    def floor(self): 
     
    470519        raise NotImplementedError, "Khinchin's constant only available up to %s bits"%self.__bits 
    471520 
     521    def _real_double_(self): 
     522        """ 
     523        EXAMPLES: 
     524            sage: RealDoubleField()(khinchin) 
     525            2.6854520010653064453 
     526        """ 
     527        return sage.rings.all.RDF(2.685452001065306445309714835481795693820) 
     528 
     529 
    472530    def __float__(self):  
    473531        return 2.685452001065306445309714835481795693820 
     
    512570        raise NotImplementedError, "Twin Prime constant only available up to %s bits"%self.__bits 
    513571 
     572    def _real_double_(self): 
     573        """ 
     574        EXAMPLES: 
     575            sage: RealDoubleField()(twinprime) 
     576            0.66016181584686962 
     577        """ 
     578        return sage.rings.all.RDF(0.660161815846869573927812110014555778432) 
     579 
    514580    def __float__(self): 
    515581        """ 
     
    565631        raise NotImplementedError, "Merten's constant only available up to %s bits"%self.__bits 
    566632 
     633    def _real_double_(self): 
     634        """ 
     635        EXAMPLES: 
     636            sage: RealDoubleField()(merten) 
     637            0.261497212847642783755426838608695859051 
     638        """ 
     639        return sage.rings.all.RDF(0.261497212847642783755426838608695859051) 
     640 
    567641    def __float__(self): 
    568642        """ 
     
    620694        raise NotImplementedError, "Brun's constant only available up to %s bits"%self.__bits 
    621695 
     696    def _real_double_(self): 
     697        """ 
     698        EXAMPLES: 
     699            sage: RealDoubleField()(brun) 
     700            1.9021605831040 
     701        """ 
     702        return sage.rings.all.RDF(1.9021605831040) 
     703 
    622704    def __float__(self): 
    623705        """ 
  • sage/rings/all.py

    r1271 r1283  
    8080Reals = RealField 
    8181 
     82from real_double import RealDoubleField, RDF, RealDoubleElement 
     83 
    8284# Complex numbers 
    8385from complex_field import ComplexField, is_ComplexField, CC 
  • sage/rings/finite_field_element.py

    r924 r1287  
    141141        Return a square root of this finite field element in its 
    142142        finite field, if there is one.  Otherwise, raise a ValueError. 
     143 
     144        EXAMPLES: 
     145          sage: F = GF(7^2) 
     146          sage: F(2).square_root() 
     147          3 
     148          sage: F(3).square_root() 
     149          2*a + 6 
     150          sage: F(3).square_root()**2 
     151          3 
     152          sage: F(4).square_root() 
     153          2 
     154          sage: K = GF(7^3) 
     155          sage: K(3).square_root() 
     156          Traceback (most recent call last): 
     157          ... 
     158          ValueError: must be a perfect square. 
     159 
    143160        """ 
    144161        R = polynomial_ring.PolynomialRing(self.parent()) 
     
    146163        g = f.factor() 
    147164        if len(g) == 2 or g[0][1] == 2: 
    148             return -g[0][0] 
     165            return -g[0][0][0] 
    149166        raise ValueError, "must be a perfect square." 
    150167 
  • sage/schemes/elliptic_curves/ell_finite_field.py

    r1097 r1288  
    2222from ell_field import EllipticCurve_field 
    2323import sage.rings.ring as ring 
    24 from sage.rings.all import Integer 
     24from sage.rings.all import Integer, PolynomialRing 
    2525import gp_cremona 
    2626import sea 
     
    127127         
    128128    def __points_over_arbitrary_field(self): 
    129         # TODO -- rewrite this insanely stupid implementation!! 
    130         print "WARNING: Using very very stupid algorithm for finding points over" 
    131         print "non-prime finite field.  Please rewrite.  See the file ell_finite.field.py." 
    132         # The best way to rewrite is to extend Cremona's code (either gp or mwrank) so 
    133         # it works over non-prime fields (should be easy), then generate up the group. 
     129        # todo: This function used to have the following comment: 
     130 
     131        ### TODO -- rewrite this insanely stupid implementation!! 
     132        ### print "WARNING: Using very very stupid algorithm for finding points over" 
     133        ### print "non-prime finite field.  Please rewrite.  See the file ell_finite.field.py." 
     134        ### The best way to rewrite is to extend Cremona's code (either gp or mwrank) so 
     135        ### it works over non-prime fields (should be easy), then generate up the group. 
     136 
     137        # I changed the algorithm so that it's not as naive as it used to be. 
     138        # But it's still surely far from optimal; I don't know anything about 
     139        # point enumeration algorithms. -- David Harvey (2006-09-24) 
     140         
    134141        points = [self(0)] 
     142        R = PolynomialRing(self.base_ring()) 
     143        a1, a2, a3, a4, a6 = self.ainvs() 
    135144        for x in self.base_field(): 
    136             for y in self.base_field(): 
    137                 try: 
    138                     points.append(self([x,y])) 
    139                 except TypeError: 
    140                     pass 
     145            f = R([-(x**3 + a2*x**2 + a4*x + a6), (a1*x + a3), 1]) 
     146            factors = f.factor() 
     147            if len(factors) == 2 or factors[0][1] == 2: 
     148                for factor in factors: 
     149                    points.append(self([x, -factor[0][0]])) 
    141150        return points 
    142151 
     
    145154        All the points on this elliptic curve. 
    146155 
    147         If the base field is another other than $\FF_p$, this function currently 
    148         uses a VERY VERY naive algorithm.   The problem is that Cremona's gp 
    149         script \code{ell_zp.gp} currently only treats the case of prime fields. 
    150         If you need more general functionality, please volunteer to implement 
    151         it, either by extending \code{ell_zp.gp} (if you know PARI/GP well) or 
    152         by writing new \sage code. 
     156        EXAMPLES: 
     157          sage: p = 5 
     158          sage: F = GF(p) 
     159          sage: E = EllipticCurve(F, [1, 3]) 
     160          sage: a_sub_p = E.change_ring(QQ).ap(p); a_sub_p 
     161          2 
     162 
     163          sage: len(E.points()) 
     164          4 
     165          sage: p + 1 - a_sub_p 
     166          4 
     167          sage: E.points() 
     168          [(0 : 1 : 0), (4 : 1 : 1), (1 : 0 : 1), (4 : 4 : 1)] 
     169 
     170          sage: K = GF(p**2) 
     171          sage: E = E.change_ring(K) 
     172          sage: len(E.points()) 
     173          32 
     174          sage: (p + 1)**2 - a_sub_p**2 
     175          32 
     176          sage: E.points() 
     177          [(0 : 1 : 0), 
     178           (0 : 2*a + 4 : 1), 
     179           (0 : 3*a + 1 : 1), 
     180           (1 : 0 : 1), 
     181           (2 : 2*a + 4 : 1), 
     182           (2 : 3*a + 1 : 1), 
     183           (3 : 2*a + 4 : 1), 
     184           (3 : 3*a + 1 : 1), 
     185           (4 : 1 : 1), 
     186           (4 : 4 : 1), 
     187           (a : 1 : 1), 
     188           (a : 4 : 1), 
     189           (a + 2 : a + 1 : 1), 
     190           (a + 2 : 4*a + 4 : 1), 
     191           (a + 3 : a : 1), 
     192           (a + 3 : 4*a : 1), 
     193           (a + 4 : 0 : 1), 
     194           (2*a : 2*a : 1), 
     195           (2*a : 3*a : 1), 
     196           (2*a + 4 : a + 1 : 1), 
     197           (2*a + 4 : 4*a + 4 : 1), 
     198           (3*a + 1 : a + 3 : 1), 
     199           (3*a + 1 : 4*a + 2 : 1), 
     200           (3*a + 2 : 2*a + 3 : 1), 
     201           (3*a + 2 : 3*a + 2 : 1), 
     202           (4*a : 0 : 1), 
     203           (4*a + 1 : 1 : 1), 
     204           (4*a + 1 : 4 : 1), 
     205           (4*a + 3 : a + 3 : 1), 
     206           (4*a + 3 : 4*a + 2 : 1), 
     207           (4*a + 4 : a + 4 : 1), 
     208           (4*a + 4 : 4*a + 1 : 1)] 
     209            
    153210        """ 
    154211        try: 
     
    191248        return q + 1 - self.cardinality() 
    192249 
    193     def cardinality(self, algorithm='heuristic', early_abort=False): 
     250    def cardinality(self, algorithm='heuristic', early_abort=False, disable_warning=False): 
    194251        r""" 
    195252        Return the number of points on this elliptic curve over this 
     
    197254         
    198255        \note{If the cardinality of the base field is not prime, this 
    199         function currently uses a very very naive enumeration of all 
    200         points.  It's so stupid, that it prints a warning.} 
     256        function literally enumerates the points and counts them. It's so 
     257        stupid, it prints a warning. You can disable the warning with the 
     258        disable_warning flag.} 
    201259 
    202260        INPUT: 
     
    221279        EXAMPLES: 
    222280            sage: EllipticCurve(GF(4),[1,2,3,4,5]).cardinality() 
    223             WARNING: Using very very stupid algorithm for finding points over 
    224             non-prime finite field.  Please rewrite.  See the file ell_finite.field.py. 
     281            WARNING: Using very very stupid algorithm for counting 
     282            points over non-prime finite field. Please rewrite. 
     283            See the file ell_finite_field.py. 
    225284            8 
    226285            sage: EllipticCurve(GF(9),[1,2,3,4,5]).cardinality() 
    227             WARNING: Using very very stupid algorithm for finding points over 
    228             non-prime finite field.  Please rewrite.  See the file ell_finite.field.py. 
     286            WARNING: Using very very stupid algorithm for counting 
     287            points over non-prime finite field. Please rewrite. 
     288            See the file ell_finite_field.py. 
    229289            16 
    230290            sage: EllipticCurve(GF(10007),[1,2,3,4,5]).cardinality() 
     
    260320                 
    261321        if N == 0: 
     322            if not disable_warning: 
     323                print "WARNING: Using very very stupid algorithm for counting " 
     324                print "points over non-prime finite field. Please rewrite." 
     325                print "See the file ell_finite_field.py." 
    262326            N = len(self.points()) 
    263327        self.__cardinality = Integer(N) 
  • sage/schemes/elliptic_curves/ell_generic.py

    r1169 r1290  
    559559 
    560560 
     561    def pseudo_torsion_polynomial(self, n, x=None, cache=None): 
     562        r""" 
     563        Returns the n-th torsion polynomial (division polynomial), without 
     564        the 2-torsion factor if n is even, as a polynomial in $x$. 
     565 
     566        These are the polynomials $g_n$ defined in Mazur/Tate (``The p-adic 
     567        sigma function''), but with the sign flipped for even $n$, so that 
     568        the leading coefficient is always positive. 
     569 
     570        The full torsion polynomials may be recovered as follows: 
     571        \begin{itemize} 
     572        \item $\psi_n = g_n$ for odd $n$. 
     573        \item $\psi_n = (2y + a_1 x + a_3) g_n$ for even $n$. 
     574        \end{itemize} 
     575 
     576        Note that the $g_n$'s are always polynomials in $x$, whereas the 
     577        $\psi_n$'s require the appearance of a $y$. 
     578 
     579        SEE ALSO: 
     580            -- torsion_polynomial() 
     581            -- multiple_x_numerator() 
     582            -- multiple_x_denominator() 
     583 
     584        INPUT: 
     585            n -- positive integer, or the special values -1 and -2 which 
     586                 mean $B_6 = (2y + a_1 x + a_3)^2$ and $B_6^2$ respectively 
     587                 (in the notation of Mazur/Tate). 
     588            x -- optional ring element to use as the "x" variable. If x 
     589                 is None, then a new polynomial ring will be constructed over 
     590                 the base ring of the elliptic curve, and its generator will 
     591                 be used as x. Note that x does not need to be a generator of 
     592                 a polynomial ring; any ring element is ok. This permits fast 
     593                 calculation of the torsion polynomial *evaluated* on any 
     594                 element of a ring. 
     595            cache -- optional dictionary, with integer keys. If the key m 
     596                 is in cache, then cache[m] is assumed to be the value of 
     597                 pseudo_torsion_polynomial(m) for the supplied x. New entries 
     598                 will be added to the cache as they are computed. 
     599 
     600        ALGORITHM: 
     601            -- Recursion described in Mazur/Tate. The recursive formulae are 
     602            evaluated $O((log n)^2)$ times. 
     603 
     604        TODO: 
     605            -- for better unity of code, it might be good to make the regular 
     606            torsion_polynomial() function use this as a subroutine. 
     607 
     608        AUTHORS: 
     609            -- David Harvey (2006-09-24) 
     610 
     611        EXAMPLES: 
     612           sage: E = EllipticCurve("37a") 
     613           sage: E.pseudo_torsion_polynomial(1) 
     614           1 
     615           sage: E.pseudo_torsion_polynomial(2) 
     616           1 
     617           sage: E.pseudo_torsion_polynomial(3) 
     618           3*x^4 - 6*x^2 + 3*x - 1 
     619           sage: E.pseudo_torsion_polynomial(4) 
     620           2*x^6 - 10*x^4 + 10*x^3 - 10*x^2 + 2*x + 1 
     621           sage: E.pseudo_torsion_polynomial(5) 
     622           5*x^12 - 62*x^10 + 95*x^9 - 105*x^8 - 60*x^7 + 285*x^6 - 174*x^5 - 5*x^4 - 5*x^3 + 35*x^2 - 15*x + 2 
     623           sage: E.pseudo_torsion_polynomial(6) 
     624           3*x^16 - 72*x^14 + 168*x^13 - 364*x^12 + 1120*x^10 - 1144*x^9 + 300*x^8 - 540*x^7 + 1120*x^6 - 588*x^5 - 133*x^4 + 252*x^3 - 114*x^2 + 22*x - 1 
     625           sage: E.pseudo_torsion_polynomial(7) 
     626           7*x^24 - 308*x^22 + 986*x^21 - 2954*x^20 + 28*x^19 + 17171*x^18 - 23142*x^17 + 511*x^16 - 5012*x^15 + 43804*x^14 - 7140*x^13 - 96950*x^12 + 111356*x^11 - 19516*x^10 - 49707*x^9 + 40054*x^8 - 124*x^7 - 18382*x^6 + 13342*x^5 - 4816*x^4 + 1099*x^3 - 210*x^2 + 35*x - 3 
     627           sage: E.pseudo_torsion_polynomial(8) 
     628           4*x^30 - 292*x^28 + 1252*x^27 - 5436*x^26 + 2340*x^25 + 39834*x^24 - 79560*x^23 + 51432*x^22 - 142896*x^21 + 451596*x^20 - 212040*x^19 - 1005316*x^18 + 1726416*x^17 - 671160*x^16 - 954924*x^15 + 1119552*x^14 + 313308*x^13 - 1502818*x^12 + 1189908*x^11 - 160152*x^10 - 399176*x^9 + 386142*x^8 - 220128*x^7 + 99558*x^6 - 33528*x^5 + 6042*x^4 + 310*x^3 - 406*x^2 + 78*x - 5 
     629 
     630           sage: E.pseudo_torsion_polynomial(18) % E.pseudo_torsion_polynomial(6) == 0 
     631           True 
     632 
     633          An example to illustrate the relationship with torsion points. 
     634           sage: F = GF(11) 
     635           sage: E = EllipticCurve(F, [0, 2]); E 
     636           Elliptic Curve defined by y^2  = x^3 + 2 over Finite Field of size 11 
     637           sage: f = E.pseudo_torsion_polynomial(5); f 
     638           5*x^12 + x^9 + 8*x^6 + 4*x^3 + 7 
     639           sage: f.factor() 
     640           (5) * (x^2 + 5) * (x^2 + 2*x + 5) * (x^2 + 5*x + 7) * (x^2 + 7*x + 7) * (x^2 + 9*x + 5) * (x^2 + 10*x + 7) 
     641 
     642          This indicates that the x-coordinates of all the 5-torsion points 
     643          of E are in GF(11^2), and therefore the y-coordinates are in 
     644          GF(11^4). 
     645           sage: K = GF(11^4) 
     646           sage: X = E.change_ring(K) 
     647           sage: f = X.pseudo_torsion_polynomial(5) 
     648           sage: x_coords = [root for (root, _) in f.roots()]; x_coords 
     649            [a^3 + 7*a^2 + 6*a, 
     650             2*a^3 + 3*a^2 + a + 7, 
     651             3*a^3 + 10*a^2 + 7*a + 1, 
     652             3*a^3 + 10*a^2 + 7*a + 3, 
     653             3*a^3 + 10*a^2 + 7*a + 8, 
     654             5*a^3 + 2*a^2 + 8*a + 7, 
     655             6*a^3 + 9*a^2 + 3*a + 4, 
     656             8*a^3 + a^2 + 4*a + 4, 
     657             8*a^3 + a^2 + 4*a + 8, 
     658             8*a^3 + a^2 + 4*a + 10, 
     659             9*a^3 + 8*a^2 + 10*a + 8, 
     660             10*a^3 + 4*a^2 + 5*a + 6] 
     661            
     662          Now we check that these are exactly the x coordinates of the 
     663          5-torsion points of E. 
     664           sage: for x in x_coords: 
     665           ...       y = (x**3 + 2).square_root() 
     666           ...       P = X([x, y]) 
     667           ...       assert P.order(disable_warning=True) == 5 
     668 
     669          todo: need to show an example where the 2-torsion is missing 
     670 
     671        """ 
     672        if cache is None: 
     673            cache = {} 
     674        else: 
     675            try: 
     676                return cache[n] 
     677            except KeyError: 
     678                pass 
     679 
     680        if x is None: 
     681            x = rings.PolynomialRing(self.base_ring()).gen() 
     682 
     683        b2, b4, b6, b8 = self.b_invariants() 
     684 
     685        n = int(n) 
     686        if n <= 4: 
     687            if n == -1: 
     688                answer = 4*x**3 + b2*x**2 + 2*b4*x + b6 
     689            elif n == -2: 
     690                answer = self.pseudo_torsion_polynomial(-1, x, cache) ** 2 
     691            elif n == 1 or n == 2: 
     692                answer = x.parent()(1) 
     693            elif n == 3: 
     694                answer = 3*x**4 + b2*x**3 + 3*b4*x**2 + 3*b6*x + b8 
     695            elif n == 4: 
     696                answer = -self.pseudo_torsion_polynomial(-2, x, cache) + \ 
     697                         (6*x**2 + b2*x + b4) * \ 
     698                         self.pseudo_torsion_polynomial(3, x, cache) 
     699            else: 
     700                raise ValueError, "n must be a positive integer (or -1 or -2)" 
     701        else: 
     702            if n % 2 == 0: 
     703                m = (n-2) // 2 
     704                g_mplus3 = self.pseudo_torsion_polynomial(m+3, x, cache) 
     705                g_mplus2 = self.pseudo_torsion_polynomial(m+2, x, cache) 
     706                g_mplus1 = self.pseudo_torsion_polynomial(m+1, x, cache) 
     707                g_m      = self.pseudo_torsion_polynomial(m,   x, cache) 
     708                g_mless1 = self.pseudo_torsion_polynomial(m-1, x, cache) 
     709                answer = g_mplus1 * \ 
     710                         (g_mplus3 * g_m**2 - g_mless1 * g_mplus2**2) 
     711            else: 
     712                m = (n-1) // 2 
     713                g_mplus2 = self.pseudo_torsion_polynomial(m+2, x, cache) 
     714                g_mplus1 = self.pseudo_torsion_polynomial(m+1, x, cache) 
     715                g_m      = self.pseudo_torsion_polynomial(m,   x, cache) 
     716                g_mless1 = self.pseudo_torsion_polynomial(m-1, x, cache) 
     717                B6_sqr   = self.pseudo_torsion_polynomial(-2, x, cache) 
     718                if m % 2 == 0: 
     719                    answer = B6_sqr * g_mplus2 * g_m**3 - \ 
     720                             g_mless1 * g_mplus1**3 
     721                else: 
     722                    answer = g_mplus2 * g_m**3 - \ 
     723                             B6_sqr * g_mless1 * g_mplus1**3 
     724 
     725        cache[n] = answer 
     726        return answer 
     727 
     728 
     729    def multiple_x_numerator(self, n, x=None, cache=None): 
     730        r""" 
     731        Returns the numerator of the x-coordinate of the nth multiple of 
     732        a point, using torsion polynomials (division polynomials). 
     733 
     734        The inputs n, x, cache are as described in pseudo_torsion_polynomial(). 
     735 
     736        The result is adjusted to be correct for both even and odd n. 
     737 
     738        WARNING: 
     739          -- There may of course be cancellation between the numerator and 
     740          the denominator (multiple_x_denominator()). Be careful. For more 
     741          information on how to avoid cancellation, see Christopher Wuthrich's 
     742          thesis. 
     743 
     744        SEE ALSO: 
     745          -- multiple_x_denominator() 
     746 
     747        AUTHORS: 
     748           -- David Harvey (2006-09-24) 
     749 
     750        EXAMPLES: 
     751          sage: E = EllipticCurve("37a") 
     752          sage: P = E.gens()[0] 
     753          sage: x = P[0] 
     754 
     755          sage: (35*P)[0] 
     756          -804287518035141565236193151/1063198259901027900600665796 
     757          sage: E.multiple_x_numerator(35, x) 
     758          -804287518035141565236193151 
     759          sage: E.multiple_x_denominator(35, x) 
     760          1063198259901027900600665796 
     761 
     762          sage: (36*P)[0] 
     763          54202648602164057575419038802/15402543997324146892198790401 
     764          sage: E.multiple_x_numerator(36, x) 
     765          54202648602164057575419038802 
     766          sage: E.multiple_x_denominator(36, x) 
     767          15402543997324146892198790401 
     768 
     769        An example where cancellation occurs: 
     770          sage: E = EllipticCurve("88a1") 
     771          sage: P = E.gens()[0] 
     772          sage: n = E.multiple_x_numerator(11, P[0]); n 
     773          442446784738847563128068650529343492278651453440 
     774          sage: d = E.multiple_x_denominator(11, P[0]); d 
     775          1427247692705959881058285969449495136382746624 
     776          sage: n/d 
     777          310 
     778          sage: 11*P 
     779          (310 : -5458 : 1) 
     780           
     781        """ 
     782        if cache is None: 
     783            cache = {} 
     784 
     785        if x is None: 
     786            x = rings.PolynomialRing(self.base_ring()).gen() 
     787 
     788        n = int(n) 
     789        if n < 2: 
     790            print "n must be at least 2" 
     791 
     792        self.pseudo_torsion_polynomial( -2, x, cache) 
     793        self.pseudo_torsion_polynomial(n-1, x, cache) 
     794        self.pseudo_torsion_polynomial(n  , x, cache) 
     795        self.pseudo_torsion_polynomial(n+1, x, cache) 
     796 
     797        if n % 2 == 0: 
     798            return x * cache[-1] * cache[n]**2 - cache[n-1] * cache[n+1] 
     799        else: 
     800            return x * cache[n]**2 - cache[-1] * cache[n-1] * cache[n+1] 
     801 
     802 
     803    def multiple_x_denominator(self, n, x=None, cache=None): 
     804        r""" 
     805        Returns the denominator of the x-coordinate of the nth multiple of 
     806        a point, using torsion polynomials (division polynomials). 
     807 
     808        The inputs n, x, cache are as described in pseudo_torsion_polynomial(). 
     809 
     810        The result is adjusted to be correct for both even and odd n. 
     811 
     812        SEE ALSO: 
     813          -- multiple_x_numerator() 
     814 
     815        TODO: the numerator and denominator versions share a calculation, 
     816        namely squaring $\psi_n$. Maybe would be good to offer a combined 
     817        version to make this more efficient. 
     818 
     819        EXAMPLES: 
     820           -- see multiple_x_numerator() 
     821 
     822        AUTHORS: 
     823           -- David Harvey (2006-09-24) 
     824 
     825        """ 
     826        if cache is None: 
     827            cache = {} 
     828 
     829        if x is None: 
     830            x = rings.PolynomialRing(self.base_ring()).gen() 
     831 
     832        n = int(n) 
     833        if n < 2: 
     834            print "n must be at least 2" 
     835 
     836        self.pseudo_torsion_polynomial(-2, x, cache) 
     837        self.pseudo_torsion_polynomial(n , x, cache) 
     838 
     839        if n % 2 == 0: 
     840            return cache[-1] * cache[n]**2 
     841        else: 
     842            return cache[n]**2 
     843 
     844 
    561845    def torsion_polynomial(self, n, i=0): 
    562846        """ 
     
    570854            Polynomial -- n-th torsion polynomial, which is a polynomial over 
    571855                          the base field of the elliptic curve.  
     856 
     857        SEE ALSO: 
     858            pseudo_torsion_polynomial() 
    572859 
    573860        EXAMPLES: 
  • sage/schemes/elliptic_curves/ell_point.py

    r1097 r1289  
    286286 
    287287class EllipticCurvePoint_finite_field(EllipticCurvePoint_field): 
    288     def order(self): 
     288    def order(self, disable_warning=False): 
    289289        """ 
    290290        Return the order of this point on the elliptic curve. 
     
    315315            self.__order = rings.Integer(e.ellzppointorder(list(self.xy()))) 
    316316        else: 
    317             print "WARNING -- using naive point order finding over finite field!" 
     317            if not disable_warning: 
     318                print "WARNING -- using naive point order finding over finite field!" 
    318319            # TODO: This is very very naive!!  -- should use baby-step giant step; maybe in mwrank 
    319320            #      note that this is *not* implemented in PARI! 
  • sage/server/notebook/notebook.py

    r1184 r1285  
    330330import shutil 
    331331import socket 
     332import re           # regular expressions 
    332333 
    333334# SAGE libraries 
     
    454455        os.system(cmd) 
    455456        D = os.listdir(tmp)[0] 
     457        worksheet = load('%s/%s/%s.sobj'%(tmp,D,D), compress=False) 
     458        names = self.worksheet_names() 
     459        if D in names: 
     460            m = re.match('.*?([0-9]+)$',D) 
     461            if m is None: 
     462                n = 0 
     463            else: 
     464                n = int(m.groups()[0]) 
     465            while "%s%d"%(D,n) in names: 
     466                n += 1 
     467            cmd = 'mv %s/%s/%s.sobj %s/%s/%s%d.sobj'%(tmp,D,D,tmp,D,D,n) 
     468            print cmd 
     469            os.system(cmd) 
     470            cmd = 'mv %s/%s %s/%s%d'%(tmp,D,tmp,D,n) 
     471            print cmd 
     472            os.system(cmd) 
     473            D = "%s%d"%(D,n) 
     474            worksheet.set_name(D) 
    456475        print D 
    457         worksheet = load('%s/%s/%s.sobj'%(tmp,D,D), compress=False) 
    458476        S = self.__worksheet_dir  
    459477        cmd = 'rm -rf "%s/%s"'%(S,D) 
     
    10551073             jsmath      = True, 
    10561074             show_debug  = False, 
    1057              warn        = True): 
     1075             warn        = True, 
     1076             ignore_lock = False): 
    10581077    r""" 
    10591078    Start a SAGE notebook web server at the given port. 
     
    11301149        if not (os.path.exists('%s/nb.sobj'%dir) or os.path.exists('%s/nb-backup.sobj'%dir)): 
    11311150            raise RuntimeError, '"%s" is not a valid SAGE notebook directory (missing nb.sobj).'%dir 
     1151        if os.path.exists('%s/pid'%dir) and not ignore_lock: 
     1152            f = file('%s/pid'%dir) 
     1153            p = f.read() 
     1154            f.close() 
     1155            try: 
     1156                #This is a hack to check whether or not the process is running. 
     1157                os.kill(int(p),0) 
     1158                print "\n".join([" This notebook appears to be running with PID %s.  If it is"%p, 
     1159                                 " not responding, you will need to kill that process to continue.", 
     1160                                 " If another (non-sage) process is running with that PID, call", 
     1161                                 " notebook(..., ignore_lock = True, ...). " ]) 
     1162                return 
     1163            except OSError: 
     1164                pass 
     1165        f = file('%s/pid'%dir, 'w') 
     1166        f.write("%d"%os.getpid()) 
     1167        f.close() 
    11321168        try: 
    11331169            nb = load('%s/nb.sobj'%dir, compress=False) 
     
    11671203    from sage.misc.misc import delete_tmpfiles 
    11681204    delete_tmpfiles() 
     1205    os.remove('%s/pid'%dir) 
    11691206    return nb 
    11701207     
  • sage/server/notebook/worksheet.py

    r1184 r1285  
    1919import traceback 
    2020import time 
    21  
     21import crypt 
    2222import pexpect 
    2323 
     
    5050        self.__name = name 
    5151        self.__notebook = notebook 
    52         self.__passcode = passcode 
     52        self.__passcode = crypt.crypt(passcode, self.__salt) 
     53        self.__passcrypt= True 
    5354        dir = list(name) 
    5455        for i in range(len(dir)): 
     
    8384                C.set_worksheet(self) 
    8485 
     86    def salt(self): 
     87        try: 
     88            return self.__salt 
     89        except AttributeError: 
     90            self.__salt = "%f"%time.time() 
     91            return self.__salt 
     92 
    8593    def passcode(self): 
    8694        try: 
     95            c = self.__passcrypt 
     96        except AttributeError: 
     97            self.__passcrypt = False 
     98        try: 
     99            if not self.__passcrypt: 
     100                self.__passcode = crypt.crypt(self.__passcode, self.salt()) 
     101                self.__passcrypt = True 
    87102            return self.__passcode 
    88103        except AttributeError: 
    89             self.__passcode = '' 
    90             return '' 
     104            self.__passcode = crypt.crypt(self.__passcode, self.salt()) 
     105            self.__passcrypt = True 
     106            return self.__passcode 
    91107 
    92108    def filename(self): 
     
    546562 
    547563    def auth(self, passcode): 
    548         if self.passcode() == '': 
    549             return True 
    550         else: 
    551             return self.passcode() == passcode 
     564        return self.passcode() == crypt.crypt(passcode, self.__salt) 
    552565 
    553566    def _strip_synchro_from_start_of_output(self, s): 
     
    10111024        return self.__name 
    10121025 
     1026    def set_name(self, name): 
     1027        self.__name = name 
     1028 
    10131029    def append(self, L): 
    10141030        self.__cells.append(L) 
  • setup.py

    r1292 r1293  
    164164                libraries = ['gsl', CBLAS]) 
    165165 
     166real_double = Extension('sage.rings.real_double', 
     167                ['sage/rings/real_double.pyx'], 
     168                libraries = ['gsl', CBLAS]) 
     169 
    166170complex_double = Extension('sage.rings.complex_double', 
    167171                           ['sage/rings/complex_double.pyx'], 
     
    195199    gsl_interpolation, 
    196200    gsl_callback, 
     201    real_double, 
    197202    complex_double, 
    198203 
Note: See TracChangeset for help on using the changeset viewer.