Skip to content

Commit 658e502

Browse files
committed
Check for composite moduli in resultants
1 parent 86ffb15 commit 658e502

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/flint/test/test_all.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2853,17 +2853,25 @@ def setbad(obj, i, val):
28532853
assert a.resultant(b) == prime**tot
28542854

28552855
x = P([0, 1])
2856-
# Flint does not implement resultants over GF(q) for nonprime q, so we
2857-
# there's nothing for us to check.
2858-
if composite_characteristic or type(x) == flint.fq_default_poly:
2856+
2857+
if composite_characteristic and type(x) == flint.fmpz_mod_poly:
2858+
# Flint crashes in this case, even though the resultant could be
2859+
# computed.
2860+
divisor = characteristic.factor()[0][0]
2861+
if type(x) == flint.fmpz_mod_poly:
2862+
assert raises(lambda: x.resultant(x + divisor), ValueError)
2863+
elif type(x) == flint.fq_default_poly:
2864+
# Flint does not implement resultants over GF(q) for nonprime q, so
2865+
# there's nothing for us to check.
28592866
pass
28602867
else:
28612868
assert x.resultant(x) == 0
28622869
assert x.resultant(x**2 + x - x) == 0
2870+
assert x.resultant(x**10 - x**5 + 1) == S(1)
2871+
assert (x - 1).resultant(x**5 + 1) == S(2)
28632872

28642873
for k in range(-10, 10):
28652874
assert x.resultant(x + S(k)) == S(k)
2866-
assert x.resultant(x**10 - x**5 + 1) == S(1)
28672875

28682876
def _all_mpolys():
28692877
return [

src/flint/types/fmpz_mod_poly.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,9 @@ cdef class fmpz_mod_poly(flint_poly):
14651465
"""
14661466
cdef fmpz_mod res
14671467

1468+
if not self.ctx.mod.is_prime():
1469+
raise ValueError("cannot compute fmpz_mod_poly resultants with composite moduli")
1470+
14681471
other = self.ctx.any_as_fmpz_mod_poly(other)
14691472
if other is NotImplemented:
14701473
raise TypeError(f"Cannot interpret {other} as a polynomial")

0 commit comments

Comments
 (0)