Skip to content

Commit b1b8493

Browse files
committed
raise ValueError in case (in)equality is not decidable
1 parent 94e0de4 commit b1b8493

File tree

3 files changed

+47
-14
lines changed

3 files changed

+47
-14
lines changed

src/sage/data_structures/stream.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,23 @@ def iterate_coefficients(self):
937937
yield self._target[n]
938938
n += 1
939939

940+
def is_nonzero(self):
941+
r"""
942+
Return ``True`` if and only if this stream is known
943+
to be nonzero.
944+
945+
An assumption of this class is that it is nonzero.
946+
947+
EXAMPLES::
948+
949+
sage: from sage.data_structures.stream import Stream_uninitialized
950+
sage: g = Stream_uninitialized(0)
951+
sage: g.is_nonzero()
952+
True
953+
"""
954+
if self._target is None:
955+
return True
956+
return super().is_nonzero()
940957

941958
class Stream_unary(Stream_inexact):
942959
r"""

src/sage/rings/lazy_series.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -938,9 +938,13 @@ def _richcmp_(self, other, op):
938938
939939
sage: fz = L(lambda n: 0, valuation=0)
940940
sage: L.zero() == fz
941-
False
941+
Traceback (most recent call last):
942+
...
943+
ValueError: undecidable
942944
sage: fz == L.zero()
943-
False
945+
Traceback (most recent call last):
946+
...
947+
ValueError: undecidable
944948
945949
TESTS::
946950
@@ -952,13 +956,15 @@ def _richcmp_(self, other, op):
952956
953957
"""
954958
if op is op_EQ:
955-
prec = self.parent().options['halting_precision']
956-
if prec is None:
957-
return self._coeff_stream == other._coeff_stream
958-
959959
# they may be trivially equal
960960
if self._coeff_stream == other._coeff_stream:
961961
return True
962+
# they may be trivially different
963+
if self._coeff_stream != other._coeff_stream:
964+
return False
965+
prec = self.parent().options['halting_precision']
966+
if prec is None:
967+
raise ValueError("undecidable")
962968
# otherwise we check the first prec coefficients
963969
m = min(self._coeff_stream._approximate_order,
964970
other._coeff_stream._approximate_order)
@@ -1003,7 +1009,9 @@ def __bool__(self):
10031009
sage: M = L(lambda n: 2*n if n < 10 else 1, valuation=0); M
10041010
O(z^7)
10051011
sage: bool(M)
1006-
True
1012+
Traceback (most recent call last):
1013+
...
1014+
ValueError: undecidable
10071015
sage: M[15]
10081016
1
10091017
sage: bool(M)
@@ -1013,7 +1021,9 @@ def __bool__(self):
10131021
sage: M = L(lambda n: 2*n if n < 10 else 1, valuation=0); M
10141022
O(z^7)
10151023
sage: bool(M)
1016-
True
1024+
Traceback (most recent call last):
1025+
...
1026+
ValueError: undecidable
10171027
sage: M[15]
10181028
1
10191029
sage: bool(M)
@@ -1040,9 +1050,11 @@ def __bool__(self):
10401050
True
10411051
sage: g.define(1 + z*g)
10421052
sage: bool(g)
1043-
True
1053+
Traceback (most recent call last):
1054+
...
1055+
ValueError: undecidable
10441056
"""
1045-
return bool(self._coeff_stream)
1057+
return not (self == self.parent().zero())
10461058

10471059
def define(self, s):
10481060
r"""
@@ -1716,7 +1728,9 @@ def _acted_upon_(self, scalar, self_on_left):
17161728
Different scalars potentially give different series::
17171729
17181730
sage: 2 * M == 3 * M
1719-
False
1731+
Traceback (most recent call last):
1732+
...
1733+
ValueError: undecidable
17201734
17211735
Sparse series can be multiplied with a scalar::
17221736

src/sage/rings/lazy_series_ring.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,8 @@ class options(GlobalOptions):
664664
description='the number of coefficients to display for nonzero constant series',
665665
checker=lambda x: x in ZZ and x > 0)
666666
halting_precision = dict(default=None,
667-
description='the number of coefficients, beginning with the approximate valuation, to check in equality tests',
668-
checker=lambda x: x is None or x in ZZ and x > 0)
667+
description='the number of coefficients, beginning with the approximate valuation, to check in equality tests',
668+
checker=lambda x: x is None or x in ZZ and x > 0)
669669

670670
@cached_method
671671
def one(self):
@@ -1117,7 +1117,9 @@ class LazyLaurentSeriesRing(LazySeriesRing):
11171117
sage: f2 = f * 2 # currently no coefficients computed
11181118
sage: f3 = f * 3 # currently no coefficients computed
11191119
sage: f2 == f3
1120-
False
1120+
Traceback (most recent call last):
1121+
...
1122+
ValueError: undecidable
11211123
sage: f2 # computes some of the coefficients of f2
11221124
2*z^-1 - 2 + 2*z - 2*z^2 + 2*z^3 - 2*z^4 + 2*z^5 + O(z^6)
11231125
sage: f3 # computes some of the coefficients of f3

0 commit comments

Comments
 (0)