Ticket #10532: trac_10532_faster_MPowerSeries_mul.patch

File trac_10532_faster_MPowerSeries_mul.patch, 2.9 KB (added by niles, 9 years ago)

depends on #1956 and trac_10480_fast_PowerSeries_poly_multiplication2.patch

  • sage/rings/multi_power_series_ring.py

    # HG changeset patch
    # User Mario Pernici <mario.pernici@gmail.com>
    # Date 1293512890 -3600
    # Node ID b2f7d097555e8a8411fe3ea1a50fe80aa857d6d3
    # Parent  f3c0d7fad5b52c5e256fc7675a48559101370421
    #10532 faster MPowerSeries._mul_, _send_to_bg and _send_to_fg
    
    MPowerSeries._mul_ uses the do_mul_trunc_generic
    algorithm in polynomial_element.pyx
    
    diff -r f3c0d7fad5b5 -r b2f7d097555e sage/rings/multi_power_series_ring.py
    a b  
    989989            f = self._poly_ring(f)
    990990        except TypeError:
    991991            raise TypeError("Cannot coerce input to polynomial ring.")
    992         fg_to_bg_dict = dict((v,v*self._bg_ps_ring().gen())
    993                              for v in self._poly_ring().gens())
    994         return self._bg_ps_ring(f.subs(fg_to_bg_dict))
     992        degs = f.degrees()
     993        if degs:
     994            emax = 0
     995            f1 = [0]*(sum(degs)+1)
     996            for x in f:
     997                e = sum(x[1].degrees())
     998                if e > emax:
     999                    emax = e
     1000                f1[e] += x[0]*x[1]
     1001            f1 = f1[:emax+1]
     1002        else:
     1003            f1 = f
     1004        return self._bg_ps_ring(f1)
    9951005
    9961006    def _send_to_fg(self,f):
    9971007        """
     
    10171027            4 + 4*f0 + 4*f2
    10181028        """
    10191029       
    1020         return self._poly_ring(f.subs({self.__bg_indeterminate:1}))
     1030        return self._poly_ring(sum(f.list()))
    10211031
    10221032   
    10231033   
  • sage/rings/multi_power_series_ring_element.py

    diff -r f3c0d7fad5b5 -r b2f7d097555e sage/rings/multi_power_series_ring_element.py
    a b  
    172172from sage.structure.nonexact import Nonexact
    173173from sage.structure.parent_gens import ParentWithGens
    174174from sage.structure.category_object import CategoryObject
     175from sage.rings.polynomial.polynomial_element import Polynomial_generic_dense
     176from sage.rings.power_series_poly import PowerSeries_poly
    175177
    176178
    177179def is_MPowerSeries(f):
     
    658660            sage: all(S >= g.prec() for S in [sum(e) for e in diff.exponents()])
    659661            True
    660662        """
    661         f = left._bg_value * right._bg_value
    662         return MPowerSeries(left.parent(), f, prec=f.prec())
     663        prec = left._bg_value._mul_prec(right._bg_value)
     664        if prec is infinity or not isinstance(left._bg_value.polynomial(), Polynomial_generic_dense) or  not isinstance(right._bg_value.polynomial(), Polynomial_generic_dense):
     665          f = left._bg_value*right._bg_value
     666        else:
     667          f = left._bg_value.polynomial().mul_trunc(right._bg_value.polynomial(),prec,1)
     668          f = PowerSeries_poly(left._bg_value.parent(),f,prec,check = True)
     669        return MPowerSeries(left.parent(), f, prec)
     670
    663671   
    664672#    def _rmul_(self, c):
    665673#        # multivariate power series rings are assumed to be commutative