Skip to content

Commit 40daeec

Browse files
committed
Fix failing tests by fallback to factor()
1 parent 0d2e125 commit 40daeec

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

src/sage/categories/fields.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,13 @@ def _squarefree_decomposition_univariate_polynomial(self, f):
692692
sage: f = QQbar['x'](1) # needs sage.rings.number_field
693693
sage: f.squarefree_decomposition() # needs sage.rings.number_field
694694
1
695+
696+
.. NOTE::
697+
698+
Currently factorization over non-finite fields with positive characteristic
699+
is not implemented, it would be useful to port the algorithm in
700+
:meth:`sage.rings.finite_rings.finite_field_base.FiniteField._squarefree_decomposition_univariate_polynomial`
701+
here.
695702
"""
696703
from sage.structure.factorization import Factorization
697704
if f.degree() == 0:

src/sage/rings/polynomial/polynomial_element.pyx

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10514,27 +10514,44 @@ cdef class Polynomial(CommutativePolynomial):
1051410514
sage: (x^3 + x^2).radical() # needs sage.rings.finite_rings
1051510515
x^2 + x
1051610516
10517-
TESTS::
10517+
TESTS:
10518+
10519+
Check that the method is sufficiently fast::
1051810520
1051910521
sage: R.<x> = GF(2^13)[]
1052010522
sage: f = R.random_element(degree=1000)
10521-
sage: g = f.radical()
10523+
sage: g = f.radical() # < 1s
10524+
10525+
Check that the method works as long as either :meth:`squarefree_decomposition`
10526+
or :meth:`factor` is implemented::
10527+
10528+
sage: F.<x> = FunctionField(GF(2^10))
10529+
sage: R.<y> = F[]
10530+
sage: f = (y+1/(x-1))^2 * (y+x)
10531+
sage: f.factor()
10532+
(y + x) * (y + 1/(x + 1))^2
10533+
sage: f.squarefree_decomposition()
10534+
Traceback (most recent call last):
10535+
...
10536+
NotImplementedError: square-free decomposition not implemented for this polynomial
1052210537
"""
1052310538
P = self._parent
1052410539
R = P.base_ring()
1052510540
p = R.characteristic()
10526-
if p == 0 or p > self.degree():
10527-
if R.is_field():
10528-
return self // self.gcd(self.derivative())
10529-
else:
10530-
# Be careful with the content: return the
10531-
# radical of the content times the radical of
10532-
# (self/content)
10533-
content = self.content_ideal().gen()
10534-
self_1 = (self//content)
10535-
return (self_1 // self_1.gcd(self_1.derivative())) * content.radical()
10536-
else: # The above method is not always correct (see Issue 8736)
10537-
return self.squarefree_decomposition().radical_value()
10541+
if 0 < p <= self.degree():
10542+
# The method below is not always correct (see Issue 8736)
10543+
try:
10544+
return self.squarefree_decomposition().radical_value()
10545+
except NotImplementedError:
10546+
return self.factor().radical_value()
10547+
if R.is_field():
10548+
return self // self.gcd(self.derivative())
10549+
# Be careful with the content: return the
10550+
# radical of the content times the radical of
10551+
# (self/content)
10552+
content = self.content_ideal().gen()
10553+
self_1 = (self//content)
10554+
return (self_1 // self_1.gcd(self_1.derivative())) * content.radical()
1053810555

1053910556
def content_ideal(self):
1054010557
"""

0 commit comments

Comments
 (0)