Skip to content

Commit 4fc91e1

Browse files
committed
#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.
1 parent c3028e7 commit 4fc91e1

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
@@ -10509,11 +10509,21 @@ def _factor_univariate_polynomial(self, poly, **kwargs):
1050910509
sage: x = polygen(K,'x')
1051010510
sage: factor(x*x+4) # indirect doctest
1051110511
(x - 2*i) * (x + 2*i)
10512+
10513+
TESTS::
10514+
10515+
sage: with seed(0):
10516+
....: P.<y> = NumberField(QQ['a'].random_element(30,10^100), 'a')[]
10517+
sage: (3*y^4/4).factor()
10518+
(3/4) * y^4
1051210519
"""
1051310520
if self.degree() == 1:
1051410521
factors = poly.change_ring(QQ).factor()
1051510522
return Factorization([(p.change_ring(self), e)
1051610523
for p, e in factors], self(factors.unit()))
10524+
elif poly.is_term():
10525+
return Factorization([(poly.parent().gen(), poly.degree())],
10526+
poly.leading_coefficient())
1051710527

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

0 commit comments

Comments
 (0)