@@ -2854,14 +2854,18 @@ def quick_poly():
28542854
28552855 assert + quick_poly () \
28562856 == quick_poly ()
2857- # assert -quick_poly() \
2858- # == mpoly({(0, 0): -1, (0, 1): -2, (1, 0): -3, (2, 2): -4})
2857+
2858+ assert - quick_poly () \
2859+ == mpoly (
2860+ {(0 , 0 ): - 1 , (0 , 1 ): - 2 , (1 , 0 ): - 3 , (2 , 2 ): - 4 } if P is not flint .nmod_mpoly
2861+ else {k : ctx .modulus () + v for k , v in {(0 , 0 ): - 1 , (0 , 1 ): - 2 , (1 , 0 ): - 3 , (2 , 2 ): - 4 }.items ()}
2862+ )
28592863
28602864 assert quick_poly () \
28612865 + mpoly ({(0 , 0 ): 5 , (0 , 1 ): 6 , (1 , 0 ): 7 , (2 , 2 ): 8 }) \
28622866 == mpoly ({(0 , 0 ): 6 , (0 , 1 ): 8 , (1 , 0 ): 10 , (2 , 2 ): 12 })
28632867
2864- for T in [int , S , flint . fmpz , lambda x : P (x , ctx = ctx )]:
2868+ for T in [int , S , lambda x : P (x , ctx = ctx )]:
28652869 p = quick_poly ()
28662870 p += T (1 )
28672871 q = quick_poly ()
@@ -2875,24 +2879,31 @@ def quick_poly():
28752879 assert raises (lambda : None + mpoly ({(0 , 0 ): 2 , (0 , 1 ): 2 , (1 , 0 ): 3 , (2 , 2 ): 4 }), TypeError )
28762880 assert raises (lambda : quick_poly () + P (ctx = ctx1 ), IncompatibleContextError )
28772881 assert raises (lambda : quick_poly ().iadd (P (ctx = ctx1 )), IncompatibleContextError )
2878- # assert raises(lambda: quick_poly().iadd(None), NotImplementedError)
2882+ assert raises (lambda : quick_poly ().iadd (None ), NotImplementedError )
28792883
2880- # assert quick_poly() - mpoly({(0, 0): 5, (0, 1): 6, (1, 0): 7, (2, 2): 8}) \
2881- # == mpoly({(0, 0): -4, (0, 1): -4, (1, 0): -4, (2, 2): -4})
2884+ assert quick_poly () - mpoly ({(0 , 0 ): 5 , (0 , 1 ): 6 , (1 , 0 ): 7 , (2 , 2 ): 8 }) \
2885+ == mpoly (
2886+ {(0 , 0 ): - 4 , (0 , 1 ): - 4 , (1 , 0 ): - 4 , (2 , 2 ): - 4 } if P is not flint .nmod_mpoly
2887+ else {k : ctx .modulus () + v for k , v in {(0 , 0 ): - 4 , (0 , 1 ): - 4 , (1 , 0 ): - 4 , (2 , 2 ): - 4 }.items ()}
2888+ )
28822889
2883- for T in [int , S , flint . fmpz , lambda x : P (x , ctx = ctx )]:
2890+ for T in [int , S , lambda x : P (x , ctx = ctx )]:
28842891 p = quick_poly ()
28852892 p -= T (1 )
28862893 q = quick_poly ()
28872894 assert q .isub (T (1 )) is None
28882895 assert quick_poly () - T (1 ) == p == q == mpoly ({(0 , 1 ): 2 , (1 , 0 ): 3 , (2 , 2 ): 4 })
2889- # assert T(1) - quick_poly() == mpoly({(0, 1): -2, (1, 0): -3, (2, 2): -4})
2896+ assert T (1 ) - quick_poly () == \
2897+ mpoly (
2898+ {(0 , 1 ): - 2 , (1 , 0 ): - 3 , (2 , 2 ): - 4 } if P is not flint .nmod_mpoly
2899+ else {k : ctx .modulus () + v for k , v in {(0 , 1 ): - 2 , (1 , 0 ): - 3 , (2 , 2 ): - 4 }.items ()}
2900+ )
28902901
28912902 assert raises (lambda : quick_poly () - None , TypeError )
28922903 assert raises (lambda : None - quick_poly (), TypeError )
28932904 assert raises (lambda : quick_poly () - P (ctx = ctx1 ), IncompatibleContextError )
28942905 assert raises (lambda : quick_poly ().isub (P (ctx = ctx1 )), IncompatibleContextError )
2895- # assert raises(lambda: quick_poly().isub(None), NotImplementedError)
2906+ assert raises (lambda : quick_poly ().isub (None ), NotImplementedError )
28962907
28972908 assert quick_poly () * mpoly ({(1 , 0 ): 5 , (0 , 1 ): 6 }) \
28982909 == mpoly ({
@@ -2905,7 +2916,7 @@ def quick_poly():
29052916 (0 , 1 ): 6
29062917 })
29072918
2908- for T in [int , S , flint . fmpz , lambda x : P (x , ctx = ctx )]:
2919+ for T in [int , S , lambda x : P (x , ctx = ctx )]:
29092920 p = quick_poly ()
29102921 p *= T (2 )
29112922 q = quick_poly ()
@@ -2917,7 +2928,7 @@ def quick_poly():
29172928 assert raises (lambda : None * quick_poly (), TypeError )
29182929 assert raises (lambda : quick_poly () * P (ctx = ctx1 ), IncompatibleContextError )
29192930 assert raises (lambda : quick_poly ().imul (P (ctx = ctx1 )), IncompatibleContextError )
2920- # assert raises(lambda: quick_poly().imul(None), NotImplementedError)
2931+ assert raises (lambda : quick_poly ().imul (None ), NotImplementedError )
29212932
29222933 if (P is flint .fmpz_mod_mpoly or P is flint .nmod_mpoly ) and not ctx .is_prime ():
29232934 assert raises (lambda : quick_poly () // mpoly ({(1 , 1 ): 1 }), DomainError )
@@ -3023,7 +3034,11 @@ def quick_poly():
30233034 else :
30243035 assert raises (lambda : (f * g ).gcd (f ), DomainError )
30253036
3026- # assert (f * g).factor() == (S(2), [(mpoly({(0, 1): 1, (1, 0): 1}), 1), (f, 1)])
3037+ if P is flint .fmpz_mod_mpoly or P is flint .nmod_mpoly :
3038+ if is_field :
3039+ assert (f * g ).factor () == (S (8 ), [(mpoly ({(0 , 1 ): 1 , (1 , 0 ): 1 }), 1 ), (f / 4 , 1 )])
3040+ else :
3041+ assert (f * g ).factor () == (S (2 ), [(mpoly ({(0 , 1 ): 1 , (1 , 0 ): 1 }), 1 ), (f , 1 )])
30273042
30283043 if (P is not flint .fmpz_mod_mpoly and P is not flint .nmod_mpoly ) or f .context ().is_prime ():
30293044 assert (f * f ).sqrt () == f
0 commit comments