]> www.ginac.de Git - cln.git/blob - tests/test_MI_mul.cc
Fix double_approx(const cl_RA& x) on 64-Bit platforms.
[cln.git] / tests / test_MI_mul.cc
1 #include "test_MI.h"
2
3 int test_MI_mul (int iterations)
4 {
5         int error = 0;
6         int i;
7         // Check commutativity.
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                 cl_MI b = R->canonhom(testrandom_I());
13                 ASSERT3(a*b == b*a, m,a,b);
14         }
15         // Check associativity.
16         for (i = iterations; i > 0; i--) {
17                 cl_I m = testrandom_I();
18                 cl_modint_ring R = 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);
23         }
24         // Check second binomial formula.
25         for (i = iterations; i > 0; i--) {
26                 cl_I m = testrandom_I();
27                 cl_modint_ring R = 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);
31         }
32         // Check distributive formula.
33         for (i = iterations; i > 0; i--) {
34                 cl_I m = testrandom_I();
35                 cl_modint_ring R = 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);
40         }
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 = find_modint_ring(m);
45                 cl_MI a = R->canonhom(testrandom_I());
46                 cl_MI z = R->zero();
47                 cl_MI o = R->one();
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);
52         }
53         return error;
54 }