# 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
|
b
|
|
| 1081 | 1081 | except TypeError: |
| 1082 | 1082 | return False |
| 1083 | 1083 | |
| 1084 | | def sqrt(self, prec=None, extend=False, |
| 1085 | | all=False, name=None): |
| 1086 | | r""" |
| 1087 | | The square root function. |
| | 1084 | def sqrt(self, prec=None, extend=False, all=False, name=None): |
| | 1085 | r""" The square root function. |
| 1088 | 1086 | |
| 1089 | 1087 | INPUT: |
| 1090 | 1088 | |
| 1091 | | - prec - integer (default: None): if not None and the series has |
| 1092 | | infinite precision, truncates series at precision prec. |
| | 1089 | - prec - integer (default: None): if not None and the series |
| | 1090 | has infinite precision, truncates series at precision |
| | 1091 | prec. |
| 1093 | 1092 | |
| 1094 | | - extend - bool (default: False); if True, return a square root in an |
| 1095 | | extension ring, if necessary. Otherwise, raise a ValueError if the |
| 1096 | | square is not in the base power series ring. For example, if extend |
| 1097 | | is True the square root of a power series with odd degree leading |
| 1098 | | coefficient is defined as an element of a formal extension ring. |
| | 1093 | - extend - bool (default: False); if True, return a square |
| | 1094 | root in an extension ring, if necessary. Otherwise, raise |
| | 1095 | a ValueError if the square is not in the base power series |
| | 1096 | ring. For example, if extend is True the square root of a |
| | 1097 | power series with odd degree leading coefficient is |
| | 1098 | defined as an element of a formal extension ring. |
| 1099 | 1099 | |
| 1100 | | - name - if extend is True, you must also specify the print name of |
| 1101 | | the formal square root. |
| | 1100 | - name - if extend is True, you must also specify the print |
| | 1101 | name of the formal square root. |
| 1102 | 1102 | |
| 1103 | | - all - bool (default: False); if True, return |
| 1104 | | all square roots of self, instead of just one. |
| | 1103 | - all - bool (default: False); if True, return all square |
| | 1104 | roots of self, instead of just one. |
| 1105 | 1105 | |
| 1106 | 1106 | ALGORITHM: Newton's method |
| 1107 | 1107 | |
| 1108 | 1108 | .. math:: |
| 1109 | 1109 | |
| 1110 | | x_{i+1} = \frac{1}{2}( x_i + self/x_i ) |
| 1111 | | |
| 1112 | | |
| 1113 | | |
| | 1110 | x_{i+1} = \frac{1}{2}( x_i + self/x_i ) |
| | 1111 | |
| 1114 | 1112 | EXAMPLES:: |
| 1115 | 1113 | |
| 1116 | 1114 | sage: K.<t> = PowerSeriesRing(QQ, 't', 5) |
| … |
… |
|
| 1156 | 1154 | sage: s^2 |
| 1157 | 1155 | 2*t + t^3 + O(t^4) |
| 1158 | 1156 | sage: parent(s) |
| 1159 | | 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) |
| | 1157 | 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) |
| | 1158 | |
| | 1159 | TESTS:: |
| | 1160 | |
| | 1161 | sage: R.<x> = QQ[[]] |
| | 1162 | sage: (x^10/2).sqrt() |
| | 1163 | Traceback (most recent call last): |
| | 1164 | ... |
| | 1165 | ValueError: unable to take the square root of 1/2 |
| 1160 | 1166 | |
| 1161 | 1167 | AUTHORS: |
| 1162 | 1168 | |
| … |
… |
|
| 1193 | 1199 | return a |
| 1194 | 1200 | |
| 1195 | 1201 | val = self.valuation() |
| | 1202 | |
| 1196 | 1203 | if formal_sqrt or val % 2 == 1: |
| 1197 | 1204 | if extend: |
| 1198 | 1205 | if name is None: |
| … |
… |
|
| 1206 | 1213 | return [a, -a] |
| 1207 | 1214 | else: |
| 1208 | 1215 | return a |
| | 1216 | elif formal_sqrt: |
| | 1217 | raise ValueError, "unable to take the square root of %s"%u[0] |
| 1209 | 1218 | else: |
| 1210 | 1219 | raise ValueError, "power series does not have a square root since it has odd valuation." |
| | 1220 | |
| 1211 | 1221 | |
| 1212 | 1222 | pr = self.prec() |
| 1213 | 1223 | if pr == infinity: |