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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/sage/rings/laurent_series_ring_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,14 @@ cdef class LaurentSeries(AlgebraElement):
t^-3 + t^3 + O(t^9)

ALGORITHM: Shift the unit parts to align them, then add.

TESTS:

Verify that :trac:`35860` is fixed::

sage: R.<t> = LaurentPolynomialRing(ZZ)
sage: sqrt(t^2) + t^-1
t^-1 + t
"""
cdef LaurentSeries right = <LaurentSeries>right_m
cdef long m
Expand Down
8 changes: 7 additions & 1 deletion src/sage/rings/polynomial/polynomial_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1988,6 +1988,12 @@ cdef class Polynomial(CommutativePolynomial):
False
sage: R(0).is_square()
True

Make sure :trac:`35860` is fixed::

sage: S.<x> = PolynomialRing(ZZ)
sage: is_square(S(1), True)[1].parent()
Univariate Polynomial Ring in x over Integer Ring
"""
if self.is_zero():
return (True, self) if root else True
Expand All @@ -2000,7 +2006,7 @@ cdef class Polynomial(CommutativePolynomial):
u = self._parent.base_ring()(f.unit())

if all(a[1] % 2 == 0 for a in f) and u.is_square():
g = u.sqrt()
g = self._parent(u.sqrt())
for a in f:
g *= a[0] ** (a[1] // 2)
return (True, g) if root else True
Expand Down