3 int test_MI_expt (int iterations)
7 // Check special caSes 0, 1, 2.
8 for (i = iterations; i > 0; i--) {
9 cl_I m = testrandom_I();
10 cl_modint_ring R = find_modint_ring(m);
11 cl_MI a = R->canonhom(testrandom_I());
12 ASSERT2(expt(a,0) == R->one(), m,a);
13 ASSERT2(expt(a,1) == a, m,a);
14 ASSERT2(expt(a,2) == a*a, m,a);
16 // Check special cases -1, -2.
17 for (i = iterations; i > 0; i--) {
18 cl_I m = testrandom_I();
19 cl_modint_ring R = find_modint_ring(m);
20 cl_I ai = testrandom_I();
22 cl_MI a = R->canonhom(ai);
23 cl_MI ar = R->recip(a);
24 ASSERT2(expt(a,-1) == ar, m,a);
25 ASSERT2(expt(a,-2) == ar*ar, m,a);
28 // Check homomorphism (fixed exponent).
29 for (i = iterations; i > 0; i--) {
30 cl_I m = testrandom_I();
31 if (!zerop(m)) { // avoid generating huge numbers
32 cl_modint_ring R = find_modint_ring(m);
33 cl_MI a = R->canonhom(testrandom_I());
34 cl_MI b = R->canonhom(testrandom_I());
35 cl_I e = abs(testrandom_I());
36 ASSERT4(expt(a,e)*expt(b,e) == expt(a*b,e), m,a,b,e);
39 // Check distributive formulas (fixed base).
40 for (i = iterations; i > 0; i--) {
41 cl_I m = testrandom_I();
42 if (!zerop(m)) { // avoid generating huge numbers
43 cl_modint_ring R = find_modint_ring(m);
44 cl_MI a = R->canonhom(testrandom_I());
45 cl_I e = abs(testrandom_I());
46 cl_I f = abs(testrandom_I());
47 ASSERT4(expt(a,e)*expt(a,f) == expt(a,e+f), m,a,e,f);
48 ASSERT4(expt(expt(a,e),f) == expt(a,e*f), m,a,e,f);