Ticket #14814: trac_14814_review.patch

File trac_14814_review.patch, 9.8 KB (added by chapoton, 8 years ago)
  • sage/rings/multi_power_series_ring_element.py

    # HG changeset patch
    # User Frederic Chapoton <chapoton at math.univ-lyon1.fr>
    # Date 1378928463 -7200
    # Node ID 309ccb993efad38c53dad6954721b7cd92cd7a41
    # Parent  886dc1657f93c05b9a3effd57e9d348250ab6819
    trac #14814 review patch (minor details)
    
    diff --git a/sage/rings/multi_power_series_ring_element.py b/sage/rings/multi_power_series_ring_element.py
    a b Substitution of power series with finite 
    9696
    9797Subs works as expected::
    9898
    99     sage: r0 = -t^2 - s*t^3 - 2*t^6 + s^7 + s^5*t^2 + R.O(10)   
     99    sage: r0 = -t^2 - s*t^3 - 2*t^6 + s^7 + s^5*t^2 + R.O(10)
    100100    sage: r1 = s^4 - s*t^4 + s^6*t - 4*s^2*t^5 - 6*s^3*t^5 + R.O(10)
    101101    sage: r2 = 2*s^3*t^2 - 2*s*t^4 - 2*s^3*t^4 + s*t^7 + R.O(10)
    102     sage: r0.subs({t:r2,s:r1}) 
     102    sage: r0.subs({t:r2,s:r1})
    103103    -4*s^6*t^4 + 8*s^4*t^6 - 4*s^2*t^8 + 8*s^6*t^6 - 8*s^4*t^8 - 4*s^4*t^9
    104104    + 4*s^2*t^11 - 4*s^6*t^8 + O(s, t)^15
    105105    sage: r0.subs({t:r2,s:r1}) == r0(r1,r2)
    Construct ring homomorphisms from one po 
    123123
    124124Inversion::
    125125
    126     sage: h = 1 + s + t + s*t + s^2*t^2 + 3*s^4 + 3*s^3*t + R.O(5); 
     126    sage: h = 1 + s + t + s*t + s^2*t^2 + 3*s^4 + 3*s^3*t + R.O(5);
    127127    sage: k = h^-1; k
    128128    1 - s - t + s^2 + s*t + t^2 - s^3 - s^2*t - s*t^2 - t^3 - 2*s^4 -
    129129    2*s^3*t + s*t^3 + t^4 + O(s, t)^5
    AUTHORS: 
    151151
    152152"""
    153153
    154    
    155154#*****************************************************************************
    156155#       Copyright (C) 2010 Niles Johnson <nilesj@gmail.com>
    157156#
    from sage.rings.power_series_ring_elemen 
    164163from sage.rings.polynomial.all import is_PolynomialRing
    165164from sage.rings.power_series_ring import is_PowerSeriesRing
    166165
    167 from sage.rings.all import ZZ
    168166from sage.rings.integer import Integer
    169167from sage.rings.finite_rings.integer_mod_ring import Zmod
    170168
    class MPowerSeries(PowerSeries): 
    292290        sage: R = PolynomialRing(ZZ,5,T.gens())
    293291        sage: t = R.gens()
    294292        sage: r = -t[2]*t[3] + t[3]^2 + t[4]^2
    295         sage: T(r) 
     293        sage: T(r)
    296294        -t2*t3 + t3^2 + t4^2
    297295        sage: r.parent()
    298296        Multivariate Polynomial Ring in t0, t1, t2, t3, t4 over Integer Ring
    class MPowerSeries(PowerSeries): 
    374372                # base rings do not match
    375373                self._bg_value = parent._bg_ps_ring(x)
    376374            else:
    377                 # x is a univariate power series, but not from the 
     375                # x is a univariate power series, but not from the
    378376                # background power series ring
    379377                #
    380378                # convert x to a polynomial and send to background
    class MPowerSeries(PowerSeries): 
    392390                #self._value = x
    393391                self._bg_value = parent._send_to_bg(x).add_bigoh(prec)
    394392            except (TypeError, AttributeError):
    395                 raise TypeError("Input does not coerce to any of the expected rings.")
     393                raise TypeError("Input does not coerce to any of the "
     394                                "expected rings.")
    396395
    397396        self._go_to_fg = parent._send_to_fg
    398397        self._prec = self._bg_value.prec()
    class MPowerSeries(PowerSeries): 
    789788        """
    790789        Return the trailing monomial of ``self``
    791790
     791        This is defined here as the lowest term of the underlying polynomial.
     792
    792793        EXAMPLE::
    793794
    794795            sage: R.<a,b,c> = PowerSeriesRing(ZZ)
    class MPowerSeries(PowerSeries): 
    809810
    810811    def quo_rem(self, other):
    811812        r"""
    812         Quotient and remainder for increassing power division
     813        Quotient and remainder for increasing power division
    813814
    814815        INPUT: ``other`` - an element of the same power series ring as ``self``
    815816
    class MPowerSeries(PowerSeries): 
    851852            ZeroDivisionError
    852853        """
    853854        if other.parent() is not self.parent():
    854             raise ValueError, "Don't know how to divide by a element of %s"%(other.parent())
     855            raise ValueError("Do not know how to divide by a element of %s" % (other.parent()))
    855856        other_tt = other.trailing_monomial()
    856857        if not other_tt:
    857858            raise ZeroDivisionError()
    858         mprec = min(self.prec(), other.prec())
    859859        rem = self.parent().zero().add_bigoh(self.prec())
    860860        quo = self.parent().zero().add_bigoh(self.prec()-other.valuation())
    861861        while self:
    class MPowerSeries(PowerSeries): 
    900900            sage: f/(a*f)
    901901            Traceback (most recent call last):
    902902            ...
    903             ValueError: Not divisible
     903            ValueError: not divisible
    904904
    905905        An example where one looses precision::
    906906
    class MPowerSeries(PowerSeries): 
    918918            return self*~denom_r
    919919        quo, rem = self.quo_rem(denom_r)
    920920        if rem:
    921             raise ValueError("Not divisible")
     921            raise ValueError("not divisible")
    922922        else:
    923923            return quo
    924924
    class MPowerSeries(PowerSeries): 
    932932        which there is a supported action on the base ring.
    933933
    934934        EXAMPLES::
    935        
     935
    936936            sage: R.<s,t> = PowerSeriesRing(ZZ); R
    937937            Multivariate Power Series Ring in s, t over Integer Ring
    938938            sage: f = 1 + t + s + s*t + R.O(3)
    class MPowerSeries(PowerSeries): 
    981981            return self.change_ring(Zmod(other))
    982982        raise NotImplementedError("Mod on multivariate power series ring elements not defined except modulo an integer.")
    983983
    984 
    985 
    986984    def dict(self):
    987985        """
    988986        Return underlying dictionary with keys the exponents and values the
    class MPowerSeries(PowerSeries): 
    10211019            sage: t = M.gens()
    10221020            sage: f = 1/2*t[0]^3*t[1]^3*t[2]^2 + 2/3*t[0]*t[2]^6*t[3] \
    10231021            - t[0]^3*t[1]^3*t[3]^3 - 1/4*t[0]*t[1]*t[2]^7 + M.O(10)
    1024             sage: f 
     1022            sage: f
    10251023            1/2*t0^3*t1^3*t2^2 + 2/3*t0*t2^6*t3 - t0^3*t1^3*t3^3
    10261024            - 1/4*t0*t1*t2^7 + O(t0, t1, t2, t3)^10
    10271025           
    class MPowerSeries(PowerSeries): 
    12161214        """
    12171215        return self.parent(self._bg_value.add_bigoh(prec))
    12181216
    1219 
    12201217    def O(self, prec):
    12211218        """
    12221219        Return a multivariate power series of total precision obtained
    class MPowerSeries(PowerSeries): 
    12521249            sage: t = M.gens()
    12531250            sage: f = 1/2*t[0]^3*t[1]^3*t[2]^2 + 2/3*t[0]*t[2]^6*t[3] \
    12541251            - t[0]^3*t[1]^3*t[3]^3 - 1/4*t[0]*t[1]*t[2]^7 + M.O(10)
    1255             sage: f 
     1252            sage: f
    12561253            1/2*t0^3*t1^3*t2^2 + 2/3*t0*t2^6*t3 - t0^3*t1^3*t3^3
    12571254            - 1/4*t0*t1*t2^7 + O(t0, t1, t2, t3)^10
    12581255
    class MPowerSeries(PowerSeries): 
    13401337            return True
    13411338        else:
    13421339            return False
    1343            
    1344        
     1340
    13451341    def degree(self):
    13461342        """
    13471343        Return degree of underlying polynomial of ``self``.
    class MPowerSeries(PowerSeries): 
    14851481            If the base ring is not a field (e.g. `ZZ`), or if it has a non
    14861482            zero characteristic, (e.g. `ZZ/3ZZ`), integration is not always
    14871483            possible, while staying with the same base ring. In the first
    1488             case, Sage will report that it hasn't been able to coerce some
     1484            case, Sage will report that it has not been able to coerce some
    14891485            coefficient to the base ring::
    14901486
    14911487                sage: T.<a,b> = PowerSeriesRing(ZZ,2)
    class MPowerSeries(PowerSeries): 
    15641560        R = P.base_ring()
    15651561        xx = P(xx)
    15661562        if not xx.is_gen():
    1567             for g in P.gens(): # try to find a generator equal to xx
     1563            for g in P.gens():  # try to find a generator equal to xx
    15681564                if g == xx:
    15691565                    xx = g
    15701566                    break
    15711567            else:
    1572                 raise ValueError, "%s is not a variable"%(xx)
     1568                raise ValueError("%s is not a variable" % xx)
    15731569        xxe = xx.exponents()[0]
    1574         pos = [i for i, c in enumerate(xxe) if c != 0][0] # get the position of the variable
    1575         res = { mon.eadd(xxe) : R(co / (mon[pos]+1)) for mon, co in self.dict().iteritems() }
     1570        pos = [i for i, c in enumerate(xxe) if c != 0][0]  # get the position of the variable
     1571        res = {mon.eadd(xxe): R(co / (mon[pos]+1))
     1572               for mon, co in self.dict().iteritems()}
    15761573        return P( res ).add_bigoh(self.prec()+1)
    15771574
    15781575    def ogf(self):
    class MPowerSeries(PowerSeries): 
    16601657        """
    16611658        raise NotImplementedError("variable not defined for multivariate power series; use 'variables' instead.")
    16621659   
    1663     def shift(self, n): 
     1660    def shift(self, n):
    16641661        """
    16651662        Doesn't make sense for multivariate power series.
    16661663       
    class MPowerSeries(PowerSeries): 
    17491746        OUTPUT:
    17501747       
    17511748        The exponentiated multivariate power series as a new
    1752         multivaritate power series.
     1749        multivariate power series.
    17531750       
    17541751        EXAMPLES::
    17551752
    class MPowerSeries(PowerSeries): 
    18381835          the result to.
    18391836
    18401837        OUTPUT:
    1841        
     1838
    18421839        The logarithm of the multivariate power series as a new
    1843         multivaritate power series.
    1844        
     1840        multivariate power series.
     1841
    18451842        EXAMPLES::
    18461843
    18471844            sage: T.<a,b> = PowerSeriesRing(ZZ,2)
    class MPowerSeries(PowerSeries): 
    18831880            a + O(a, b)^10
    18841881
    18851882            sage: log(1+a)
    1886             a - 1/2*a^2 + 1/3*a^3 - 1/4*a^4 + 1/5*a^5 - 1/6*a^6 + 1/7*a^7 
     1883            a - 1/2*a^2 + 1/3*a^3 - 1/4*a^4 + 1/5*a^5 - 1/6*a^6 + 1/7*a^7
    18871884            - 1/8*a^8 + 1/9*a^9 - 1/10*a^10 + 1/11*a^11 + O(a, b)^12
    18881885            sage: -log(1-a+T.O(5))
    18891886            a + 1/2*a^2 + 1/3*a^3 + 1/4*a^4 + O(a, b)^5
    class MO(object): 
    19861983        if self._vars != parent.gens():
    19871984            raise NotImplementedError
    19881985        return self._vars[0].parent()(0,prec)
    1989              
    1990