@@ -2834,6 +2834,42 @@ def setbad(obj, i, val):
28342834 if type (p ) == flint .fq_default_poly :
28352835 assert raises (lambda : p .integral (), NotImplementedError )
28362836
2837+ # resultant checks.
2838+ x = P ([0 , 1 ])
2839+
2840+ if composite_characteristic and type (x ) in [flint .fmpz_mod_poly , flint .nmod_poly ]:
2841+ # Flint sometimes crashes in this case, even though the resultant
2842+ # could be computed.
2843+ divisor = characteristic .factor ()[0 ][0 ]
2844+ assert raises (lambda : x .resultant (x + divisor ), ValueError )
2845+ elif type (x ) == flint .fq_default_poly :
2846+ # Flint does not implement resultants over GF(q) for nonprime q, so
2847+ # there's nothing for us to check.
2848+ pass
2849+ else :
2850+ assert x .resultant (x ) == 0
2851+ assert x .resultant (x ** 2 + x - x ) == 0
2852+ assert x .resultant (x ** 10 - x ** 5 + 1 ) == S (1 )
2853+ assert (x - 1 ).resultant (x ** 5 + 1 ) == S (2 )
2854+
2855+ for k in range (- 10 , 10 ):
2856+ assert x .resultant (x + S (k )) == S (k )
2857+
2858+ def test_poly_resultants ():
2859+ # Check that the resultant of two cyclotomic polynomials is right.
2860+ # See Dresden's 2012 "Resultants of Cyclotomic Polynomials"
2861+ for m in range (1 , 50 ):
2862+ for n in range (m + 1 , 50 ):
2863+ a = flint .fmpz_poly .cyclotomic (m )
2864+ b = flint .fmpz_poly .cyclotomic (n )
2865+ q , r = divmod (flint .fmpz (n ), flint .fmpz (m ))
2866+ fs = q .factor ()
2867+ if r != 0 or len (fs ) > 1 :
2868+ assert a .resultant (b ) == 1
2869+ else :
2870+ prime = fs [0 ][0 ]
2871+ tot = flint .fmpz (m ).euler_phi ()
2872+ assert a .resultant (b ) == prime ** tot
28372873
28382874def _all_mpolys ():
28392875 return [
@@ -2869,7 +2905,6 @@ def _all_mpolys():
28692905 ),
28702906 ]
28712907
2872-
28732908def test_mpolys ():
28742909 for P , get_context , S , is_field , characteristic in _all_mpolys ():
28752910
@@ -4832,6 +4867,8 @@ def test_all_tests():
48324867 test_polys ,
48334868 test_mpolys ,
48344869
4870+ test_poly_resultants ,
4871+
48354872 test_fmpz_mpoly_vec ,
48364873
48374874 test_matrices_eq ,
0 commit comments