Ticket #6998: trac_6998.patch

File trac_6998.patch, 3.9 KB (added by mhansen, 4 years ago)
  • sage/rings/power_series_ring_element.pyx

    # HG changeset patch
    # User Mike Hansen <mhansen@gmail.com>
    # Date 1253772680 -25200
    # Node ID decc9de9e3a2406d0d1ebdd5940b316fe3e05117
    # Parent  a185c21a1957d29c2787cf660680ce378e3d86fb
    [mq]: trac_6998.patch
    
    diff --git a/sage/rings/power_series_ring_element.pyx b/sage/rings/power_series_ring_element.pyx
    a b  
    10811081            except TypeError: 
    10821082                return False 
    10831083     
    1084     def sqrt(self, prec=None, extend=False, 
    1085              all=False, name=None): 
    1086         r""" 
    1087         The square root function. 
     1084    def sqrt(self, prec=None, extend=False, all=False, name=None): 
     1085        r""" The square root function. 
    10881086         
    10891087        INPUT: 
    10901088         
    1091           - prec - integer (default: None): if not None and the series has 
    1092             infinite precision, truncates series at precision prec. 
     1089          - prec - integer (default: None): if not None and the series 
     1090            has infinite precision, truncates series at precision 
     1091            prec. 
    10931092 
    1094           - extend - bool (default: False); if True, return a square root in an 
    1095             extension ring, if necessary. Otherwise, raise a ValueError if the 
    1096             square is not in the base power series ring. For example, if extend 
    1097             is True the square root of a power series with odd degree leading 
    1098             coefficient is defined as an element of a formal extension ring. 
     1093          - extend - bool (default: False); if True, return a square 
     1094            root in an extension ring, if necessary. Otherwise, raise 
     1095            a ValueError if the square is not in the base power series 
     1096            ring. For example, if extend is True the square root of a 
     1097            power series with odd degree leading coefficient is 
     1098            defined as an element of a formal extension ring. 
    10991099 
    1100           - name - if extend is True, you must also specify the print name of 
    1101             the formal square root.  
     1100          - name - if extend is True, you must also specify the print 
     1101            name of the formal square root. 
    11021102 
    1103           - all - bool (default: False); if True, return 
    1104             all square roots of self, instead of just one. 
     1103          - all - bool (default: False); if True, return all square 
     1104            roots of self, instead of just one. 
    11051105         
    11061106        ALGORITHM: Newton's method 
    11071107         
    11081108        .. math:: 
    11091109         
    1110                              x_{i+1} = \frac{1}{2}( x_i + self/x_i )              
    1111          
    1112          
    1113          
     1110           x_{i+1} = \frac{1}{2}( x_i + self/x_i )              
     1111 
    11141112        EXAMPLES:: 
    11151113         
    11161114            sage: K.<t> = PowerSeriesRing(QQ, 't', 5) 
     
    11561154            sage: s^2 
    11571155            2*t + t^3 + O(t^4) 
    11581156            sage: parent(s) 
    1159             Univariate Quotient Polynomial Ring in sqrtf over Power Series Ring in t over Rational Field with modulus x^2 - 2*t - t^3 + O(t^4)             
     1157            Univariate Quotient Polynomial Ring in sqrtf over Power Series Ring in t over Rational Field with modulus x^2 - 2*t - t^3 + O(t^4) 
     1158 
     1159        TESTS:: 
     1160 
     1161            sage: R.<x> = QQ[[]] 
     1162            sage: (x^10/2).sqrt() 
     1163            Traceback (most recent call last): 
     1164            ... 
     1165            ValueError: unable to take the square root of 1/2 
    11601166         
    11611167        AUTHORS: 
    11621168 
     
    11931199                    return a 
    11941200 
    11951201        val = self.valuation() 
     1202         
    11961203        if formal_sqrt or val % 2 == 1: 
    11971204            if extend: 
    11981205                if name is None: 
     
    12061213                    return [a, -a] 
    12071214                else: 
    12081215                    return a 
     1216            elif formal_sqrt: 
     1217                raise ValueError, "unable to take the square root of %s"%u[0] 
    12091218            else: 
    12101219                raise ValueError, "power series does not have a square root since it has odd valuation." 
     1220                 
    12111221         
    12121222        pr = self.prec() 
    12131223        if pr == infinity: