@@ -4483,180 +4483,180 @@ def test_matrices_transpose():
4483
4483
# assert raises(lambda: nqr.sqrt(), DomainError)
4484
4484
4485
4485
4486
- def test_fq_default_poly ():
4487
- F = flint .fq_default_ctx (11 , 3 )
4488
- R1 = flint .fq_default_poly_ctx (F )
4489
- R2 = flint .fq_default_poly_ctx (11 , 3 )
4490
- R3 = flint .fq_default_poly_ctx (13 , 5 )
4491
-
4492
- assert raises (lambda : flint .fq_default_poly_ctx ("AAA" ), TypeError )
4493
- assert (R1 == R1 ) is True
4494
- assert hash (R1 ) == hash (R2 )
4495
- assert (R1 != R1 ) is False
4496
- assert (R1 == R2 ) is True
4497
- assert (R1 != R2 ) is False
4498
- assert (R1 != R3 ) is True
4499
- assert (R1 == R3 ) is False
4500
- assert (R1 != "AAA" ) is True
4501
- assert (R1 == "AAA" ) is False
4502
-
4503
- assert str (R1 ) == "Context for fq_default_poly with field: Context for fq_default in GF(11^3)[z]/(z^3 + 2*z + 9)"
4504
- assert str (R1 ) == str (R2 )
4505
- assert repr (R3 ) == "fq_default_poly_ctx(fq_default_ctx(13, 5, 'z', x^5 + 4*x + 11, 'FQ_NMOD'))"
4506
-
4507
- # random element failure
4508
- f = R1 .random_element (not_zero = True )
4509
- assert not f .is_zero ()
4510
- assert raises (lambda : R1 .random_element (monic = "AAA" ), TypeError )
4511
- assert raises (lambda : R1 .random_element (degree = - 1 ), ValueError )
4512
-
4513
- assert raises (lambda : flint .fq_default_poly ([1 ,2 ,3 ], "AAA" ), TypeError )
4514
-
4515
- assert R1 (0 ).leading_coefficient () == 0
4516
- assert raises (lambda : R1 .random_element ().reverse (degree = - 1 ), ValueError )
4517
-
4518
- # some coercion
4519
- assert raises (lambda : R3 (F (1 )), ValueError )
4520
- assert R1 .one () == R1 (1 )
4521
- assert R1 .one () == R1 ([1 ])
4522
- assert R1 .one () == R1 (flint .fmpz (1 ))
4523
- assert R1 .one () == R1 (flint .fmpz_poly ([1 ]))
4524
- assert R1 .one () == R1 (flint .fmpz_mod_ctx (11 )(1 ))
4525
- assert R1 .one () == R1 (flint .fmpz_mod_poly_ctx (11 )(1 ))
4526
- assert R1 .one () == R1 (flint .nmod_poly (1 , 11 ))
4527
-
4528
- R_sml = flint .fq_default_poly_ctx (5 )
4529
- R_med = flint .fq_default_poly_ctx (65537 )
4530
- R_big = flint .fq_default_poly_ctx (2 ** 127 - 1 )
4531
- R_sml_ext = flint .fq_default_poly_ctx (5 , 5 )
4532
- R_med_ext = flint .fq_default_poly_ctx (65537 , 3 )
4533
- R_big_ext = flint .fq_default_poly_ctx (2 ** 127 - 1 , 2 )
4534
-
4535
- F_cmp = flint .fq_default_ctx (11 )
4536
- R_cmp = flint .fq_default_poly_ctx (F_cmp )
4537
- f_cmp = R_cmp ([1 ,2 ,3 ,4 ,5 ])
4538
-
4539
- for R_test in [R_sml , R_med , R_big , R_sml_ext , R_med_ext , R_big_ext ]:
4540
- F_test = R_test .base_field ()
4541
- while True :
4542
- nqr = F_test .random_element ()
4543
- if not nqr .is_square ():
4544
- break
4545
-
4546
- f = R_test ([- 1 ,- 2 ])
4547
- g = R_test ([- 3 ,- 4 ])
4548
- assert (f == f ) is True
4549
- assert (f != g ) is True
4550
- assert (hash (f ) == hash (f )) is True
4551
- assert (hash (f ) != hash (g )) is True
4552
-
4553
- # Exact division
4554
- assert raises (lambda : f .exact_division (f_cmp ), ValueError )
4555
- assert raises (lambda : f .exact_division ("AAA" ), TypeError )
4556
- assert raises (lambda : f .exact_division (0 ), ZeroDivisionError )
4557
- assert (f * g ).exact_division (g ) == f
4558
- assert raises (lambda : f .exact_division (g ), DomainError )
4559
- assert raises (lambda : f / "AAA" , TypeError )
4560
- assert raises (lambda : "AAA" / f , TypeError )
4561
-
4562
- # ZeroDivisionError
4563
- assert raises (lambda : f / 0 , ZeroDivisionError )
4564
- assert raises (lambda : f // 0 , ZeroDivisionError )
4565
- assert raises (lambda : 1 / R_test .zero (), ZeroDivisionError )
4566
- assert raises (lambda : 1 // R_test .zero (), ZeroDivisionError )
4567
- assert raises (lambda : 1 % R_test .zero (), ZeroDivisionError )
4568
-
4569
- # pow
4570
- # assert ui and fmpz exp agree for polynomials and generators
4571
- R_gen = R_test .gen ()
4572
- assert raises (lambda : f ** (- 2 ), ValueError )
4573
- assert pow (f , 2 ** 60 , g ) == pow (pow (f , 2 ** 30 , g ), 2 ** 30 , g )
4574
- assert pow (R_gen , 2 ** 60 , g ) == pow (pow (R_gen , 2 ** 30 , g ), 2 ** 30 , g )
4575
- assert raises (lambda : pow (f , - 2 , g ), ValueError )
4576
- assert raises (lambda : pow (f , 1 , "A" ), TypeError )
4577
- assert raises (lambda : pow (f , "A" , g ), TypeError )
4578
- assert raises (lambda : f .pow_mod (2 ** 32 , g , mod_rev_inv = "A" ), TypeError )
4579
-
4580
- # Shifts
4581
- assert raises (lambda : R_test ([1 ,2 ,3 ]).left_shift (- 1 ), ValueError )
4582
- assert raises (lambda : R_test ([1 ,2 ,3 ]).right_shift (- 1 ), ValueError )
4583
- assert R_test ([1 ,2 ,3 ]).left_shift (3 ) == R_test ([0 ,0 ,0 ,1 ,2 ,3 ])
4584
- assert R_test ([1 ,2 ,3 ]).right_shift (1 ) == R_test ([2 ,3 ])
4585
-
4586
- # mulmod
4587
- assert f .mul_mod (f , g ) == (f * f ) % g
4588
- assert raises (lambda : f .mul_mod (f , "AAA" ), TypeError )
4589
- assert raises (lambda : f .mul_mod ("AAA" , g ), TypeError )
4590
-
4591
- # pow_mod
4592
- assert f .pow_mod (2 , g ) == (f * f ) % g
4593
- assert raises (lambda : f .pow_mod (2 , "AAA" ), TypeError )
4594
-
4595
- # roots
4596
- assert raises (lambda : f .real_roots (), DomainError )
4597
- assert raises (lambda : f .complex_roots (), DomainError )
4598
-
4599
- # compose errors
4600
- assert raises (lambda : f .compose ("A" ), TypeError )
4601
- assert raises (lambda : f .compose_mod ("A" , g ), TypeError )
4602
- assert raises (lambda : f .compose_mod (g , "A" ), TypeError )
4603
- assert raises (lambda : f .compose_mod (g , R_test .zero ()), ZeroDivisionError )
4604
-
4605
- # inverse_mod
4606
- while True :
4607
- # Ensure f is invertible
4608
- f = R_test .random_element ()
4609
- if not f .constant_coefficient ().is_zero ():
4610
- break
4611
- while True :
4612
- h = R_test .random_element ()
4613
- if f .gcd (h ).is_one ():
4614
- break
4615
- g = f .inverse_mod (h )
4616
- assert f .mul_mod (g , h ).is_one ()
4617
- assert raises (lambda : f .inverse_mod (2 * f ), ValueError )
4618
-
4619
- # series
4620
- f_non_square = R_test ([nqr , 1 , 1 , 1 ])
4621
- f_zero = R_test ([0 , 1 , 1 , 1 ])
4622
- assert raises (lambda : f_non_square .sqrt_trunc (1 ), ValueError )
4623
- assert raises (lambda : f_zero .sqrt_trunc (1 ), ZeroDivisionError )
4624
- assert raises (lambda : f_non_square .inv_sqrt_trunc (1 ), ValueError )
4625
- assert raises (lambda : f_zero .inv_sqrt_trunc (1 ), ZeroDivisionError )
4626
- f_inv = f .inverse_series_trunc (2 )
4627
- assert (f * f_inv ) % R_test ([0 ,0 ,1 ]) == 1
4628
- assert raises (lambda : R_test ([0 ,1 ]).inverse_series_trunc (2 ), ZeroDivisionError )
4629
-
4630
- # deflation
4631
- f1 = R_test ([1 ,0 ,2 ,0 ,3 ])
4632
- assert raises (lambda : f1 .deflate (100 ), ValueError )
4633
- assert f1 .deflate (2 ) == R_test ([1 ,2 ,3 ])
4634
-
4635
- # truncate things
4636
- f = R_test .random_element ()
4637
- g = R_test .random_element ()
4638
- h = R_test .random_element ()
4639
- x = R_test .gen ()
4640
- f_trunc = f % x ** 3
4641
-
4642
- assert f .equal_trunc (f_trunc , 3 )
4643
- assert not f .equal_trunc ("A" , 3 )
4644
- assert not f .equal_trunc (f_cmp , 3 )
4645
-
4646
- assert raises (lambda : f .add_trunc ("A" , 1 ), TypeError )
4647
- assert raises (lambda : f .add_trunc (f_cmp , 1 ), ValueError )
4648
- assert f .add_trunc (g , 3 ) == (f + g ) % x ** 3
4649
-
4650
- assert raises (lambda : f .sub_trunc ("A" , 1 ), TypeError )
4651
- assert raises (lambda : f .sub_trunc (f_cmp , 1 ), ValueError )
4652
- assert f .sub_trunc (g , 3 ) == (f - g ) % x ** 3
4653
-
4654
- assert raises (lambda : f .mul_low ("A" , 1 ), TypeError )
4655
- assert raises (lambda : f .mul_low (g , "A" ), TypeError )
4656
- assert raises (lambda : f .mul_low (f_cmp , 1 ), ValueError )
4657
- assert f .mul_low (g , 3 ) == (f * g ) % x ** 3
4486
+ # def test_fq_default_poly():
4487
+ # F = flint.fq_default_ctx(11, 3)
4488
+ # R1 = flint.fq_default_poly_ctx(F)
4489
+ # R2 = flint.fq_default_poly_ctx(11, 3)
4490
+ # R3 = flint.fq_default_poly_ctx(13, 5)
4491
+
4492
+ # assert raises(lambda: flint.fq_default_poly_ctx("AAA"), TypeError)
4493
+ # assert (R1 == R1) is True
4494
+ # assert hash(R1) == hash(R2)
4495
+ # assert (R1 != R1) is False
4496
+ # assert (R1 == R2) is True
4497
+ # assert (R1 != R2) is False
4498
+ # assert (R1 != R3) is True
4499
+ # assert (R1 == R3) is False
4500
+ # assert (R1 != "AAA") is True
4501
+ # assert (R1 == "AAA") is False
4502
+
4503
+ # assert str(R1) == "Context for fq_default_poly with field: Context for fq_default in GF(11^3)[z]/(z^3 + 2*z + 9)"
4504
+ # assert str(R1) == str(R2)
4505
+ # assert repr(R3) == "fq_default_poly_ctx(fq_default_ctx(13, 5, 'z', x^5 + 4*x + 11, 'FQ_NMOD'))"
4506
+
4507
+ # # random element failure
4508
+ # f = R1.random_element(not_zero=True)
4509
+ # assert not f.is_zero()
4510
+ # assert raises(lambda: R1.random_element(monic="AAA"), TypeError)
4511
+ # assert raises(lambda: R1.random_element(degree=-1), ValueError)
4512
+
4513
+ # assert raises(lambda: flint.fq_default_poly([1,2,3], "AAA"), TypeError)
4514
+
4515
+ # assert R1(0).leading_coefficient() == 0
4516
+ # assert raises(lambda: R1.random_element().reverse(degree=-1), ValueError)
4517
+
4518
+ # # some coercion
4519
+ # assert raises(lambda: R3(F(1)), ValueError)
4520
+ # assert R1.one() == R1(1)
4521
+ # assert R1.one() == R1([1])
4522
+ # assert R1.one() == R1(flint.fmpz(1))
4523
+ # assert R1.one() == R1(flint.fmpz_poly([1]))
4524
+ # assert R1.one() == R1(flint.fmpz_mod_ctx(11)(1))
4525
+ # assert R1.one() == R1(flint.fmpz_mod_poly_ctx(11)(1))
4526
+ # assert R1.one() == R1(flint.nmod_poly(1, 11))
4527
+
4528
+ # R_sml = flint.fq_default_poly_ctx(5)
4529
+ # R_med = flint.fq_default_poly_ctx(65537)
4530
+ # R_big = flint.fq_default_poly_ctx(2**127 - 1)
4531
+ # R_sml_ext = flint.fq_default_poly_ctx(5, 5)
4532
+ # R_med_ext = flint.fq_default_poly_ctx(65537, 3)
4533
+ # R_big_ext = flint.fq_default_poly_ctx(2**127 - 1, 2)
4534
+
4535
+ # F_cmp = flint.fq_default_ctx(11)
4536
+ # R_cmp = flint.fq_default_poly_ctx(F_cmp)
4537
+ # f_cmp = R_cmp([1,2,3,4,5])
4538
+
4539
+ # for R_test in [R_sml, R_med, R_big, R_sml_ext, R_med_ext, R_big_ext]:
4540
+ # F_test = R_test.base_field()
4541
+ # while True:
4542
+ # nqr = F_test.random_element()
4543
+ # if not nqr.is_square():
4544
+ # break
4658
4545
4659
- assert raises (lambda : f .pow_trunc (- 1 , 5 ), ValueError )
4546
+ # f = R_test([-1,-2])
4547
+ # g = R_test([-3,-4])
4548
+ # assert (f == f) is True
4549
+ # assert (f != g) is True
4550
+ # assert (hash(f) == hash(f)) is True
4551
+ # assert (hash(f) != hash(g)) is True
4552
+
4553
+ # # Exact division
4554
+ # assert raises(lambda: f.exact_division(f_cmp), ValueError)
4555
+ # assert raises(lambda: f.exact_division("AAA"), TypeError)
4556
+ # assert raises(lambda: f.exact_division(0), ZeroDivisionError)
4557
+ # assert (f * g).exact_division(g) == f
4558
+ # assert raises(lambda: f.exact_division(g), DomainError)
4559
+ # assert raises(lambda: f / "AAA", TypeError)
4560
+ # assert raises(lambda: "AAA" / f, TypeError)
4561
+
4562
+ # # ZeroDivisionError
4563
+ # assert raises(lambda: f / 0, ZeroDivisionError)
4564
+ # assert raises(lambda: f // 0, ZeroDivisionError)
4565
+ # assert raises(lambda: 1 / R_test.zero(), ZeroDivisionError)
4566
+ # assert raises(lambda: 1 // R_test.zero(), ZeroDivisionError)
4567
+ # assert raises(lambda: 1 % R_test.zero(), ZeroDivisionError)
4568
+
4569
+ # # pow
4570
+ # # assert ui and fmpz exp agree for polynomials and generators
4571
+ # R_gen = R_test.gen()
4572
+ # assert raises(lambda: f**(-2), ValueError)
4573
+ # assert pow(f, 2**60, g) == pow(pow(f, 2**30, g), 2**30, g)
4574
+ # assert pow(R_gen, 2**60, g) == pow(pow(R_gen, 2**30, g), 2**30, g)
4575
+ # assert raises(lambda: pow(f, -2, g), ValueError)
4576
+ # assert raises(lambda: pow(f, 1, "A"), TypeError)
4577
+ # assert raises(lambda: pow(f, "A", g), TypeError)
4578
+ # assert raises(lambda: f.pow_mod(2**32, g, mod_rev_inv="A"), TypeError)
4579
+
4580
+ # # Shifts
4581
+ # assert raises(lambda: R_test([1,2,3]).left_shift(-1), ValueError)
4582
+ # assert raises(lambda: R_test([1,2,3]).right_shift(-1), ValueError)
4583
+ # assert R_test([1,2,3]).left_shift(3) == R_test([0,0,0,1,2,3])
4584
+ # assert R_test([1,2,3]).right_shift(1) == R_test([2,3])
4585
+
4586
+ # # mulmod
4587
+ # assert f.mul_mod(f, g) == (f*f) % g
4588
+ # assert raises(lambda: f.mul_mod(f, "AAA"), TypeError)
4589
+ # assert raises(lambda: f.mul_mod("AAA", g), TypeError)
4590
+
4591
+ # # pow_mod
4592
+ # assert f.pow_mod(2, g) == (f*f) % g
4593
+ # assert raises(lambda: f.pow_mod(2, "AAA"), TypeError)
4594
+
4595
+ # # roots
4596
+ # assert raises(lambda: f.real_roots(), DomainError)
4597
+ # assert raises(lambda: f.complex_roots(), DomainError)
4598
+
4599
+ # # compose errors
4600
+ # assert raises(lambda: f.compose("A"), TypeError)
4601
+ # assert raises(lambda: f.compose_mod("A", g), TypeError)
4602
+ # assert raises(lambda: f.compose_mod(g, "A"), TypeError)
4603
+ # assert raises(lambda: f.compose_mod(g, R_test.zero()), ZeroDivisionError)
4604
+
4605
+ # # inverse_mod
4606
+ # while True:
4607
+ # # Ensure f is invertible
4608
+ # f = R_test.random_element()
4609
+ # if not f.constant_coefficient().is_zero():
4610
+ # break
4611
+ # while True:
4612
+ # h = R_test.random_element()
4613
+ # if f.gcd(h).is_one():
4614
+ # break
4615
+ # g = f.inverse_mod(h)
4616
+ # assert f.mul_mod(g, h).is_one()
4617
+ # assert raises(lambda: f.inverse_mod(2*f), ValueError)
4618
+
4619
+ # # series
4620
+ # f_non_square = R_test([nqr, 1, 1, 1])
4621
+ # f_zero = R_test([0, 1, 1, 1])
4622
+ # assert raises(lambda: f_non_square.sqrt_trunc(1), ValueError)
4623
+ # assert raises(lambda: f_zero.sqrt_trunc(1), ZeroDivisionError)
4624
+ # assert raises(lambda: f_non_square.inv_sqrt_trunc(1), ValueError)
4625
+ # assert raises(lambda: f_zero.inv_sqrt_trunc(1), ZeroDivisionError)
4626
+ # f_inv = f.inverse_series_trunc(2)
4627
+ # assert (f * f_inv) % R_test([0,0,1]) == 1
4628
+ # assert raises(lambda: R_test([0,1]).inverse_series_trunc(2), ZeroDivisionError)
4629
+
4630
+ # # deflation
4631
+ # f1 = R_test([1,0,2,0,3])
4632
+ # assert raises(lambda: f1.deflate(100), ValueError)
4633
+ # assert f1.deflate(2) == R_test([1,2,3])
4634
+
4635
+ # # truncate things
4636
+ # f = R_test.random_element()
4637
+ # g = R_test.random_element()
4638
+ # h = R_test.random_element()
4639
+ # x = R_test.gen()
4640
+ # f_trunc = f % x**3
4641
+
4642
+ # assert f.equal_trunc(f_trunc, 3)
4643
+ # assert not f.equal_trunc("A", 3)
4644
+ # assert not f.equal_trunc(f_cmp, 3)
4645
+
4646
+ # assert raises(lambda: f.add_trunc("A", 1), TypeError)
4647
+ # assert raises(lambda: f.add_trunc(f_cmp, 1), ValueError)
4648
+ # assert f.add_trunc(g, 3) == (f + g) % x**3
4649
+
4650
+ # assert raises(lambda: f.sub_trunc("A", 1), TypeError)
4651
+ # assert raises(lambda: f.sub_trunc(f_cmp, 1), ValueError)
4652
+ # assert f.sub_trunc(g, 3) == (f - g) % x**3
4653
+
4654
+ # assert raises(lambda: f.mul_low("A", 1), TypeError)
4655
+ # assert raises(lambda: f.mul_low(g, "A"), TypeError)
4656
+ # assert raises(lambda: f.mul_low(f_cmp, 1), ValueError)
4657
+ # assert f.mul_low(g, 3) == (f * g) % x**3
4658
+
4659
+ # assert raises(lambda: f.pow_trunc(-1, 5), ValueError)
4660
4660
4661
4661
4662
4662
def test_all_tests ():
@@ -4729,7 +4729,7 @@ def test_all_tests():
4729
4729
test_matrices_fflu ,
4730
4730
4731
4731
# test_fq_default,
4732
- test_fq_default_poly ,
4732
+ # test_fq_default_poly,
4733
4733
4734
4734
test_arb ,
4735
4735
0 commit comments