Ticket #8972: 8972_power_series_inverses.patch

File 8972_power_series_inverses.patch, 4.0 KB (added by SimonKing, 13 years ago)

Bugfixes for fraction field and inverses of power series over non-fields

  • sage/rings/laurent_series_ring.py

    # HG changeset patch
    # User Simon King <simon.king@nuigalway.ie>
    # Date 1273951205 -3600
    # Node ID afbcfe01027852f6b4ba28a411ab08c4a59c20fc
    # Parent  b863b0bd2d339b2740caf20783aabf3832531de8
    Fixing various errors related with inverses of power series.
    
    diff -r b863b0bd2d33 -r afbcfe010278 sage/rings/laurent_series_ring.py
    a b  
    4646        sage: Frac(GF(5)['y'])
    4747        Fraction Field of Univariate Polynomial Ring in y over Finite Field of size 5
    4848   
    49     Here the fraction field is not just the Laurent series ring, so you
    50     can't use the ``Frac`` notation to make the Laurent
    51     series ring.
     49    After fixing ticket #8972, this also works if the base ring is not
     50    a field. In this case, the ``Frac`` constructor returns the Laurent
     51    series ring over the fraction field of the base ring.
    5252   
    5353    ::
    5454   
    5555        sage: Frac(ZZ[['t']])
    56         Fraction Field of Power Series Ring in t over Integer Ring
     56        Laurent Series Ring in t over Rational Field
    5757   
    5858    Laurent series rings are determined by their variable and the base
    5959    ring, and are globally unique.
  • sage/rings/power_series_ring.py

    diff -r b863b0bd2d33 -r afbcfe010278 sage/rings/power_series_ring.py
    a b  
    783783            return self.__laurent_series_ring           
    784784   
    785785class PowerSeriesRing_domain(PowerSeriesRing_generic, integral_domain.IntegralDomain):
    786       pass
    787    
     786    def fraction_field(self):
     787        """
     788        Return the fraction field of this power series ring, which
     789        is the same as the Laurent series ring over the fraction
     790        field of the base ring of ``self``.
     791
     792        EXAMPLE::
     793
     794            sage: R1.<x> = ZZ[[]]
     795            sage: FractionField(R1)
     796            Laurent Series Ring in x over Rational Field
     797            sage: R2.<x> = GF(3)['t'][[]]
     798            sage: 1/x in FractionField(R2)
     799            True
     800        """
     801        return self.laurent_series_ring().base_extend(self.base().fraction_field())
     802
    788803class PowerSeriesRing_over_field(PowerSeriesRing_domain):
    789804    def fraction_field(self):
    790805        """
  • sage/rings/power_series_ring_element.pyx

    diff -r b863b0bd2d33 -r afbcfe010278 sage/rings/power_series_ring_element.pyx
    a b  
    976976            t + O(t^21)
    977977            sage: (t^5/(t^2 - 2)) * (t^2 -2 )
    978978            t^5 + O(t^25)
     979
     980        TEST:
     981
     982        The following tests against a bug that was fixed in
     983        ticket #8972::
     984
     985            sage: P.<t> = ZZ[]
     986            sage: R.<x> = P[[]]
     987            sage: 1/(t*x)
     988            1/t*x^-1
    979989        """
     990        F = self._parent.fraction_field()
    980991        denom = <PowerSeries>denom_r
    981992        if denom.is_zero():
    982993            raise ZeroDivisionError, "Can't divide by something indistinguishable from 0"
    983         u = denom.valuation_zero_part()
    984         inv = ~u  # inverse
    985994       
    986995        v = denom.valuation()
    987996        if v > self.valuation():
    988             R = self._parent.laurent_series_ring()
    989             return R(self)/R(denom)
     997            R = self._parent.laurent_series_ring().base_extend(self._parent.base().fraction_field())
     998            return F(R(self)/R(denom))
    990999       
    9911000        # Algorithm: Cancel common factors of q from top and bottom,
    9921001        # then invert the denominator.  We do the cancellation first
    9931002        # because we can only invert a unit (and remain in the ring
    9941003        # of power series).
    9951004       
     1005        P_ext = self._parent.base_extend(denom_r.parent().base().fraction_field())
     1006        u = P_ext(denom.valuation_zero_part())
     1007        inv = ~u  # inverse
    9961008        if v > 0:
    9971009            num = self >> v
    9981010        else:
    9991011            num = self
    1000         return num*inv
     1012        return F(num*inv)
    10011013
    10021014    def __mod__(self, other):
    10031015        """