@@ -2173,7 +2173,7 @@ def test_fmpz_mod_poly():
2173
2173
assert raises (lambda : f_bad .divmod (f_bad ), ValueError )
2174
2174
2175
2175
# gcd
2176
- assert raises (lambda : f_cmp .gcd (f_cmp ), NotImplementedError )
2176
+ assert raises (lambda : f_cmp .gcd (f_cmp ), DomainError )
2177
2177
assert raises (lambda : f .gcd ("f" ), TypeError )
2178
2178
2179
2179
# xgcd
@@ -2766,7 +2766,7 @@ def setbad(obj, i, val):
2766
2766
pass
2767
2767
else :
2768
2768
# Z/nZ for n not prime
2769
- assert raises (lambda : P ([1 , 2 , 1 ]).gcd (P ([1 , 1 ])), NotImplementedError )
2769
+ assert raises (lambda : P ([1 , 2 , 1 ]).gcd (P ([1 , 1 ])), DomainError )
2770
2770
assert raises (lambda : P ([1 , 2 , 1 ]).gcd (None ), TypeError )
2771
2771
2772
2772
if is_field :
@@ -2846,11 +2846,12 @@ def _all_mpolys():
2846
2846
def test_mpolys ():
2847
2847
for P , get_context , S , is_field , characteristic in _all_mpolys ():
2848
2848
2849
- # Division under modulo will raise a flint exception if something is not invertible, crashing the program. We
2850
- # can't tell before what is invertible and what is not before hand so we always raise an exception, except for
2851
- # fmpz_mpoly, that returns an bool noting if the division is exact or not.
2852
- division_not_supported = P is not flint .fmpz_mpoly and not is_field
2853
- characteristic_zero = not (P is flint .fmpz_mod_mpoly or P is flint .nmod_mpoly )
2849
+ # Division under modulo will raise a flint exception if something is
2850
+ # not invertible, crashing the program. We can't tell before what is
2851
+ # invertible and what is not before hand so we always raise an
2852
+ # exception, except for fmpz_mpoly, that returns an bool noting if the
2853
+ # division is exact or not.
2854
+ composite_characteristic = characteristic != 0 and not characteristic .is_prime ()
2854
2855
2855
2856
ctx = get_context (nvars = 2 )
2856
2857
@@ -3115,7 +3116,7 @@ def quick_poly():
3115
3116
assert raises (lambda : quick_poly ().imul (P (ctx = ctx1 )), IncompatibleContextError )
3116
3117
assert raises (lambda : quick_poly ().imul (None ), NotImplementedError )
3117
3118
3118
- if division_not_supported :
3119
+ if composite_characteristic :
3119
3120
assert raises (lambda : quick_poly () // mpoly ({(1 , 1 ): 1 }), DomainError )
3120
3121
assert raises (lambda : quick_poly () % mpoly ({(1 , 1 ): 1 }), DomainError )
3121
3122
assert raises (lambda : divmod (quick_poly (), mpoly ({(1 , 1 ): 1 })), DomainError )
@@ -3145,7 +3146,7 @@ def quick_poly():
3145
3146
3146
3147
f = mpoly ({(1 , 1 ): 4 , (0 , 0 ): 1 })
3147
3148
g = mpoly ({(0 , 1 ): 2 , (1 , 0 ): 2 })
3148
- if not division_not_supported :
3149
+ if not composite_characteristic :
3149
3150
assert 1 // quick_poly () == P (ctx = ctx )
3150
3151
assert 1 % quick_poly () == P (1 , ctx = ctx )
3151
3152
assert divmod (1 , quick_poly ()) == (P (ctx = ctx ), P (1 , ctx = ctx ))
@@ -3212,7 +3213,7 @@ def quick_poly():
3212
3213
# # XXX: Not sure what this should do in general:
3213
3214
assert raises (lambda : pow (P (1 , ctx = ctx ), 2 , 3 ), NotImplementedError )
3214
3215
3215
- if division_not_supported :
3216
+ if composite_characteristic :
3216
3217
assert raises (lambda : (f * g ).gcd (f ), DomainError )
3217
3218
else :
3218
3219
if is_field :
@@ -3222,18 +3223,18 @@ def quick_poly():
3222
3223
assert raises (lambda : quick_poly ().gcd (None ), TypeError )
3223
3224
assert raises (lambda : quick_poly ().gcd (P (ctx = ctx1 )), IncompatibleContextError )
3224
3225
3225
- if division_not_supported :
3226
+ if composite_characteristic :
3226
3227
# Factorisation not allowed over Z/nZ for n not prime.
3227
3228
# Flint would abort so we raise an exception instead:
3228
3229
assert raises (lambda : (f * g ).factor (), DomainError )
3229
- elif characteristic_zero :
3230
+ elif characteristic == 0 :
3230
3231
# Primitive factors over Z for fmpz_mpoly and fmpq_mpoly
3231
3232
assert (f * g ).factor () == (S (2 ), [(g / 2 , 1 ), (f , 1 )])
3232
3233
elif is_field :
3233
3234
# Monic polynomials over Z/pZ for nmod_mpoly and fmpz_mod_mpoly
3234
3235
assert (f * g ).factor () == (S (8 ), [(g / 2 , 1 ), (f / 4 , 1 )])
3235
3236
3236
- if division_not_supported :
3237
+ if composite_characteristic :
3237
3238
assert raises (lambda : (f * g ).sqrt (), DomainError )
3238
3239
else :
3239
3240
assert (f * f ).sqrt () == f
@@ -3365,11 +3366,21 @@ def factor_sqf(p):
3365
3366
# https://github.com/flintlib/python-flint/issues/124
3366
3367
# so we can't even test it...
3367
3368
nmod_poly_will_crash = type (x ) is flint .nmod_poly
3369
+ if nmod_poly_will_crash :
3370
+ continue
3368
3371
3369
- if not nmod_poly_will_crash :
3370
- assert raises (lambda : x .factor (), DomainError )
3371
-
3372
- # All tests below would raise
3372
+ try :
3373
+ S (4 ).sqrt () ** 2 == S (4 )
3374
+ except DomainError :
3375
+ pass
3376
+ assert raises (lambda : (x ** 2 ).sqrt (), DomainError )
3377
+ assert raises (lambda : x .gcd (x ), DomainError )
3378
+ assert raises (lambda : x .gcd (None ), TypeError )
3379
+ assert raises (lambda : x .factor (), DomainError )
3380
+ assert raises (lambda : x .factor_squarefree (), DomainError )
3381
+
3382
+ # All tests below can be expected to raise DomainError
3383
+ # Not sure if that is guaranteed in all cases though...
3373
3384
continue
3374
3385
3375
3386
assert S (0 ).sqrt () == S (0 )
0 commit comments