Skip to content

Commit

Permalink
Trac #34371: support factoring polynomials modulo prime powers
Browse files Browse the repository at this point in the history
Currently, `Polynomial_zmod_flint` refuses to factor polynomials modulo
composites, which is generally not well-defined. However, we can easily
make this work modulo prime powers (where it ''is'' well-defined) by
reusing the implementation for polynomials over p‑adics. This is almost
certainly not the fastest way of doing it, but at least it ''works''.

URL: https://trac.sagemath.org/34371
Reported by: lorenz
Ticket author(s): Lorenz Panny
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Aug 29, 2022
2 parents 8a12a20 + 19018bb commit e874714
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/sage/rings/polynomial/polynomial_zmod_flint.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -736,19 +736,36 @@ cdef class Polynomial_zmod_flint(Polynomial_template):
sage: (x^2 + 1).factor()
(x + 2) * (x + 3)
It also works for prime-power moduli::
sage: R.<x> = Zmod(23^5)[]
sage: (x^3 + 1).factor()
(x + 1) * (x^2 + 6436342*x + 1)
TESTS::
sage: R.<x> = GF(5)[]
sage: (2*x^2 + 2).factor()
(2) * (x + 2) * (x + 3)
sage: P.<x> = Zmod(10)[]
sage: (x^2).factor()
Traceback (most recent call last):
...
NotImplementedError: factorization of polynomials over rings with composite characteristic is not implemented
"""
if not self.base_ring().is_field():
raise NotImplementedError("factorization of polynomials over rings with composite characteristic is not implemented")
R = self.base_ring()

if not R.is_field():
p,e = R.characteristic().is_prime_power(get_data=True)
if not e:
raise NotImplementedError("factorization of polynomials over rings with composite characteristic is not implemented")

# Factoring is well-defined for prime-power moduli.
# For simplicity we reuse the implementation for p-adics;
# presumably this can be done faster.
from sage.rings.padics.factory import Zp
f = self.change_ring(Zp(p, prec=e))
return f.factor().base_change(self.parent())

return factor_helper(self)

Expand Down

0 comments on commit e874714

Please sign in to comment.