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
/***** This file contains routines to calculate
3
and compare Bacher-polynomials *****/
4
5
6
/******************************************************************\
7
| the Bacher-polynomial for v[I] with scalar product S
8
| is defined as follows: let list be the vectors which
9
| have the same length as v[I] and with scalar product S
10
| with v[I], for each vector w in list let n_w be the
11
| number of pairs (y,z) of vectors in list, such that all
12
| scalar products between w,y and z are S,
13
| then the Bacher-polynomial is the sum over the w in list
14
| of the monomials X^n_w
15
\******************************************************************/
16
static void bacher(pol, I, S, V, Fv)
17
bachpol *pol;
18
veclist V;
19
int I, S, **Fv;
20
{
21
int *list, nlist, *listxy, nxy, *counts;
22
int i, j, k, s, dim, sign1, sign2, *vI;
23
24
/* the Bacher-polynomials of v[I] and -v[I] are equal */
25
I = abs(I);
26
dim = V.dim;
27
vI = V.v[I];
28
/* list of vectors that have scalar product S with v[I] */
29
if ((list = (int*)malloc(2*V.n * sizeof(int))) == 0)
30
exit (2);
31
for (i = 0; i < 2*V.n; ++i)
32
list[i] = 0;
33
nlist = 0;
34
for (i = 1; i <= V.n; ++i)
35
{
36
if (V.v[i][dim] == vI[dim])
37
{
38
s = sscp(vI, Fv[i], dim);
39
if (s == S)
40
{
41
list[nlist] = i;
42
++nlist;
43
}
44
if (-s == S)
45
{
46
list[nlist] = -i;
47
++nlist;
48
}
49
}
50
}
51
/* there are nlist vectors that have scalar product S with v[I] */
52
pol->sum = nlist;
53
if ((counts = (int*)malloc(nlist * sizeof(int))) == 0)
54
exit (2);
55
if ((listxy = (int*)malloc(nlist * sizeof(int))) == 0)
56
exit (2);
57
for (i = 0; i < nlist; ++i)
58
{
59
/* listxy is the list of the nxy vectors from list that have scalar product S
60
with v[list[i]] */
61
for (j = 0; j < nlist; ++j)
62
listxy[j] = 0;
63
nxy = 0;
64
sign1 = list[i] > 0 ? 1 : -1;
65
for (j = 0; j < nlist; ++j)
66
{
67
sign2 = list[j] > 0 ? 1 : -1;
68
/* note: for i > 0 is v[-i] = -v[i] */
69
if (sign1*sign2 * sscp(V.v[sign1*list[i]], Fv[sign2*list[j]], dim) == S)
70
{
71
listxy[nxy] = list[j];
72
nxy += 1;
73
}
74
}
75
/* counts[i] is the number of pairs for the vector v[list[i]] */
76
counts[i] = 0;
77
for (j = 0; j < nxy; ++j)
78
{
79
sign1 = listxy[j] > 0 ? 1 : -1;
80
for (k = j+1; k < nxy; ++k)
81
{
82
sign2 = listxy[k] > 0 ? 1 : -1;
83
if (sign1*sign2 * sscp(V.v[sign1*listxy[j]], Fv[sign2*listxy[k]], dim) == S)
84
counts[i] += 1;
85
}
86
}
87
}
88
/* pol->maxd is the maximal degree of the Bacher-polynomial,
89
pol->mind the minimal degree */
90
pol->maxd = counts[0];
91
pol->mind = counts[0];
92
for (i = 1; i < nlist; ++i)
93
{
94
if (counts[i] > pol->maxd)
95
pol->maxd = counts[i];
96
else if (counts[i] < pol->mind)
97
pol->mind = counts[i];
98
}
99
if ((pol->coef = (int*)malloc((pol->maxd - pol->mind + 1) * sizeof(int))) == 0)
100
exit (2);
101
for (i = 0; i <= pol->maxd - pol->mind; ++i)
102
pol->coef[i] = 0;
103
for (i = 0; i < nlist; ++i)
104
pol->coef[counts[i] - pol->mind] += 1;
105
/* the Bacher-polynomial is now: sum from i=pol->mind to pol->maxd over
106
pol->coef[i - pol->mind] * X^i */
107
free(listxy);
108
free(counts);
109
free(list);
110
}
111
112
/******************************************************************\
113
| checks, whether the vector v[I] has the Bacher-polynomial pol
114
\******************************************************************/
115
static int bachcomp(pol, I, S, V, Fv)
116
bachpol pol;
117
veclist V;
118
int I, S, **Fv;
119
{
120
int *co, *list, nlist, *listxy, nxy, count;
121
int i, j, k, s, dim, sign1, sign2, *vI;
122
123
I = abs(I);
124
dim = V.dim;
125
vI = V.v[I];
126
if ((co = (int*)malloc((pol.maxd - pol.mind + 1) * sizeof(int))) == 0)
127
exit (2);
128
for (i = 0; i <= pol.maxd-pol.mind; ++i)
129
co[i] = 0;
130
if ((list = (int*)malloc(pol.sum * sizeof(int))) == 0)
131
exit (2);
132
for (i = 0; i < pol.sum; ++i)
133
list[i] = 0;
134
/* nlist should be equal to pol.sum */
135
nlist = 0;
136
for (i = 1; i <= V.n && nlist <= pol.sum; ++i)
137
{
138
if (V.v[i][dim] == vI[dim])
139
{
140
s = sscp(vI, Fv[i], dim);
141
if (s == S)
142
{
143
if (nlist < pol.sum)
144
list[nlist] = i;
145
nlist += 1;
146
}
147
if (-s == S)
148
{
149
if (nlist < pol.sum)
150
list[nlist] = -i;
151
nlist += 1;
152
}
153
}
154
}
155
if (nlist != pol.sum)
156
/* the number of vectors with scalar product S is already different */
157
{
158
free(co);
159
free(list);
160
return(0);
161
}
162
/* listxy is the list of the nxy vectors from list that have scalar product S
163
with v[list[i]] */
164
if ((listxy = (int*)malloc(nlist * sizeof(int))) == 0)
165
exit (2);
166
for (i = 0; i < nlist; ++i)
167
{
168
for (j = 0; j < nlist; ++j)
169
listxy[j] = 0;
170
nxy = 0;
171
sign1 = list[i] > 0 ? 1 : -1;
172
for (j = 0; j < nlist; ++j)
173
{
174
sign2 = list[j] > 0 ? 1 : -1;
175
if (sign1*sign2 * sscp(V.v[sign1*list[i]], Fv[sign2*list[j]], dim) == S)
176
{
177
listxy[nxy] = list[j];
178
nxy += 1;
179
}
180
}
181
/* count is the number of pairs */
182
count = 0;
183
for (j = 0; j < nxy && count <= pol.maxd; ++j)
184
{
185
sign1 = listxy[j] > 0 ? 1 : -1;
186
for (k = j+1; k < nxy && count <= pol.maxd; ++k)
187
{
188
sign2 = listxy[k] > 0 ? 1 : -1;
189
if (sign1*sign2 * sscp(V.v[sign1*listxy[j]], Fv[sign2*listxy[k]], dim) == S)
190
count += 1;
191
}
192
}
193
if (count < pol.mind || count > pol.maxd ||
194
co[count-pol.mind] >= pol.coef[count-pol.mind])
195
/* if the number of pairs is smaller than pol.mind or larger than pol.maxd
196
or if the coefficient of X^count becomes now larger than the one in pol,
197
then the Bacher-polynomials can not be equal */
198
{
199
free(listxy);
200
free(co);
201
free(list);
202
return(0);
203
}
204
else
205
co[count-pol.mind] += 1;
206
}
207
free(listxy);
208
free(co);
209
free(list);
210
/* the Bacher-polynomials are equal */
211
return(1);
212
}
213
214
/*************************************************\
215
| prints a Bacher-polynomial
216
\*************************************************/
217
static void fputbach(outfile, pol)
218
FILE *outfile;
219
bachpol pol;
220
{
221
int i;
222
223
for (i = pol.mind; i <= pol.maxd; ++i)
224
{
225
if (pol.coef[i-pol.mind] != 0)
226
fprintf(outfile, "%d*x^%d ", pol.coef[i-pol.mind], i);
227
}
228
fprintf(outfile, "\n");
229
}
230
231