Ignore:
Timestamp:
04/22/07 12:57:28 (6 years ago)
Author:
William Stein <wstein@…>
Branch:
default
Message:

Fix a bunch of issues with ring morphisms and loads/dumps

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sage/rings/rational.pyx

    r4022 r4057  
    368368        return self.numerator().valuation(p) - self.denominator().valuation(p) 
    369369     
    370     def sqrt(self, bits=None): 
     370    def sqrt_approx(self, bits=None): 
    371371        r""" 
    372372        Returns the positive square root of self as a real number to 
     
    385385        EXAMPLES: 
    386386            sage: x = 23/2 
    387             sage: x.sqrt() 
     387            sage: x.sqrt_approx() 
    388388            3.39116499156263 
    389389            sage: x = 32/5 
    390             sage: x.sqrt() 
     390            sage: x.sqrt_approx() 
    391391            2.52982212813470 
    392392            sage: x = 16/9 
    393             sage: x.sqrt() 
    394             4/3 
    395             sage: x.sqrt(53) 
     393            sage: x.sqrt_approx() 
    396394            1.33333333333333 
     395            sage: x.sqrt_approx(100) 
     396            1.3333333333333333333333333333 
    397397            sage: x = 9837/2 
    398             sage: x.sqrt() 
     398            sage: x.sqrt_approx() 
    399399            70.1320183653658 
    400400            sage: x = 645373/45 
    401             sage: x.sqrt() 
     401            sage: x.sqrt_approx() 
    402402            119.756512233040 
    403403            sage: x = -12/5 
    404             sage: x.sqrt() 
     404            sage: x.sqrt_approx() 
    405405            1.54919333848297*I 
    406406 
     
    409409        """ 
    410410        if bits is None: 
    411             try: 
    412                 return self.square_root() 
    413             except ValueError: 
    414                 pass 
    415411            bits = max(53, 2*(mpz_sizeinbase(self.value, 2)+2)) 
    416412             
     
    422418            return R(self).sqrt() 
    423419 
    424     def square_root(self): 
     420    def sqrt(self): 
    425421        r""" 
    426422        Return the positive rational square root of self, or raises a 
     
    429425        EXAMPLES: 
    430426            sage: x = 125/5 
    431             sage: x.square_root() 
     427            sage: x.sqrt() 
    432428            5 
    433429            sage: x = 64/4 
    434             sage: x.square_root() 
     430            sage: x.sqrt() 
    435431            4 
    436432            sage: x = 1000/10 
    437             sage: x.square_root() 
     433            sage: x.sqrt() 
    438434            10 
    439435            sage: x = 81/3 
    440             sage: x.square_root() 
    441             Traceback (most recent call last): 
    442             ... 
    443             ValueError: self (=27) is not a perfect square 
     436            sage: x.sqrt() 
     437            3*sqrt(3) 
     438            sage: x = -81/3 
     439            sage: x.sqrt() 
     440            3*sqrt(3)*I 
    444441 
    445442        AUTHOR: 
    446             -- Naqi Jaffery (2006-03-05): examples 
    447         """ 
     443            -- Naqi Jaffery (2006-03-05): some examples 
     444        """ 
     445        if self < 0: 
     446            from sage.calculus.calculus import sqrt 
     447            return sqrt(self) 
    448448        # TODO -- this could be quicker, by using GMP directly. 
    449         return self.numerator().square_root() / self.denominator().square_root() 
     449        return self.numerator().sqrt() / self.denominator().sqrt() 
    450450 
    451451    def period(self): 
     
    694694            32/243 
    695695            sage: (-1/1)^(1/3) 
    696             Traceback (most recent call last): 
    697             ... 
    698             TypeError: exponent (=1/3) must be an integer. 
    699             Coerce your numbers to real or complex numbers first. 
     696            -1 
    700697 
    701698        We raise to some interesting powers: 
     
    11121109    def is_zero(self): 
    11131110        return bool(mpz_cmp_si(mpq_numref(self.value), 0) == 0) 
     1111 
     1112    def is_square(self): 
     1113        return self.numerator().is_square() and self.denominator().is_square() 
    11141114     
    11151115    cdef _lshift(self, long int exp): 
Note: See TracChangeset for help on using the changeset viewer.