# Ticket #10532: trac_10532_invert.patch

File trac_10532_invert.patch, 2.4 KB (added by pernici, 9 years ago)
• ## sage/rings/multi_power_series_ring_element.py

```# HG changeset patch
# User Mario Pernici <mario.pernici@gmail.com>
# Date 1297188793 -3600
# Node ID 34aa7eff3b5a026162349dc6658d6a75a4f8fb54
# Parent  e0d02abc6dca0215ea783fc42404684403e1a3b2
In this patch __invert__ is implemented using _mul_trunc_generic;
inversion of a generic multivariate series becomes much faster.

diff -r e0d02abc6dca -r 34aa7eff3b5a sage/rings/multi_power_series_ring_element.py```
 a from sage.structure.category_object import CategoryObject from sage.rings.polynomial.polynomial_element import Polynomial_generic_dense from sage.rings.power_series_poly import PowerSeries_poly import sage.misc.misc def is_MPowerSeries(f): """ 1 - a - b + a^2 + 3*a*b + a*c + b^2 + b*c - a^3 - 5*a^2*b - 2*a^2*c - 5*a*b^2 - 4*a*b*c - b^3 - 2*b^2*c + O(a, b, c)^4 """ if self.valuation() == 0: return self.parent(self._bg_value.__invert__()) else: if self.valuation() != 0: raise NotImplementedError("Multiplicative inverse of multivariate power series currently implemented only if constant coefficient is a unit.") if self == 1: return self s = self._bg_value prec = s.prec() if prec is infinity and s.degree() > 0: prec = s._parent.default_prec() # Use Newton's method, i.e. start with single term approximation, # and then iteratively compute \$x' = 2x - Ax^2\$, where \$A\$ is the # series we're trying to invert. try: first_coeff = ~s[0] except ValueError, ZeroDivisionError: raise ZeroDivisionError, "leading coefficient must be a unit" if prec is infinity: return s._parent(first_coeff, prec=prec) A = s.truncate() R = A.parent()     # R is the corresponding polynomial ring current = R(first_coeff) for next_prec in sage.misc.misc.newton_method_sizes(prec)[1:]: z = current.square()._mul_trunc_generic(A.truncate(next_prec),next_prec) current = 2*current - z return self._parent(s.parent()(current, prec=prec)) ## comparisons def __cmp__(self, other):