3 int test_MI_mul (int iterations)
7 // Check commutativity.
8 for (i = iterations; i > 0; i--) {
9 cl_I m = testrandom_I();
10 cl_modint_ring R = cl_find_modint_ring(m);
11 cl_MI a = R->canonhom(testrandom_I());
12 cl_MI b = R->canonhom(testrandom_I());
13 ASSERT3(a*b == b*a, m,a,b);
15 // Check associativity.
16 for (i = iterations; i > 0; i--) {
17 cl_I m = testrandom_I();
18 cl_modint_ring R = cl_find_modint_ring(m);
19 cl_MI a = R->canonhom(testrandom_I());
20 cl_MI b = R->canonhom(testrandom_I());
21 cl_MI c = R->canonhom(testrandom_I());
22 ASSERT4((a*b)*c == a*(b*c), m,a,b,c);
24 // Check second binomial formula.
25 for (i = iterations; i > 0; i--) {
26 cl_I m = testrandom_I();
27 cl_modint_ring R = cl_find_modint_ring(m);
28 cl_MI a = R->canonhom(testrandom_I());
29 cl_MI b = R->canonhom(testrandom_I());
30 ASSERT3((a+b)*(a-b) == a*a-b*b, m,a,b);
32 // Check distributive formula.
33 for (i = iterations; i > 0; i--) {
34 cl_I m = testrandom_I();
35 cl_modint_ring R = cl_find_modint_ring(m);
36 cl_MI a = R->canonhom(testrandom_I());
37 cl_MI b = R->canonhom(testrandom_I());
38 cl_MI c = R->canonhom(testrandom_I());
39 ASSERT4((a+c)*(b+c) == a*b+(a+b)*c+c*c, m,a,b,c);
41 // Check special cases 0, 1, -1.
42 for (i = iterations; i > 0; i--) {
43 cl_I m = testrandom_I();
44 cl_modint_ring R = cl_find_modint_ring(m);
45 cl_MI a = R->canonhom(testrandom_I());
48 cl_MI mo = R->canonhom(-1);
49 ASSERT2(a*z == z, m,a);
50 ASSERT2(a*o == a, m,a);
51 ASSERT2(a*mo == -a, m,a);