Skip to content
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

correct parent for square root of constant polynomial #35876

Merged
merged 1 commit into from
Jul 9, 2023

Conversation

DaveWitteMorris
Copy link
Member

@DaveWitteMorris DaveWitteMorris commented Jul 2, 2023

πŸ“š Description

Fixes #35860.

If f is a polynomial that is a perfect square, then sqrt(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), where u is an ordinary polynomial, and n 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:

f2 = right.__u << right.__n - left.__n

This code assumes that the parent of right.__u is a polynomial ring: if the parent of right.__u is ZZ, 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

  • The title is concise, informative, and self-explanatory.
  • 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.

βŒ› Dependencies

@mezzarobba
Copy link
Member

Lgtm, thank you!

@DaveWitteMorris
Copy link
Member Author

Thanks!

@vbraun vbraun merged commit eef9eea into sagemath:develop Jul 9, 2023
13 of 14 checks passed
@DaveWitteMorris DaveWitteMorris deleted the 35860root branch July 9, 2023 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

is_square does not work correctly for Laurent polynomials
4 participants