@@ -2481,41 +2481,41 @@ def test_division_matrix():
2481
2481
def _all_polys ():
2482
2482
return [
2483
2483
# (poly_type, scalar_type, is_field)
2484
- (flint .fmpz_poly , flint .fmpz , False ),
2485
- (flint .fmpq_poly , flint .fmpq , True ),
2486
- (lambda * a : flint .nmod_poly (* a , 17 ), lambda x : flint .nmod (x , 17 ), True ),
2484
+ (flint .fmpz_poly , flint .fmpz , False , flint . fmpz ( 0 ) ),
2485
+ (flint .fmpq_poly , flint .fmpq , True , flint . fmpz ( 0 ) ),
2486
+ (lambda * a : flint .nmod_poly (* a , 17 ), lambda x : flint .nmod (x , 17 ), True , flint . fmpz ( 17 ) ),
2487
2487
(lambda * a : flint .fmpz_mod_poly (* a , flint .fmpz_mod_poly_ctx (163 )),
2488
2488
lambda x : flint .fmpz_mod (x , flint .fmpz_mod_ctx (163 )),
2489
- True ),
2489
+ True , flint . fmpz ( 163 ) ),
2490
2490
(lambda * a : flint .fmpz_mod_poly (* a , flint .fmpz_mod_poly_ctx (2 ** 127 - 1 )),
2491
2491
lambda x : flint .fmpz_mod (x , flint .fmpz_mod_ctx (2 ** 127 - 1 )),
2492
- True ),
2492
+ True , flint . fmpz ( 2 ** 127 - 1 ) ),
2493
2493
(lambda * a : flint .fmpz_mod_poly (* a , flint .fmpz_mod_poly_ctx (2 ** 255 - 19 )),
2494
2494
lambda x : flint .fmpz_mod (x , flint .fmpz_mod_ctx (2 ** 255 - 19 )),
2495
- True ),
2495
+ True , flint . fmpz ( 2 ** 255 - 19 ) ),
2496
2496
(lambda * a : flint .fq_default_poly (* a , flint .fq_default_poly_ctx (2 ** 127 - 1 )),
2497
2497
lambda x : flint .fq_default (x , flint .fq_default_ctx (2 ** 127 - 1 )),
2498
- True ),
2498
+ True , flint . fmpz ( 2 ** 127 - 1 ) ),
2499
2499
(lambda * a : flint .fq_default_poly (* a , flint .fq_default_poly_ctx (2 ** 127 - 1 , 2 )),
2500
2500
lambda x : flint .fq_default (x , flint .fq_default_ctx (2 ** 127 - 1 , 2 )),
2501
- True ),
2501
+ True , flint . fmpz ( 2 ** 127 - 1 ) ),
2502
2502
(lambda * a : flint .fq_default_poly (* a , flint .fq_default_poly_ctx (65537 )),
2503
2503
lambda x : flint .fq_default (x , flint .fq_default_ctx (65537 )),
2504
- True ),
2504
+ True , flint . fmpz ( 65537 ) ),
2505
2505
(lambda * a : flint .fq_default_poly (* a , flint .fq_default_poly_ctx (65537 , 5 )),
2506
2506
lambda x : flint .fq_default (x , flint .fq_default_ctx (65537 , 5 )),
2507
- True ),
2507
+ True , flint . fmpz ( 65537 ) ),
2508
2508
(lambda * a : flint .fq_default_poly (* a , flint .fq_default_poly_ctx (11 )),
2509
2509
lambda x : flint .fq_default (x , flint .fq_default_ctx (11 )),
2510
- True ),
2510
+ True , flint . fmpz ( 11 ) ),
2511
2511
(lambda * a : flint .fq_default_poly (* a , flint .fq_default_poly_ctx (11 , 5 )),
2512
2512
lambda x : flint .fq_default (x , flint .fq_default_ctx (11 , 5 )),
2513
- True ),
2513
+ True , flint . fmpz ( 11 ) ),
2514
2514
]
2515
2515
2516
2516
2517
2517
def test_polys ():
2518
- for P , S , is_field in _all_polys ():
2518
+ for P , S , is_field , characteristic in _all_polys ():
2519
2519
assert P ([S (1 )]) == P ([1 ]) == P (P ([1 ])) == P (1 )
2520
2520
2521
2521
assert raises (lambda : P ([None ]), TypeError )
@@ -2750,37 +2750,41 @@ def setbad(obj, i, val):
2750
2750
2751
2751
def _all_mpolys ():
2752
2752
return [
2753
- (flint .fmpz_mpoly , flint .fmpz_mpoly_ctx .get_context , flint .fmpz , False ),
2754
- (flint .fmpq_mpoly , flint .fmpq_mpoly_ctx .get_context , flint .fmpq , True ),
2753
+ (flint .fmpz_mpoly , flint .fmpz_mpoly_ctx .get_context , flint .fmpz , False , flint . fmpz ( 0 ) ),
2754
+ (flint .fmpq_mpoly , flint .fmpq_mpoly_ctx .get_context , flint .fmpq , True , flint . fmpz ( 0 ) ),
2755
2755
(
2756
2756
flint .fmpz_mod_mpoly ,
2757
2757
lambda * args , ** kwargs : flint .fmpz_mod_mpoly_ctx .get_context (* args , ** kwargs , modulus = 101 ),
2758
2758
lambda x : flint .fmpz_mod (x , flint .fmpz_mod_ctx (101 )),
2759
2759
True ,
2760
+ flint .fmpz (101 ),
2760
2761
),
2761
2762
(
2762
2763
flint .fmpz_mod_mpoly ,
2763
2764
lambda * args , ** kwargs : flint .fmpz_mod_mpoly_ctx .get_context (* args , ** kwargs , modulus = 100 ),
2764
2765
lambda x : flint .fmpz_mod (x , flint .fmpz_mod_ctx (100 )),
2765
2766
False ,
2767
+ flint .fmpz (100 ),
2766
2768
),
2767
2769
(
2768
2770
flint .nmod_mpoly ,
2769
2771
lambda * args , ** kwargs : flint .nmod_mpoly_ctx .get_context (* args , ** kwargs , modulus = 101 ),
2770
2772
lambda x : flint .nmod (x , 101 ),
2771
2773
True ,
2774
+ flint .fmpz (101 ),
2772
2775
),
2773
2776
(
2774
2777
flint .nmod_mpoly ,
2775
2778
lambda * args , ** kwargs : flint .nmod_mpoly_ctx .get_context (* args , ** kwargs , modulus = 100 ),
2776
2779
lambda x : flint .nmod (x , 100 ),
2777
2780
False ,
2781
+ flint .fmpz (100 ),
2778
2782
),
2779
2783
]
2780
2784
2781
2785
2782
2786
def test_mpolys ():
2783
- for P , get_context , S , is_field in _all_mpolys ():
2787
+ for P , get_context , S , is_field , characteristic in _all_mpolys ():
2784
2788
2785
2789
# Division under modulo will raise a flint exception if something is not invertible, crashing the program. We
2786
2790
# can't tell before what is invertible and what is not before hand so we always raise an exception, except for
@@ -3235,7 +3239,7 @@ def test_fmpz_mpoly_vec():
3235
3239
3236
3240
def _all_polys_mpolys ():
3237
3241
3238
- for P , S , is_field in _all_polys ():
3242
+ for P , S , is_field , characteristic in _all_polys ():
3239
3243
x = P ([0 , 1 ])
3240
3244
y = None
3241
3245
assert isinstance (x , (
@@ -3245,18 +3249,18 @@ def _all_polys_mpolys():
3245
3249
flint .fmpz_mod_poly ,
3246
3250
flint .fq_default_poly ,
3247
3251
))
3248
- characteristic_zero = isinstance (x , (flint .fmpz_poly , flint .fmpq_poly ))
3249
- yield P , S , [x , y ], is_field , characteristic_zero
3252
+ yield P , S , [x , y ], is_field , characteristic
3250
3253
3251
- for P , ctx_type , S , is_field in _all_mpolys ():
3252
- ctx = ctx_type (2 , flint .Ordering .lex , [ "x" , "y" ] )
3254
+ for P , get_context , S , is_field , characteristic in _all_mpolys ():
3255
+ ctx = get_context (2 , flint .Ordering .lex , nametup = ( "x" , "y" ) )
3253
3256
x , y = ctx .gens ()
3254
3257
assert isinstance (x , (
3255
3258
flint .fmpz_mpoly ,
3256
3259
flint .fmpq_mpoly ,
3260
+ flint .nmod_mpoly ,
3261
+ flint .fmpz_mod_mpoly ,
3257
3262
))
3258
- characteristic_zero = isinstance (x , (flint .fmpz_mpoly , flint .fmpq_mpoly ))
3259
- yield P , S , [x , y ], is_field , characteristic_zero
3263
+ yield P , S , [x , y ], is_field , characteristic
3260
3264
3261
3265
3262
3266
def test_factor_poly_mpoly ():
@@ -3273,7 +3277,11 @@ def factor(p):
3273
3277
assert type (m ) is int
3274
3278
return coeff , sorted (factors , key = lambda p : (p [1 ], str (p [0 ])))
3275
3279
3276
- for P , S , [x , y ], is_field , characteristic_zero in _all_polys_mpolys ():
3280
+ for P , S , [x , y ], is_field , characteristic in _all_polys_mpolys ():
3281
+
3282
+ if characteristic != 0 and not characteristic .is_prime ():
3283
+ assert raises (lambda : x .factor (), DomainError )
3284
+ continue
3277
3285
3278
3286
assert factor (0 * x ) == (S (0 ), [])
3279
3287
assert factor (0 * x + 1 ) == (S (1 ), [])
@@ -3284,15 +3292,15 @@ def factor(p):
3284
3292
assert factor (x * (x + 1 )) == (S (1 ), [(x , 1 ), (x + 1 , 1 )])
3285
3293
assert factor (2 * (x + 1 )) == (S (2 ), [(x + 1 , 1 )])
3286
3294
3287
- if characteristic_zero :
3295
+ if characteristic == 0 :
3288
3296
# primitive factors over Z for Z and Q.
3289
3297
assert factor (2 * x + 1 ) == (S (1 ), [(2 * x + 1 , 1 )])
3290
3298
else :
3291
3299
# monic factors over Z/pZ and GF(p^d)
3292
3300
assert factor (2 * x + 1 ) == (S (2 ), [(x + S (1 )/ 2 , 1 )])
3293
3301
3294
3302
if is_field :
3295
- if characteristic_zero :
3303
+ if characteristic == 0 :
3296
3304
assert factor ((2 * x + 1 )/ 7 ) == (S (1 )/ 7 , [(2 * x + 1 , 1 )])
3297
3305
else :
3298
3306
assert factor ((2 * x + 1 )/ 7 ) == (S (2 )/ 7 , [(x + S (1 )/ 2 , 1 )])
@@ -3302,13 +3310,13 @@ def factor(p):
3302
3310
assert factor (x * y + 1 ) == (S (1 ), [(x * y + 1 , 1 )])
3303
3311
assert factor (x * y ) == (S (1 ), [(x , 1 ), (y , 1 )])
3304
3312
3305
- if characteristic_zero :
3313
+ if characteristic == 0 :
3306
3314
assert factor (2 * x + y ) == (S (1 ), [(2 * x + y , 1 )])
3307
3315
else :
3308
- assert factor (2 * x + y ) == (S (1 ) / 2 , [(x + y / 2 , 1 )])
3316
+ assert factor (2 * x + y ) == (S (2 ) , [(x + y / 2 , 1 )])
3309
3317
3310
3318
if is_field :
3311
- if characteristic_zero :
3319
+ if characteristic == 0 :
3312
3320
assert factor ((2 * x + y )/ 7 ) == (S (1 )/ 7 , [(2 * x + y , 1 )])
3313
3321
else :
3314
3322
assert factor ((2 * x + y )/ 7 ) == (S (2 )/ 7 , [(x + y / 2 , 1 )])
0 commit comments