File: test_MI_mul.cc

package info (click to toggle)
cln 1.3.7-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,996 kB
  • sloc: cpp: 80,860; sh: 5,138; ansic: 3,174; makefile: 1,274
file content (54 lines) | stat: -rw-r--r-- 1,559 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "test_MI.h"

int test_MI_mul (int iterations)
{
	int error = 0;
	int i;
	// Check commutativity.
	for (i = iterations; i > 0; i--) {
		cl_I m = testrandom_I();
		cl_modint_ring R = find_modint_ring(m);
		cl_MI a = R->canonhom(testrandom_I());
		cl_MI b = R->canonhom(testrandom_I());
		ASSERT3(a*b == b*a, m,a,b);
	}
	// Check associativity.
	for (i = iterations; i > 0; i--) {
		cl_I m = testrandom_I();
		cl_modint_ring R = find_modint_ring(m);
		cl_MI a = R->canonhom(testrandom_I());
		cl_MI b = R->canonhom(testrandom_I());
		cl_MI c = R->canonhom(testrandom_I());
		ASSERT4((a*b)*c == a*(b*c), m,a,b,c);
	}
	// Check second binomial formula.
	for (i = iterations; i > 0; i--) {
		cl_I m = testrandom_I();
		cl_modint_ring R = find_modint_ring(m);
		cl_MI a = R->canonhom(testrandom_I());
		cl_MI b = R->canonhom(testrandom_I());
		ASSERT3((a+b)*(a-b) == a*a-b*b, m,a,b);
	}
	// Check distributive formula.
	for (i = iterations; i > 0; i--) {
		cl_I m = testrandom_I();
		cl_modint_ring R = find_modint_ring(m);
		cl_MI a = R->canonhom(testrandom_I());
		cl_MI b = R->canonhom(testrandom_I());
		cl_MI c = R->canonhom(testrandom_I());
		ASSERT4((a+c)*(b+c) == a*b+(a+b)*c+c*c, m,a,b,c);
	}
	// Check special cases 0, 1, -1.
	for (i = iterations; i > 0; i--) {
		cl_I m = testrandom_I();
		cl_modint_ring R = find_modint_ring(m);
		cl_MI a = R->canonhom(testrandom_I());
		cl_MI z = R->zero();
		cl_MI o = R->one();
		cl_MI mo = R->canonhom(-1);
		ASSERT2(a*z == z, m,a);
		ASSERT2(a*o == a, m,a);
		ASSERT2(a*mo == -a, m,a);
	}
	return error;
}