Skip to content

Commit 691e237

Browse files
committed
improve check for __invert__ and _div_
1 parent 72e15b6 commit 691e237

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/sage/rings/lazy_series.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
sage: f
5858
1 + z + 2*z^2 + 3*z^3 + 5*z^4 + 8*z^5 + 13*z^6 + O(z^7)
5959
sage: f^-1
60-
1 - z - z^2 + O(z^7)
60+
1 - z - z^2
6161
sage: f + f^-1
6262
2 + z^2 + 3*z^3 + 5*z^4 + 8*z^5 + 13*z^6 + O(z^7)
6363
sage: g = (f + f^-1)*(f - f^-1); g
@@ -3256,10 +3256,20 @@ def __invert__(self):
32563256
Traceback (most recent call last):
32573257
...
32583258
ZeroDivisionError: cannot divide by a series of positive valuation
3259+
3260+
Check that :issue:`36253` is fixed::
3261+
3262+
sage: f = L(lambda n: n)
3263+
sage: ~f
3264+
Traceback (most recent call last):
3265+
...
3266+
ZeroDivisionError: cannot divide by a series of positive valuation
32593267
"""
32603268
P = self.parent()
32613269
coeff_stream = self._coeff_stream
3262-
if P._minimal_valuation is not None and coeff_stream._approximate_order > 0:
3270+
if (P._minimal_valuation is not None
3271+
and (coeff_stream._approximate_order > 0
3272+
or not coeff_stream.is_uninitialized() and not coeff_stream[0])):
32633273
raise ZeroDivisionError("cannot divide by a series of positive valuation")
32643274

32653275
# the inverse is exact if and only if coeff_stream corresponds to one of
@@ -3411,9 +3421,11 @@ def _div_(self, other):
34113421
sage: 1 / f
34123422
Traceback (most recent call last):
34133423
...
3414-
ZeroDivisionError: cannot divide by 0
3424+
ZeroDivisionError: cannot divide by a series of positive valuation
34153425
sage: L.options._reset()
34163426
"""
3427+
if self.is_one():
3428+
return ~other
34173429
if not other:
34183430
raise ZeroDivisionError("cannot divide by 0")
34193431

@@ -4351,6 +4363,7 @@ def revert(self):
43514363
R = P.base_ring()
43524364
# we cannot assume that the last initial coefficient
43534365
# and the constant differ, see stream.Stream_exact
4366+
# TODO: provide example or remove this claim
43544367
if (coeff_stream._degree == 1 + len(coeff_stream._initial_coefficients)
43554368
and coeff_stream._constant == -R.one()
43564369
and all(c == -R.one() for c in coeff_stream._initial_coefficients)):

0 commit comments

Comments
 (0)