Skip to content

Conversation

@cxzhong
Copy link
Contributor

@cxzhong cxzhong commented Dec 12, 2025

Fix #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

📝 Checklist

  • 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

Refactor normalization and inverse checks in LaurentPolynomial.
@github-actions
Copy link

github-actions bot commented Dec 12, 2025

Documentation preview for this PR (built with commit 1bec308; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

Copy link
Collaborator

@tscrim tscrim left a 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 _normalized failed 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 why has_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.

@cxzhong cxzhong requested a review from tscrim December 13, 2025 18:49
Copy link
Collaborator

@tscrim tscrim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. LGTM.

vbraun pushed a commit to vbraun/sage that referenced this pull request Dec 20, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Substitution in (multivariate) LaurentPolynomialRing is incorrect

2 participants