Skip to content

Commit a875710

Browse files
author
Release Manager
committed
gh-38720: Raise exception when factoring zero polynomial <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes #12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes #12345". --> The zero polynomial doesn't have a factorization or square-free factorization, so ``` PolynomialRing(GF(7), 'x').zero().factor() PolynomialRing(GF(7), 'x').zero().squarefree_decomposition() ``` should raise errors instead of returning zero. This patch fixes this behavior. URL: #38720 Reported by: Kyle Hofmann Reviewer(s): Kwankyu Lee
2 parents 40f146b + e9b8e84 commit a875710

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/sage/rings/polynomial/polynomial_zmod_flint.pyx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,19 @@ cdef class Polynomial_zmod_flint(Polynomial_template):
762762
sage: P.<x> = GF(7)[]
763763
sage: (6*x+3).squarefree_decomposition()
764764
(6) * (x + 4)
765+
766+
Test zero polynomial::
767+
768+
sage: R.<x> = PolynomialRing(GF(65537), implementation="FLINT")
769+
sage: R.zero().squarefree_decomposition()
770+
Traceback (most recent call last):
771+
...
772+
ArithmeticError: square-free decomposition of 0 is not defined
765773
"""
774+
if self.is_zero():
775+
raise ArithmeticError(
776+
"square-free decomposition of 0 is not defined"
777+
)
766778
if not self.base_ring().is_field():
767779
raise NotImplementedError("square free factorization of polynomials over rings with composite characteristic is not implemented")
768780

@@ -803,9 +815,20 @@ cdef class Polynomial_zmod_flint(Polynomial_template):
803815
Traceback (most recent call last):
804816
...
805817
AlarmInterrupt
818+
819+
Test zero polynomial::
820+
821+
sage: R.<x> = PolynomialRing(GF(65537), implementation="FLINT")
822+
sage: R.zero().factor()
823+
Traceback (most recent call last):
824+
...
825+
ArithmeticError: factorization of 0 is not defined
826+
806827
"""
807-
R = self.base_ring()
828+
if self.is_zero():
829+
raise ArithmeticError("factorization of 0 is not defined")
808830

831+
R = self.base_ring()
809832
if not R.is_field():
810833
p,e = R.characteristic().is_prime_power(get_data=True)
811834
if not e:

0 commit comments

Comments
 (0)