Skip to content

Commit 4f4d6e7

Browse files
author
Release Manager
committed
gh-40815: Speed up computation of radical of polynomial See the added test, before this change, it takes forever. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [ ] The title is concise and informative. - [ ] 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. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #40815 Reported by: user202729 Reviewer(s): Martin Rubey, Sahil Jain, user202729
2 parents eb4f55c + feeea23 commit 4f4d6e7

File tree

2 files changed

+44
-12
lines changed

2 files changed

+44
-12
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: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10536,22 +10536,47 @@ cdef class Polynomial(CommutativePolynomial):
1053610536
sage: P.<x> = GF(2)[]
1053710537
sage: (x^3 + x^2).radical() # needs sage.rings.finite_rings
1053810538
x^2 + x
10539+
10540+
TESTS:
10541+
10542+
Check that the method is sufficiently fast::
10543+
10544+
sage: R.<x> = GF(2^13)[]
10545+
sage: f = R.random_element(degree=1000)
10546+
sage: g = f.radical() # < 1s
10547+
10548+
Check that the method works as long as either :meth:`squarefree_decomposition`
10549+
or :meth:`factor` is implemented::
10550+
10551+
sage: F.<x> = FunctionField(GF(2^10))
10552+
sage: R.<y> = F[]
10553+
sage: f = (y+1/(x-1))^2 * (y+x)
10554+
sage: f.factor()
10555+
(y + x) * (y + 1/(x + 1))^2
10556+
sage: f.squarefree_decomposition()
10557+
Traceback (most recent call last):
10558+
...
10559+
NotImplementedError: square-free decomposition not implemented for this polynomial
10560+
sage: f.radical()
10561+
y^2 + ((x^2 + x + 1)/(x + 1))*y + x/(x + 1)
1053910562
"""
1054010563
P = self._parent
1054110564
R = P.base_ring()
1054210565
p = R.characteristic()
10543-
if p == 0 or p > self.degree():
10544-
if R.is_field():
10545-
return self // self.gcd(self.derivative())
10546-
else:
10547-
# Be careful with the content: return the
10548-
# radical of the content times the radical of
10549-
# (self/content)
10550-
content = self.content_ideal().gen()
10551-
self_1 = (self//content)
10552-
return (self_1 // self_1.gcd(self_1.derivative())) * content.radical()
10553-
else: # The above method is not always correct (see Issue 8736)
10554-
return self.factor().radical_value()
10566+
if 0 < p <= self.degree():
10567+
# The method below is not always correct (see Issue 8736)
10568+
try:
10569+
return self.squarefree_decomposition().radical_value()
10570+
except NotImplementedError:
10571+
return self.factor().radical_value()
10572+
if R.is_field():
10573+
return self // self.gcd(self.derivative())
10574+
# Be careful with the content: return the
10575+
# radical of the content times the radical of
10576+
# (self/content)
10577+
content = self.content_ideal().gen()
10578+
self_1 = (self//content)
10579+
return (self_1 // self_1.gcd(self_1.derivative())) * content.radical()
1055510580

1055610581
def content_ideal(self):
1055710582
"""

0 commit comments

Comments
 (0)