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

563665 views
1
#include"typedef.h"
2
#include"matrix.h"
3
#include"longtools.h"
4
5
/**************************************************************************\
6
@---------------------------------------------------------------------------
7
@---------------------------------------------------------------------------
8
@ FILE: formspace.c
9
@---------------------------------------------------------------------------
10
@---------------------------------------------------------------------------
11
@
12
\**************************************************************************/
13
14
/**************************************************************************\
15
@---------------------------------------------------------------------------
16
@ matrix_TYP **formspace(B, Banz, sym_opt, fdim)
17
@ matrix_TYP **B;
18
@ int Banz, sym_opt, *fdim;
19
@
20
@ formspace calculates a basis of the lattice of integral matrices X with
21
@ B[i]^{tr} * X * B[i] = X for 0 <= i < Banz
22
@ The number of basis elements is returned via (int *fdim).
23
@ 'sym_opt' must be 0, 1 or -1.
24
@ sym_opt = 0: the full lattice is calculated.
25
@ sym_opt = 1: a basis for the symmetric matrices is calculated
26
@ sym_opt =-1: a basis for the skewsymmetric matrices is calculated
27
@
28
@---------------------------------------------------------------------------
29
@
30
\**************************************************************************/
31
32
matrix_TYP **formspace(B, Banz, sym_opt, fdim)
33
matrix_TYP **B;
34
int Banz, sym_opt, *fdim;
35
{
36
int i,j,k,l,m, no;
37
int dim, dd, anz;
38
matrix_TYP *X, *Xk, **E;
39
int **XX, **Bi;
40
int **pos, **sign;
41
42
43
dim = B[0]->cols;
44
if(B[0]->rows != dim)
45
{
46
printf("error in formspace: non-square matrix in group 'B'\n");
47
exit(3);
48
}
49
for(i=1;i<Banz;i++)
50
{
51
if(B[i]->rows != dim || B[i]->cols != dim)
52
{
53
printf("error in formspace: different dimesion of group elements\n");
54
exit(3);
55
}
56
}
57
if(sym_opt == 1)
58
dd = (dim *(dim+1))/2;
59
if(sym_opt == -1)
60
dd = (dim *(dim-1))/2;
61
if(sym_opt == 0)
62
dd = dim * dim;
63
if( (pos = (int **)malloc(dim *sizeof(int *))) == NULL)
64
{
65
printf("malloc of 'pos' in 'formspace' failed\n");
66
exit(2);
67
}
68
for(i=0;i<dim;i++)
69
{
70
if( (pos[i] = (int *)malloc(dim *sizeof(int))) == NULL)
71
{
72
printf("malloc of 'pos[%d]' in 'formspace' failed\n", i);
73
exit(2);
74
}
75
}
76
if( (sign = (int **)malloc(dim *sizeof(int *))) == NULL)
77
{
78
printf("malloc of 'sign' in 'formspace' failed\n");
79
exit(2);
80
}
81
for(i=0;i<dim;i++)
82
{
83
if( (sign[i] = (int *)malloc(dim *sizeof(int))) == NULL)
84
{
85
printf("malloc of 'sign[%d]' in 'formspace' failed\n", i);
86
exit(2);
87
}
88
}
89
if(sym_opt == 0)
90
{
91
no = 0;
92
for(i=0;i<dim;i++)
93
for(j=0;j<dim;j++)
94
{ pos[i][j] = no; sign[i][j] = 1; no++;}
95
}
96
if(sym_opt == 1)
97
{
98
no = 0;
99
for(i=0;i<dim;i++)
100
for(j=0;j<=i;j++)
101
{ pos[i][j] = no; sign[i][j] = 1; no++;}
102
no = 0;
103
for(i=0;i<dim;i++)
104
for(j=0;j<=i;j++)
105
{ pos[j][i] = no; sign[j][i] = 1; no++;}
106
}
107
if(sym_opt == -1)
108
{
109
no = 0;
110
for(i=0;i<dim;i++)
111
for(j=0;j<i;j++)
112
{ pos[i][j] = no; sign[i][j] = 1; no++;}
113
no = 0;
114
for(i=0;i<dim;i++)
115
for(j=0;j<i;j++)
116
{ pos[j][i] = no; sign[j][i] = -1; no++;}
117
for(i=0;i<dim;i++)
118
{ pos[i][i] = 0; sign[i][i] = 0;}
119
}
120
121
X = init_mat(dd * Banz, dd, "");
122
XX = X->array.SZ;
123
no = 0;
124
if(sym_opt == 0)
125
{
126
no = 0;
127
for(i=0;i<Banz;i++)
128
{
129
Bi = B[i]->array.SZ;
130
for(j=0;j<dim;j++)
131
for(k=0;k<dim;k++)
132
{
133
for(l=0;l<dim;l++)
134
for(m=0;m<dim;m++)
135
XX[no][pos[l][m]] += sign[l][m] * Bi[l][j] * Bi[m][k];
136
XX[no][pos[j][k]]--;
137
no++;
138
}
139
}
140
}
141
if(sym_opt == 1)
142
{
143
no = 0;
144
for(i=0;i<Banz;i++)
145
{
146
Bi = B[i]->array.SZ;
147
for(j=0;j<dim;j++)
148
for(k=0;k<=j;k++)
149
{
150
for(l=0;l<dim;l++)
151
for(m=0;m<dim;m++)
152
XX[no][pos[l][m]] += sign[l][m] * Bi[l][j] * Bi[m][k];
153
XX[no][pos[j][k]]--;
154
no++;
155
}
156
}
157
}
158
if(sym_opt == -1)
159
{
160
no = 0;
161
for(i=0;i<Banz;i++)
162
{
163
Bi = B[i]->array.SZ;
164
for(j=0;j<dim;j++)
165
for(k=0;k<j;k++)
166
{
167
for(l=0;l<dim;l++)
168
for(m=0;m<dim;m++)
169
XX[no][pos[l][m]] += sign[l][m] * Bi[l][j] * Bi[m][k];
170
XX[no][pos[j][k]]--;
171
no++;
172
}
173
}
174
}
175
Xk = long_kernel_mat(X);
176
free_mat(X);
177
if(Xk == NULL)
178
anz = 0;
179
else
180
anz = Xk->cols;
181
if(anz != 0)
182
{
183
if( (E = (matrix_TYP **)malloc(anz *sizeof(matrix_TYP *))) == NULL)
184
{
185
printf("malloc of 'E' in 'formspace' failed\n");
186
exit(2);
187
}
188
}
189
else
190
E = NULL;
191
for(i=0;i<anz;i++)
192
{
193
E[i] = init_mat(dim, dim, "");
194
if(sym_opt == 0)
195
{
196
for(j=0;j<dim;j++)
197
for(k=0;k<dim;k++)
198
E[i]->array.SZ[j][k] = Xk->array.SZ[pos[j][k]][i];
199
}
200
if(sym_opt == 1)
201
{
202
for(j=0;j<dim;j++)
203
for(k=0;k<=j;k++)
204
{
205
E[i]->array.SZ[j][k] = Xk->array.SZ[pos[j][k]][i];
206
if(j != k)
207
E[i]->array.SZ[k][j] = E[i]->array.SZ[j][k];
208
}
209
}
210
if(sym_opt == -1)
211
{
212
for(j=0;j<dim;j++)
213
for(k=0;k<j;k++)
214
{
215
E[i]->array.SZ[j][k] = Xk->array.SZ[pos[j][k]][i];
216
E[i]->array.SZ[k][j] = -E[i]->array.SZ[j][k];
217
}
218
for(j=0;j<dim;j++)
219
E[i]->array.SZ[j][j] = 0;
220
}
221
}
222
for(i=0;i<anz;i++)
223
Check_mat(E[i]);
224
if(anz != 0)
225
free_mat(Xk);
226
for(i=0;i<dim;i++)
227
{ free(pos[i]); free(sign[i]);}
228
free(pos); free(sign);
229
*fdim = anz;
230
for(i=0;i<anz;i++)
231
{
232
for(j=0;j<dim && E[i]->array.SZ[j][j] == 0; j++);
233
if(j<dim && E[i]->array.SZ[j][j] < 0)
234
{
235
for(k=0;k<dim;k++)
236
for(l=0;l<dim;l++)
237
E[i]->array.SZ[k][l] = -E[i]->array.SZ[k][l];
238
}
239
}
240
return(E);
241
}
242
243