Skip to content

Commit bdfdab9

Browse files
issue 35860: correct parent for square root of constant polynomial
1 parent 853d070 commit bdfdab9

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/sage/rings/laurent_series_ring_element.pyx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,14 @@ cdef class LaurentSeries(AlgebraElement):
751751
t^-3 + t^3 + O(t^9)
752752
753753
ALGORITHM: Shift the unit parts to align them, then add.
754+
755+
TESTS:
756+
757+
Verify that :trac:`35860` is fixed::
758+
759+
sage: R.<t> = LaurentPolynomialRing(ZZ)
760+
sage: sqrt(t^2) + t^-1
761+
t^-1 + t
754762
"""
755763
cdef LaurentSeries right = <LaurentSeries>right_m
756764
cdef long m

src/sage/rings/polynomial/polynomial_element.pyx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1988,6 +1988,12 @@ cdef class Polynomial(CommutativePolynomial):
19881988
False
19891989
sage: R(0).is_square()
19901990
True
1991+
1992+
Make sure :trac:`35860` is fixed::
1993+
1994+
sage: S.<x> = PolynomialRing(ZZ)
1995+
sage: is_square(S(1), True)[1].parent()
1996+
Univariate Polynomial Ring in x over Integer Ring
19911997
"""
19921998
if self.is_zero():
19931999
return (True, self) if root else True
@@ -2000,7 +2006,7 @@ cdef class Polynomial(CommutativePolynomial):
20002006
u = self._parent.base_ring()(f.unit())
20012007

20022008
if all(a[1] % 2 == 0 for a in f) and u.is_square():
2003-
g = u.sqrt()
2009+
g = self._parent(u.sqrt())
20042010
for a in f:
20052011
g *= a[0] ** (a[1] // 2)
20062012
return (True, g) if root else True

0 commit comments

Comments
 (0)