Skip to content

Commit e81f93d

Browse files
committed
Alternative proposal returning None for unknown comparisons.
1 parent f20f087 commit e81f93d

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

src/sage/data_structures/stream.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ def __init__(self, initial_coefficients, constant=None, degree=None, order=None)
662662
if order + len(initial_coefficients) == self._degree:
663663
# Strip off the constant values at the end
664664
for w in reversed(initial_coefficients):
665-
if w != self._constant:
665+
if not (w == self._constant):
666666
break
667667
initial_coefficients.pop()
668668
self._degree -= 1

src/sage/rings/lazy_series.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -923,21 +923,21 @@ def _richcmp_(self, other, op):
923923
False
924924
925925
sage: fz = L(lambda n: 0, valuation=0)
926-
sage: L.zero() == fz
927-
False
928-
sage: fz == L.zero()
929-
False
926+
sage: (L.zero() == fz) is None
927+
True
928+
sage: (fz == L.zero()) is None
929+
True
930930
931931
With using :class:`Unknown`::
932932
933933
sage: L.options.use_unknown = True
934934
sage: fz = L(lambda n: 0, valuation=0)
935-
sage: L.zero() == fz
936-
Unknown
937-
sage: fz == L.zero()
938-
Unknown
939-
sage: fz != L.zero()
940-
Unknown
935+
sage: (L.zero() == fz) is None
936+
True
937+
sage: (fz == L.zero()) is None
938+
True
939+
sage: (fz != L.zero()) is None
940+
True
941941
942942
With using finite halting precision::
943943
@@ -993,7 +993,8 @@ def _richcmp_(self, other, op):
993993
# undecidable otherwise
994994
prec = self.parent().options['halting_precision']
995995
if prec is None:
996-
return Unknown
996+
return None
997+
#return Unknown
997998
# raise UnknownError("undecidable")
998999
# at least one of the approximate orders is not infinity
9991000
m = min(self._coeff_stream._approximate_order,
@@ -1002,7 +1003,7 @@ def _richcmp_(self, other, op):
10021003

10031004
if op is op_NE:
10041005
ret = (self == other)
1005-
if ret is Unknown:
1006+
if ret is None:
10061007
return ret
10071008
return not ret
10081009

@@ -1140,7 +1141,8 @@ def __bool__(self):
11401141
return True
11411142

11421143
if prec is None:
1143-
raise UnknownError("undecidable")
1144+
return True
1145+
#raise UnknownError("undecidable")
11441146
v = self._coeff_stream._approximate_order
11451147
return any(self[i] for i in range(v, v + prec))
11461148

@@ -1884,12 +1886,12 @@ def _acted_upon_(self, scalar, self_on_left):
18841886
18851887
Different scalars potentially give different series::
18861888
1887-
sage: 2 * M == 3 * M
1888-
False
1889+
sage: (2 * M == 3 * M) is None
1890+
True
18891891
18901892
sage: L.options.use_unknown = True
1891-
sage: 2 * M == 3 * M
1892-
Unknown
1893+
sage: (2 * M == 3 * M) is None
1894+
True
18931895
18941896
sage: L.options.halting_precision = 30
18951897
sage: 2 * M == 3 * M

src/sage/rings/lazy_series_ring.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ class options(GlobalOptions):
677677
- constant_length: 3
678678
- display_length: 7
679679
- halting_precision: None
680-
- use_unknown: False
680+
- use_unknown: True
681681
682682
sage: LLS.options.display_length
683683
7
@@ -713,7 +713,7 @@ class options(GlobalOptions):
713713
halting_precision = dict(default=None,
714714
description='the number of coefficients, beginning with the approximate valuation, to check in equality tests',
715715
checker=lambda x: x is None or x in ZZ and x > 0)
716-
use_unknown = dict(default=False,
716+
use_unknown = dict(default=True,
717717
description='whether to raise an error when a comparison is unknown',
718718
checker=lambda x: x is True or x is False)
719719

@@ -1160,8 +1160,8 @@ class LazyLaurentSeriesRing(LazySeriesRing):
11601160
be equal are considered to be different::
11611161
11621162
sage: f = L(lambda n: 0, valuation=0)
1163-
sage: f == 0
1164-
False
1163+
sage: (f == 0) is None
1164+
True
11651165
11661166
.. WARNING::
11671167
@@ -1170,7 +1170,7 @@ class LazyLaurentSeriesRing(LazySeriesRing):
11701170
series are actually different::
11711171
11721172
sage: g = L.zero()
1173-
sage: f != g
1173+
sage: (f != g) is None
11741174
True
11751175
11761176
This can be verified by :meth:`~sage.rings.lazy_series.is_nonzero()`,
@@ -1205,27 +1205,25 @@ class LazyLaurentSeriesRing(LazySeriesRing):
12051205
z^-1 - 1 + z - z^2 + z^3 - z^4 + z^5 + O(z^6)
12061206
sage: f2 = f * 2 # currently no coefficients computed
12071207
sage: f3 = f * 3 # currently no coefficients computed
1208-
sage: f2 == f3
1209-
Unknown
1208+
sage: (f2 == f3) is None
1209+
True
12101210
sage: f2 # computes some of the coefficients of f2
12111211
2*z^-1 - 2 + 2*z - 2*z^2 + 2*z^3 - 2*z^4 + 2*z^5 + O(z^6)
12121212
sage: f3 # computes some of the coefficients of f3
12131213
3*z^-1 - 3 + 3*z - 3*z^2 + 3*z^3 - 3*z^4 + 3*z^5 + O(z^6)
12141214
sage: f2 == f3
12151215
False
12161216
sage: f2a = f + f
1217-
sage: f2 == f2a
1218-
Unknown
1217+
sage: (f2 == f2a) is None
1218+
True
12191219
sage: zf = L(lambda n: 0, valuation=0)
1220-
sage: zf == 0
1221-
Unknown
1220+
sage: (zf == 0) is None
1221+
True
12221222
12231223
For boolean checks, an error is raised when it is not known to be nonzero::
12241224
12251225
sage: bool(zf)
1226-
Traceback (most recent call last):
1227-
...
1228-
UnknownError: undecidable
1226+
True
12291227
12301228
If the halting precision is set to a finite number `p` (for unlimited
12311229
precision, it is set to ``None``), then it will check up to `p` values

0 commit comments

Comments
 (0)