Skip to content

Commit 9d8a90d

Browse files
author
Release Manager
committed
Trac #34714: fast path for factoring monomials over number fields
Trivial instances of univariate polynomial factorization over complicated number fields are extremely slow because Sage starts by trying to compute an integral basis. We introduce a fast path that handles monomials — most importantly, the identity polynomial. Ideally, we should do something similar over arbitrary rings, but this is currently difficult to implement in a generic because the `factor()` method of constants is under-specified. In particular, calling `factor()` on a rational number factors the numerator and denominator, which we certainly do not want when factoring the leading coefficient of an element of ℚ[x]. In the number field case, a possible generalization would be to detect constant multiples of polynomials that factor over ℚ. Not sure if this is a good idea. URL: https://trac.sagemath.org/34714 Reported by: mmezzarobba Ticket author(s): Marc Mezzarobba Reviewer(s): Vincent Delecroix
2 parents dcc34e2 + 4fc91e1 commit 9d8a90d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/sage/rings/number_field/number_field.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10501,11 +10501,21 @@ def _factor_univariate_polynomial(self, poly, **kwargs):
1050110501
sage: x = polygen(K,'x')
1050210502
sage: factor(x*x+4) # indirect doctest
1050310503
(x - 2*i) * (x + 2*i)
10504+
10505+
TESTS::
10506+
10507+
sage: with seed(0):
10508+
....: P.<y> = NumberField(QQ['a'].random_element(30,10^100), 'a')[]
10509+
sage: (3*y^4/4).factor()
10510+
(3/4) * y^4
1050410511
"""
1050510512
if self.degree() == 1:
1050610513
factors = poly.change_ring(QQ).factor()
1050710514
return Factorization([(p.change_ring(self), e)
1050810515
for p, e in factors], self(factors.unit()))
10516+
elif poly.is_term():
10517+
return Factorization([(poly.parent().gen(), poly.degree())],
10518+
poly.leading_coefficient())
1050910519

1051010520
# Convert the polynomial we want to factor to PARI
1051110521
f = poly._pari_with_name()

0 commit comments

Comments
 (0)