correct parent for square root of constant polynomial #35876
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📚 Description
Fixes #35860.
If
f
is a polynomial that is a perfect square, thensqrt(f)
should also be a polynomial. However, this has not been the case for polynomials that happen to be constant: the code returned a constant in the base ring, not a constant polynomial. The PR fixes this (and adds a doctest for this bug).This change fixes the serious bug that was pointed out (and diagnosed) by @amithazi in issue #35860. A single-variable Laurent polynomial is stored as a pair
(u, n)
, whereu
is an ordinary polynomial, andn
is an integer that represents an offset (i.e., multiplication by a [usually negative] power of the variable). To add two Laurent polynomials, one of them needs to be shifted so they have the same offset:This code assumes that the parent of
right.__u
is a polynomial ring: if the parent ofright.__u
isZZ
, then the shift operator<<
multiplies by a power of 2, instead of shifting the polynomial, so the result is nonsense. The PR also adds a doctest for this bug.📝 Checklist
⌛ Dependencies