@@ -1604,7 +1604,7 @@ def test_pickling():
1604
1604
1605
1605
def test_fmpz_mod ():
1606
1606
from flint import fmpz_mod_ctx , fmpz , fmpz_mod
1607
-
1607
+
1608
1608
p_sml = 163
1609
1609
p_med = 2 ** 127 - 1
1610
1610
p_big = 2 ** 255 - 19
@@ -1754,7 +1754,7 @@ def test_fmpz_mod():
1754
1754
assert raises (lambda : F_test (test_x ) * "AAA" , TypeError )
1755
1755
assert raises (lambda : F_test (test_x ) * F_other (test_x ), ValueError )
1756
1756
1757
- # Exponentiation
1757
+ # Exponentiation
1758
1758
1759
1759
assert F_test (0 )** 0 == pow (0 , 0 , test_mod )
1760
1760
assert F_test (0 )** 1 == pow (0 , 1 , test_mod )
@@ -1804,7 +1804,7 @@ def test_fmpz_mod():
1804
1804
1805
1805
assert fmpz (test_y ) / F_test (test_x ) == (test_y * pow (test_x , - 1 , test_mod )) % test_mod
1806
1806
assert test_y / F_test (test_x ) == (test_y * pow (test_x , - 1 , test_mod )) % test_mod
1807
-
1807
+
1808
1808
def test_fmpz_mod_dlog ():
1809
1809
from flint import fmpz , fmpz_mod_ctx
1810
1810
@@ -1826,7 +1826,7 @@ def test_fmpz_mod_dlog():
1826
1826
F = fmpz_mod_ctx (163 )
1827
1827
g = F (2 )
1828
1828
a = g ** 123
1829
-
1829
+
1830
1830
assert 123 == g .discrete_log (a )
1831
1831
1832
1832
a_int = pow (2 , 123 , 163 )
@@ -1877,7 +1877,7 @@ def test_fmpz_mod_poly():
1877
1877
assert repr (R3 ) == "fmpz_mod_poly_ctx(13)"
1878
1878
1879
1879
assert R1 .modulus () == 11
1880
-
1880
+
1881
1881
assert R1 .is_prime ()
1882
1882
assert R1 .zero () == 0
1883
1883
assert R1 .one () == 1
@@ -1946,7 +1946,7 @@ def test_fmpz_mod_poly():
1946
1946
assert str (f ) == "8*x^3 + 7*x^2 + 6*x + 7"
1947
1947
1948
1948
# TODO: currently repr does pretty printing
1949
- # just like str, we should address this. Mainly,
1949
+ # just like str, we should address this. Mainly,
1950
1950
# the issue is we want nice `repr` behaviour in
1951
1951
# interactive shells, which currently is why this
1952
1952
# choice has been made
@@ -1992,7 +1992,7 @@ def test_fmpz_mod_poly():
1992
1992
F_sml = fmpz_mod_ctx (p_sml )
1993
1993
F_med = fmpz_mod_ctx (p_med )
1994
1994
F_big = fmpz_mod_ctx (p_big )
1995
-
1995
+
1996
1996
R_sml = fmpz_mod_poly_ctx (F_sml )
1997
1997
R_med = fmpz_mod_poly_ctx (F_med )
1998
1998
R_big = fmpz_mod_poly_ctx (F_big )
@@ -2003,14 +2003,14 @@ def test_fmpz_mod_poly():
2003
2003
f_bad = R_cmp ([2 ,2 ,2 ,2 ,2 ])
2004
2004
2005
2005
for (F_test , R_test ) in [(F_sml , R_sml ), (F_med , R_med ), (F_big , R_big )]:
2006
-
2006
+
2007
2007
f = R_test ([- 1 ,- 2 ])
2008
2008
g = R_test ([- 3 ,- 4 ])
2009
2009
2010
2010
# pos, neg
2011
2011
assert f is + f
2012
2012
assert - f == R_test ([1 ,2 ])
2013
-
2013
+
2014
2014
# add
2015
2015
assert raises (lambda : f + f_cmp , ValueError )
2016
2016
assert raises (lambda : f + "AAA" , TypeError )
@@ -2063,7 +2063,7 @@ def test_fmpz_mod_poly():
2063
2063
assert raises (lambda : f / "AAA" , TypeError )
2064
2064
assert raises (lambda : f / 0 , ZeroDivisionError )
2065
2065
assert raises (lambda : f_cmp / 2 , ZeroDivisionError )
2066
-
2066
+
2067
2067
assert (f + f ) / 2 == f
2068
2068
assert (f + f ) / fmpz (2 ) == f
2069
2069
assert (f + f ) / F_test (2 ) == f
@@ -2077,7 +2077,7 @@ def test_fmpz_mod_poly():
2077
2077
assert (f + f ) // 2 == f
2078
2078
assert (f + f ) // fmpz (2 ) == f
2079
2079
assert (f + f ) // F_test (2 ) == f
2080
- assert 2 // R_test (2 ) == 1
2080
+ assert 2 // R_test (2 ) == 1
2081
2081
assert (f + 1 ) // f == 1
2082
2082
2083
2083
# pow
@@ -2171,7 +2171,7 @@ def test_fmpz_mod_poly():
2171
2171
f1 = R_test ([- 3 , 1 ])
2172
2172
f2 = R_test ([- 5 , 1 ])
2173
2173
assert f1 .resultant (f2 ) == (3 - 5 )
2174
- assert raises (lambda : f .resultant ("AAA" ), TypeError )
2174
+ assert raises (lambda : f .resultant ("AAA" ), TypeError )
2175
2175
2176
2176
# sqrt
2177
2177
f1 = R_test .random_element (irreducible = True )
@@ -2428,14 +2428,14 @@ def _all_polys():
2428
2428
(flint .fmpz_poly , flint .fmpz , False ),
2429
2429
(flint .fmpq_poly , flint .fmpq , True ),
2430
2430
(lambda * a : flint .nmod_poly (* a , 17 ), lambda x : flint .nmod (x , 17 ), True ),
2431
- (lambda * a : flint .fmpz_mod_poly (* a , flint .fmpz_mod_poly_ctx (163 )),
2432
- lambda x : flint .fmpz_mod (x , flint .fmpz_mod_ctx (163 )),
2431
+ (lambda * a : flint .fmpz_mod_poly (* a , flint .fmpz_mod_poly_ctx (163 )),
2432
+ lambda x : flint .fmpz_mod (x , flint .fmpz_mod_ctx (163 )),
2433
2433
True ),
2434
- (lambda * a : flint .fmpz_mod_poly (* a , flint .fmpz_mod_poly_ctx (2 ** 127 - 1 )),
2435
- lambda x : flint .fmpz_mod (x , flint .fmpz_mod_ctx (2 ** 127 - 1 )),
2434
+ (lambda * a : flint .fmpz_mod_poly (* a , flint .fmpz_mod_poly_ctx (2 ** 127 - 1 )),
2435
+ lambda x : flint .fmpz_mod (x , flint .fmpz_mod_ctx (2 ** 127 - 1 )),
2436
2436
True ),
2437
- (lambda * a : flint .fmpz_mod_poly (* a , flint .fmpz_mod_poly_ctx (2 ** 255 - 19 )),
2438
- lambda x : flint .fmpz_mod (x , flint .fmpz_mod_ctx (2 ** 255 - 19 )),
2437
+ (lambda * a : flint .fmpz_mod_poly (* a , flint .fmpz_mod_poly_ctx (2 ** 255 - 19 )),
2438
+ lambda x : flint .fmpz_mod (x , flint .fmpz_mod_ctx (2 ** 255 - 19 )),
2439
2439
True ),
2440
2440
]
2441
2441
@@ -2467,6 +2467,28 @@ def test_polys():
2467
2467
assert (P ([1 ]) == P ([2 ])) is False
2468
2468
assert (P ([1 ]) != P ([2 ])) is True
2469
2469
2470
+ assert (P ([1 ]) == 1 ) is True
2471
+ assert (P ([1 ]) != 1 ) is False
2472
+ assert (P ([1 ]) == 2 ) is False
2473
+ assert (P ([1 ]) != 2 ) is True
2474
+
2475
+ assert (1 == P ([1 ])) is True
2476
+ assert (1 != P ([1 ])) is False
2477
+ assert (2 == P ([1 ])) is False
2478
+ assert (2 != P ([1 ])) is True
2479
+
2480
+ s1 , s2 = S (1 ), S (2 )
2481
+
2482
+ assert (P ([s1 ]) == s1 ) is True
2483
+ assert (P ([s1 ]) != s1 ) is False
2484
+ assert (P ([s1 ]) == s2 ) is False
2485
+ assert (P ([s1 ]) != s2 ) is True
2486
+
2487
+ assert (s1 == P ([s1 ])) is True
2488
+ assert (s1 != P ([s1 ])) is False
2489
+ assert (s1 == P ([s2 ])) is False
2490
+ assert (s1 != P ([s2 ])) is True
2491
+
2470
2492
assert (P ([1 ]) == None ) is False
2471
2493
assert (P ([1 ]) != None ) is True
2472
2494
assert (None == P ([1 ])) is False
@@ -2500,12 +2522,17 @@ def setbad(obj, i, val):
2500
2522
assert raises (lambda : setbad (p , - 1 , 1 ), ValueError )
2501
2523
2502
2524
for v in [], [1 ], [1 , 2 ]:
2503
- if P == flint .fmpz_poly :
2525
+ p = P (v )
2526
+ if type (p ) == flint .fmpz_poly :
2504
2527
assert P (v ).repr () == f'fmpz_poly({ v !r} )'
2505
- elif P == flint .fmpq_poly :
2528
+ elif type ( p ) == flint .fmpq_poly :
2506
2529
assert P (v ).repr () == f'fmpq_poly({ v !r} )'
2507
- elif P == flint .nmod_poly :
2530
+ elif type ( p ) == flint .nmod_poly :
2508
2531
assert P (v ).repr () == f'nmod_poly({ v !r} , 17)'
2532
+ elif type (p ) == flint .fmpz_mod_poly :
2533
+ pass # fmpz_mod_poly does not have .repr() ...
2534
+ else :
2535
+ assert False
2509
2536
2510
2537
assert repr (P ([])) == '0'
2511
2538
assert repr (P ([1 ])) == '1'
@@ -2521,6 +2548,12 @@ def setbad(obj, i, val):
2521
2548
assert bool (P ([])) is False
2522
2549
assert bool (P ([1 ])) is True
2523
2550
2551
+ assert P ([]).is_zero () is True
2552
+ assert P ([1 ]).is_zero () is False
2553
+
2554
+ assert P ([]).is_one () is False
2555
+ assert P ([1 ]).is_one () is True
2556
+
2524
2557
assert + P ([1 , 2 , 3 ]) == P ([1 , 2 , 3 ])
2525
2558
assert - P ([1 , 2 , 3 ]) == P ([- 1 , - 2 , - 3 ])
2526
2559
@@ -2600,7 +2633,7 @@ def setbad(obj, i, val):
2600
2633
assert P ([1 , 1 ]) ** 2 == P ([1 , 2 , 1 ])
2601
2634
assert raises (lambda : P ([1 , 1 ]) ** - 1 , ValueError )
2602
2635
assert raises (lambda : P ([1 , 1 ]) ** None , TypeError )
2603
-
2636
+
2604
2637
# # XXX: Not sure what this should do in general:
2605
2638
assert raises (lambda : pow (P ([1 , 1 ]), 2 , 3 ), NotImplementedError )
2606
2639
@@ -2825,6 +2858,12 @@ def quick_poly():
2825
2858
assert bool (P (ctx = ctx )) is False
2826
2859
assert bool (P (1 , ctx = ctx )) is True
2827
2860
2861
+ assert P (ctx = ctx ).is_zero () is True
2862
+ assert P (1 , ctx = ctx ).is_zero () is False
2863
+
2864
+ assert P (ctx = ctx ).is_one () is False
2865
+ assert P (1 , ctx = ctx ).is_one () is True
2866
+
2828
2867
assert + quick_poly () \
2829
2868
== quick_poly ()
2830
2869
assert - quick_poly () \
0 commit comments