Skip to content

Commit 030ce6d

Browse files
committed
Better error handling
1 parent 7a61d6a commit 030ce6d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/sage/rings/polynomial/polynomial_element.pyx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,8 +2172,8 @@ cdef class Polynomial(CommutativePolynomial):
21722172
return self
21732173

21742174
# We expect to succeed with greater than 1/2 probability,
2175-
# so if we try 1000 times and fail, there's a bug somewhere.
2176-
for _ in range(1000):
2175+
# so if we try 100 times and fail, there's a bug somewhere.
2176+
for _ in range(100):
21772177
# Sample a polynomial "uniformly" from R
21782178
# TODO: once #37118 has been merged, this can be made cleaner,
21792179
# as we will actually have access to uniform sampling.
@@ -2281,7 +2281,9 @@ cdef class Polynomial(CommutativePolynomial):
22812281
return poly._cantor_zassenhaus_split_to_irreducible(d)
22822282
elif ZZ(d).divides(ext_degree):
22832283
return poly._cantor_zassenhaus_split_to_irreducible(d)
2284-
raise ValueError(f"no irreducible factor could be computed from {self}")
2284+
if d > ext_degree:
2285+
raise ValueError(f"no irreducible factor of degree {degree} dividing {ext_degree} could be computed from {self}")
2286+
raise AssertionError(f"no irreducible factor could be computed from {self}")
22852287

22862288
def any_irreducible_factor(self, degree=None, assume_squarefree=False, assume_distinct_deg=False, ext_degree=None):
22872289
"""
@@ -2436,6 +2438,9 @@ cdef class Polynomial(CommutativePolynomial):
24362438
# If degree has been set, there could just be no factor of the desired degree
24372439
if degree:
24382440
raise ValueError(f"polynomial {self} has no irreducible factor of degree {degree}")
2441+
# If ext_degree has been set, then there may be no irreducible factor of degree dividing ext_degree
2442+
if ext_degree:
2443+
raise ValueError(f"polynomial {self} has no irreducible factor of degree dividing {ext_degree}")
24392444
# But if any degree is allowed then there should certainly be a factor if self has degree > 0
24402445
raise AssertionError(f"no irreducible factor was computed for {self}. Bug.")
24412446

0 commit comments

Comments
 (0)