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

563603 views
1
#include "typedef.h"
2
#include "matrix.h"
3
#include "gmp.h"
4
#include "zass.h"
5
#include "getput.h"
6
7
8
extern int INFO_LEVEL;
9
10
11
static int and(int *a,int n)
12
{
13
int i;
14
15
for (i=0;i<n;i++) if (a[i] == FALSE) return FALSE;
16
17
return TRUE;
18
}
19
20
21
static int cmp_red(matrix_TYP *x,matrix_TYP *y)
22
{
23
int i,
24
j,
25
rows,
26
cols;
27
28
if (x->cols < y->cols)
29
cols = x->cols;
30
else
31
cols = y->cols;
32
33
if (x->rows < y->rows)
34
rows = x->rows;
35
else
36
rows = y->rows;
37
38
for (i=0;i<cols;i++)
39
for (j=0;j<rows;j++){
40
if (x->array.SZ[i][j] < y->array.SZ[i][j]) return -1;
41
if (x->array.SZ[i][j] > y->array.SZ[i][j]) return 1;
42
}
43
44
return 0;
45
}
46
47
48
static int red_pos(matrix_TYP *x,
49
matrix_TYP **A,
50
struct tree *knoten,
51
int n,
52
int flag)
53
{
54
int erg;
55
56
erg = cmp_red(x,A[knoten->no]);
57
58
if (erg == 1){
59
if (knoten->right == NULL){
60
if (flag == 1){
61
knoten->right = (struct tree *) calloc(1,sizeof(struct tree));
62
knoten->right->no = n;
63
return(n);
64
}
65
if (flag == 0){
66
knoten->right = (struct tree *) calloc(1,sizeof(struct tree));
67
knoten->right->no = n;
68
return(-1);
69
}
70
if (flag == (-1)){
71
return(-1);
72
}
73
}
74
else{
75
return(red_pos(x,A,knoten->right,n,flag));
76
}
77
}
78
if (erg == (-1)){
79
if (knoten->left == NULL){
80
if (flag == 1){
81
knoten->left = (struct tree *) calloc(1,sizeof(struct tree));
82
knoten->left->no = n;
83
return(n);
84
}
85
if (flag == 0){
86
knoten->left = (struct tree *) calloc(1,sizeof(struct tree));
87
knoten->left->no = n;
88
return(-1);
89
}
90
if (flag == (-1)){
91
return(-1);
92
}
93
}
94
else{
95
return(red_pos(x,A,knoten->left,n,flag));
96
}
97
}
98
if (erg == 0){
99
return(knoten->no);
100
}
101
}
102
103
/**********************************************************************
104
@
105
@----------------------------------------------------------------------
106
@
107
@ matrix_TYP *reget_gen(matrix_TYP **map,int number,bravais_TYP *G,
108
@ int **words,int word_flag)
109
@
110
@----------------------------------------------------------------------
111
@
112
***********************************************************************/
113
matrix_TYP *reget_gen(matrix_TYP **map,int number,bravais_TYP *G,
114
int **words,int word_flag)
115
{
116
int *found, /* gives a flag for each generator of G, TRUE iff
117
we already found this element */
118
length = number, /* the number of elements found so far */
119
speicher = MIN_SPEICHER,
120
k,
121
i,
122
j;
123
124
int **ele_words; /* for each matrix in ele we store a word in the
125
generators here which gives this element:
126
a general convention for the use of words:
127
word[0] stores the length of the word */
128
129
matrix_TYP *erg,
130
**ele,
131
*tmp;
132
133
struct tree *baum,
134
*baum2;
135
136
137
baum = (struct tree *) calloc(1,sizeof(struct tree));
138
baum2 = (struct tree *) calloc(1,sizeof(struct tree));
139
140
erg = init_mat(G->gen_no * G->dim,1,"");
141
142
/* changed tilman 15/07/99 from
143
for (i=0;i<G->gen_no;i++) to: */
144
for (i=0;i<number;i++)
145
Check_mat(map[i]);
146
147
/* there are to cases: the function is called the first time
148
for this generating set, then we have to calculate orbits and so on,
149
otherwise we already got the desired words in words */
150
if (word_flag == TRUE){
151
found = (int *) calloc(G->gen_no+1 , sizeof(int));
152
found++;
153
ele = (matrix_TYP **) malloc(MIN_SPEICHER * sizeof(matrix_TYP *));
154
ele_words = (int **) malloc(MIN_SPEICHER * sizeof(int*));
155
156
for (i=0;i<G->gen_no;i++){
157
red_pos(G->gen[i],G->gen,baum,i,1);
158
}
159
for (i=0;i<G->gen_no;i++)
160
Check_mat(G->gen[i]);
161
162
/* changed tilman 15/07/99 from
163
for (i=0;i<G->gen_no;i++){ to */
164
for (i=0;i<number;i++){
165
ele[i] = map[i];
166
k = red_pos(ele[i],G->gen,baum,i,-1);
167
found[k] = TRUE;
168
ele[i]->cols--; ele[i]->rows--;
169
red_pos(ele[i],ele,baum2,i,1);
170
ele[i]->cols++; ele[i]->rows++;
171
ele_words[i] = (int *) malloc(2 * sizeof(int));
172
ele_words[i][0] = 1;
173
ele_words[i][1] = i;
174
}
175
176
177
for (i=0;i<length && !and(found,G->gen_no);i++){
178
for (j=0;j<number;j++){
179
tmp = mat_mul(ele[i],map[j]);
180
tmp->cols--;tmp->rows--; /* for red_pos */
181
if (red_pos(tmp,ele,baum2,length,0) == (-1)){
182
tmp->cols++;tmp->rows++;
183
184
if (length >= speicher){
185
speicher = speicher + MIN_SPEICHER;
186
ele = (matrix_TYP **) realloc(ele,
187
speicher*sizeof(matrix_TYP *));
188
ele_words = (int **) realloc(ele_words,
189
speicher*sizeof(int *));
190
}
191
192
/* we found an new element of the orbit,
193
set the matrix and the word */
194
ele[length] = tmp;
195
ele_words[length] = (int *) malloc((ele_words[i][0]+2)
196
* sizeof(int*));
197
memcpy(ele_words[length],ele_words[i],
198
(ele_words[i][0]+1) * sizeof(int));
199
ele_words[length][0] = ele_words[i][0]+1;
200
ele_words[length][ele_words[length][0]] = j;
201
length++;
202
203
/* it might be one of the generators we are looking for */
204
found[red_pos(tmp,G->gen,baum,G->gen_no,-1)] = TRUE;
205
}
206
else{
207
tmp->cols++;tmp->rows++;
208
free_mat(tmp);
209
}
210
}
211
}
212
213
if (!and(found,G->gen_no)){
214
fprintf(stderr,"reget_gen: shouldn't happen\n");
215
exit(3);
216
}
217
218
/* now calculate the resulting cozycle alltogether */
219
for (i=0;i<G->gen_no;i++){
220
k = red_pos(G->gen[i],ele,baum2,length,-1);
221
tmp = ele[k];
222
words[i] = ele_words[k];
223
ele_words[k] = NULL;
224
if (INFO_LEVEL & 16){
225
printf("length %d \n",length);
226
printf("red_pos %d \n",k);
227
Check_mat(tmp);
228
put_mat(tmp,NULL,"tmp",2);
229
put_mat(G->gen[i],NULL,"G->gen[i]",2);
230
printf("word[%d]\n c ",i);
231
for (j=1;j<=words[i][0];j++)
232
printf("%d ",words[i][j]+1);
233
printf("\n");
234
}
235
for (j=0;j<G->dim;j++){
236
erg->array.SZ[i*G->dim +j][0] = tmp->array.SZ[j][G->dim];
237
}
238
}
239
240
/* cleaning up memory */
241
found--;
242
free(found);
243
/* changed on 16/07/99 from:
244
for (i=G->gen_no;i<length;i++) free_mat(ele[i]); to */
245
for (i=number;i<length;i++) free_mat(ele[i]);
246
free(ele);
247
for (i=0;i<length;i++) if (ele_words[i] != NULL) free(ele_words[i]);
248
free(ele_words);
249
}
250
else{
251
/* we are in the briliant position to know how the element looks
252
like */
253
for (i=0;i<G->gen_no;i++){
254
tmp = copy_mat(map[words[i][1]]);
255
for (j=2;j<=words[i][0];j++)
256
mat_muleq(tmp,map[words[i][j]]);
257
258
/* calculate the part of the cozycle belonging to the i-th
259
generator */
260
for (j=0;j<G->dim;j++)
261
erg->array.SZ[i*G->dim +j][0] = tmp->array.SZ[j][G->dim];
262
263
if (INFO_LEVEL & 16){
264
printf("reget of %d-th generator\n",i+1);
265
put_mat(tmp,NULL,NULL,2);
266
}
267
268
/* clean up tmp */
269
free_mat(tmp);
270
}
271
}
272
free_tree(baum);
273
free_tree(baum2);
274
275
return erg;
276
} /* reget_gen(....) */
277
278
279
280