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 except TypeError: return False def sqrt(self, prec=None, extend=False, all=False, name=None): r""" The square root function. def sqrt(self, prec=None, extend=False, all=False, name=None): r""" The square root function. INPUT: - prec - integer (default: None): if not None and the series has infinite precision, truncates series at precision prec. - prec - integer (default: None): if not None and the series has infinite precision, truncates series at precision prec. - extend - bool (default: False); if True, return a square root in an extension ring, if necessary. Otherwise, raise a ValueError if the square is not in the base power series ring. For example, if extend is True the square root of a power series with odd degree leading coefficient is defined as an element of a formal extension ring. - extend - bool (default: False); if True, return a square root in an extension ring, if necessary. Otherwise, raise a ValueError if the square is not in the base power series ring. For example, if extend is True the square root of a power series with odd degree leading coefficient is defined as an element of a formal extension ring. - name - if extend is True, you must also specify the print name of the formal square root. - name - if extend is True, you must also specify the print name of the formal square root. - all - bool (default: False); if True, return all square roots of self, instead of just one. - all - bool (default: False); if True, return all square roots of self, instead of just one. ALGORITHM: Newton's method .. math:: x_{i+1} = \frac{1}{2}( x_i + self/x_i ) x_{i+1} = \frac{1}{2}( x_i + self/x_i ) EXAMPLES:: sage: K. = PowerSeriesRing(QQ, 't', 5) sage: s^2 2*t + t^3 + O(t^4) sage: parent(s) 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) 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) TESTS:: sage: R. = QQ[[]] sage: (x^10/2).sqrt() Traceback (most recent call last): ... ValueError: unable to take the square root of 1/2 AUTHORS: return a val = self.valuation() if formal_sqrt or val % 2 == 1: if extend: if name is None: return [a, -a] else: return a elif formal_sqrt: raise ValueError, "unable to take the square root of %s"%u[0] else: raise ValueError, "power series does not have a square root since it has odd valuation." pr = self.prec() if pr == infinity: