-
-
Notifications
You must be signed in to change notification settings - Fork 489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New comparison mode to lazy series and better undefined check #35485
Conversation
2de89b7
to
95bd489
Compare
One quick comment as I go out the door. In the last commit, I gave another variation on this, where instead of |
Sorry, u probably won't be able to look at this until Saturday. |
95bd489
to
e81f93d
Compare
No problem; no rush. I fixed the doctest failure. I did a force push of it to keep the alternative proposal within the one commit. |
The benefits for the last proposal as it (functionally) never gives a false positive for What do you think? |
e81f93d
to
fdc7529
Compare
81cb4ec
to
a3fec59
Compare
a3fec59
to
c1c57d7
Compare
c1c57d7
to
789f23f
Compare
This does not need to depend on #35362 as the new streams added have no way of verifying (i.e., an undecidable problem) if they have uninitialized streams being created in the iterator. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a couple of things from #35480 that were lost but should be included:
diff --git a/src/sage/data_structures/stream.py b/src/sage/data_structures/stream.py
index 7038ce2149c..8cd49565fa8 100644
--- a/src/sage/data_structures/stream.py
+++ b/src/sage/data_structures/stream.py
@@ -968,6 +723,11 @@ class Stream_function(Stream_inexact):
- ``approximate_order`` -- integer; a lower bound for the order
of the stream
+ .. WARNING::
+
+ We assume for equality that ``function`` is a function in the
+ mathematical sense.
+
EXAMPLES::
sage: from sage.data_structures.stream import Stream_function
@@ -1000,6 +760,43 @@ class Stream_function(Stream_inexact):
super().__init__(is_sparse, true_order)
self._approximate_order = approximate_order
+ def __hash__(self):
+ """
+ Return the hash of ``self``.
+
+ EXAMPLES::
+
+ sage: from sage.data_structures.stream import Stream_function
+ sage: f = Stream_function(lambda n: n, True, 0)
+ sage: g = Stream_function(lambda n: 1, False, 1)
+ sage: hash(f) == hash(g)
+ True
+ """
+ # We don't hash the function as it might not be hashable.
+ return hash(type(self))
+
+ def __eq__(self, other):
+ """
+ Return whether ``self`` and ``other`` are known to be equal.
+
+ INPUT:
+
+ - ``other`` -- a stream
+
+ EXAMPLES::
+
+ sage: from sage.data_structures.stream import Stream_function
+ sage: fun = lambda n: n
+ sage: f = Stream_function(fun, True, 0)
+ sage: g = Stream_function(fun, False, 0)
+ sage: h = Stream_function(lambda n: n, False, 0)
+ sage: f == g
+ True
+ sage: f == h
+ False
+ """
+ return isinstance(other, type(self)) and self.get_coefficient == other.get_coefficient
+
class Stream_uninitialized(Stream_inexact):
r"""
@@ -2759,6 +2406,11 @@ class Stream_map_coefficients(Stream_inexact):
- ``series`` -- a :class:`Stream`
- ``function`` -- a function that modifies the elements of the stream
+ .. WARNING::
+
+ We assume for equality that ``function`` is a function in the
+ mathematical sense.
+
EXAMPLES::
sage: from sage.data_structures.stream import (Stream_map_coefficients, Stream_function)
Thanks. I have added those changes (although I weakened |
I also have subsequently checked that merging in #35362 doesn't introduce any failures or conflicts. |
There are a few trivial doctest failures in |
You're right that we cannot have any fully correct For the infinite products/sums, I could make those work purely in terms of modifying #35362. I am not convinced we should have a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect!
See #35485 (comment) - indeed, I do not want a global option, I want a Using the new |
Thank you. Most likely, but I am hoping that we will never have to use/implement a |
… padics), adding is_unitialized() doctests.
72e15b6
to
1ad7352
Compare
Trivial rebase to fix the merge conflict. |
Documentation preview for this PR (built with commit 1ad7352; changes) is ready! 🎉 |
…ined check <!-- Please provide a concise, informative and self-explanatory title. --> <!-- Don't put issue numbers in the title. Put it in the Description below. --> <!-- For example, instead of "Fixes sagemath#12345", use "Add a new method to multiply two integers" --> ### 📚 Description <!-- Describe your changes here in detail. --> <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes sagemath#12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> This fixes sagemath#35071 by: 1. providing a method to streams to see if they are unitinalized 2. includes a new mode for comparisons in the lazy series ring based on the proposal in sagemath#35429. The new comparison mode `secure` simply returns `False` when it cannot verify that `f == g` and makes sure that `(f == g) == not (f != g)`, and this will become the new default. In particular, it will return `True` for `f != g` both when it cannot show that `f == g` and when they are genuinely different. In order to verify when the comparison is unknown, we expose the `is_nonzero()` that only returns `True` when the series is _known_ to be nonzero. Thus, we verify by `(f - g).is_nonzero()`. When a finite halting precision is given, then that takes priority. For the infinite halting precision in the "old" version (`secure = True`), it will raise a `ValueError` when it cannot verify the result. **NOTE:** `f.is_zero()` is still the default `not f` for speed and the assumption these are in agreement elsewhere in Sage. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. It should be `[x]` not `[x ]`. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - sagemath#12345: short description why this is a dependency - sagemath#34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: sagemath#35485 Reported by: Travis Scrimshaw Reviewer(s): Martin Rubey, Travis Scrimshaw
…ries <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes sagemath#1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> We implement an `integral()` method for lazy Laurent and power series. If we raise an error if we perform $\int t^{-1} dt$. We also prove a way to construct a lazy (power) series as the Taylor series of a function. <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes sagemath#12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - sagemath#12345: short description why this is a dependency - sagemath#34567: ... --> - sagemath#35485: Uses the `is_uninitialized()` checking. <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: sagemath#36233 Reported by: Travis Scrimshaw Reviewer(s): Martin Rubey, Travis Scrimshaw
…ries <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes sagemath#1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> We implement an `integral()` method for lazy Laurent and power series. If we raise an error if we perform $\int t^{-1} dt$. We also prove a way to construct a lazy (power) series as the Taylor series of a function. <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes sagemath#12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - sagemath#12345: short description why this is a dependency - sagemath#34567: ... --> - sagemath#35485: Uses the `is_uninitialized()` checking. <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: sagemath#36233 Reported by: Travis Scrimshaw Reviewer(s): Martin Rubey, Travis Scrimshaw
…ries <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes sagemath#1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> We implement an `integral()` method for lazy Laurent and power series. If we raise an error if we perform $\int t^{-1} dt$. We also prove a way to construct a lazy (power) series as the Taylor series of a function. <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes sagemath#12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - sagemath#12345: short description why this is a dependency - sagemath#34567: ... --> - sagemath#35485: Uses the `is_uninitialized()` checking. <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: sagemath#36233 Reported by: Travis Scrimshaw Reviewer(s): Martin Rubey, Travis Scrimshaw
…ries <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes sagemath#1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> We implement an `integral()` method for lazy Laurent and power series. If we raise an error if we perform $\int t^{-1} dt$. We also prove a way to construct a lazy (power) series as the Taylor series of a function. <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes sagemath#12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - sagemath#12345: short description why this is a dependency - sagemath#34567: ... --> - sagemath#35485: Uses the `is_uninitialized()` checking. <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: sagemath#36233 Reported by: Travis Scrimshaw Reviewer(s): Martin Rubey, Travis Scrimshaw
📚 Description
This fixes #35071 by:
The new comparison mode
secure
simply returnsFalse
when it cannot verify thatf == g
and makes sure that(f == g) == not (f != g)
, and this will become the new default. In particular, it will returnTrue
forf != g
both when it cannot show thatf == g
and when they are genuinely different. In order to verify when the comparison is unknown, we expose theis_nonzero()
that only returnsTrue
when the series is known to be nonzero. Thus, we verify by(f - g).is_nonzero()
.When a finite halting precision is given, then that takes priority.
For the infinite halting precision in the "old" version (
secure = True
), it will raise aValueError
when it cannot verify the result.NOTE:
f.is_zero()
is still the defaultnot f
for speed and the assumption these are in agreement elsewhere in Sage.📝 Checklist
⌛ Dependencies