-
-
Notifications
You must be signed in to change notification settings - Fork 730
Improve normalization and inverse handling for Laurent Polynomials #41287
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
base: develop
Are you sure you want to change the base?
Conversation
Refactor normalization and inverse checks in LaurentPolynomial.
|
Documentation preview for this PR (built with commit 1bec308; changes) is ready! 🎉 |
tscrim
left a comment
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.
- Please add a test showing a case where the
_normalizedfailed previously (or make it clear in the docstring that is which is being checked; linking only to the issue is not specific as there are multiple things being fixed here). - Changing the internal representation with
_normalize()does not count as mutating the element. So I don't see whyhas_inverse_of()needs to be changed. - Somewhat related issue, do you have an instance where the substitution you implemented is faster than performing the normalization and then punting to the polynomials (which has specialized code for that)? Seems like a step backwards on the face of it.
tscrim
left a comment
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.
Thank you. LGTM.
sagemathgh-41287: Improve normalization and inverse handling for Laurent Polynomials Fix sagemath#41282 1. `has_inverse_of(i)` called `_normalize(i)` which mutated self, even though it should be a read-only query 2. `_normalize(i)` had a bug: it divided `_poly` by `gen(i)` once instead of by `gen(i)**e` 3. `has_any_inverse()` only checked `_mon` without considering if the representation was non-normalized 4. `__call__` evaluated `_poly` directly, which gave wrong results for non-normalized representations <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [ ] The title is concise and informative. - [ ] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#41287 Reported by: Chenxin Zhong Reviewer(s): Travis Scrimshaw
Fix #41282
has_inverse_of(i)called_normalize(i)which mutated self, even though it should be a read-only query_normalize(i)had a bug: it divided_polybygen(i)once instead of bygen(i)**ehas_any_inverse()only checked_monwithout considering if the representation was non-normalized__call__evaluated_polydirectly, which gave wrong results for non-normalized representations📝 Checklist
⌛ Dependencies