Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

563667 views
1
#include "typedef.h"
2
#include "tools.h"
3
#include "matrix.h"
4
#include "voronoi.h"
5
#include "ZZ_P.h"
6
#include "ZZ_gen_vs_P.h"
7
8
/*
9
* Determine the image of the generators in Mn(GF(p),n).
10
*/
11
12
matrix_TYP **ZZ_mod_gen (matrix_TYP **gen, int num)
13
{
14
int i, j, k, dim;
15
matrix_TYP **p_gen;
16
17
dim = gen[0]->rows;
18
p_gen = (matrix_TYP **) malloc (num * sizeof (matrix_TYP *));
19
for (k = 0; k < num; k++) {
20
p_gen[k] = init_mat (dim, dim, "p");
21
for (i = 0; i < dim; i++) {
22
for (j = 0; j < dim; j++) {
23
p_gen[k]->array.SZ[i][j] =
24
gen[k]->array.SZ[i][j] % act_prime;
25
if (p_gen[k]->array.SZ[i][j] < 0) {
26
p_gen[k]->array.SZ[i][j] += act_prime;
27
}
28
}
29
}
30
}
31
return (p_gen);
32
}
33
34
35
/*
36
* Determine the rank and a basis for the image of a vector
37
* under the operation of an order (given by its Z-basis).\
38
*/
39
40
matrix_TYP *ZZ_vec_bahn (int *vec, matrix_TYP **gen, int num)
41
{
42
matrix_TYP *basis;
43
int **B, **T, *v, new_flag;
44
int i, j, k, dim, act, new, rank, flag;
45
46
dim = gen[0]->rows;
47
48
basis = init_mat ((num + 1) * dim, dim, "p");
49
basis->prime = gen[0]->prime;
50
B = basis->array.SZ;
51
memcpy (B[0], vec, dim * sizeof (int));
52
rank = 1;
53
new = 1;
54
flag = 1;
55
while (flag) {
56
for (act = 0; act < rank; act++) {
57
v = B[act];
58
for (i = 0; i < num; i++) {
59
if (save_null_mat (gen[i]))
60
continue;
61
T = gen[i]->array.SZ;
62
new_flag = 0;
63
for (j = 0; j < dim; j++) {
64
B[new][j] = P (v[0], T[0][j]);
65
for (k = 1; k < dim; k++) {
66
B[new][j] = S(B[new][j], P(v[k], T[k][j]));
67
}
68
if (B[new][j])
69
new_flag++;
70
}
71
if (new_flag)
72
new++;
73
}
74
}
75
basis->rows = new;
76
i = p_gauss (basis);
77
flag = ((i == rank) || (i == dim)) ? 0 : 1;
78
rank = i;
79
new = i;
80
}
81
for (i = rank; i < (num + 1) * dim; i++) {
82
free (basis->array.SZ[i]);
83
}
84
basis->array.SZ = (int **) realloc (basis->array.SZ, rank * sizeof (int *));
85
basis->rows = rank;
86
87
Check_mat (basis);
88
return (basis);
89
}
90
91
92
/*
93
* Generate the vector space of given dimension over the
94
* prim field GF(p) up to a skalar factor (the leading
95
* coordinate unequal to zero is one).
96
*/
97
98
matrix_TYP *ZZ_gen_vs (int prim, int dim)
99
{
100
int act, i, j, n;
101
matrix_TYP *VS;
102
int **M;
103
104
105
/* calculate number of vectors */
106
n = 1;
107
j = prim;
108
for (i = 1; i < dim; i++) {
109
n += j;
110
j *= prim;
111
}
112
113
/* alloc space and generated vector space */
114
115
VS = init_mat (n, dim, "");
116
M = VS->array.SZ;
117
i = 1;
118
act = dim - 1;
119
M[0][act] = 1;
120
while (i < n) {
121
j = dim - 1;
122
while ((j > 0) && ((M[i][j] = (M[i - 1][j] + 1) % prim) == 0))
123
j--;
124
if (j <= act) {
125
M[i][act--] = 0;
126
M[i][act] = 1;
127
} else {
128
while (--j >= act)
129
M[i][j] = M[i - 1][j];
130
}
131
i++;
132
}
133
return (VS);
134
}
135
136