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

563624 views
1
#include "defs.h"
2
3
extern char mult,outft[];
4
extern short rwd[],***scoeff[],*cst,*cend,*ocst,***coeff,
5
wd1[],wd2[],wd3[],wd4[];
6
extern int rsp;
7
extern short **simcos[],pinv[],gno[],base[],lorb[],*svptr[],cord[],cp[],bno,
8
invg[],**mat[],mwl2,mwdl,mlwdl,maxcos,dim,prime,*spv,**spm,ng,rwl,nb;
9
extern FILE *ip,*op;
10
11
int
12
gc (void)
13
/* Garbage collection of coefficients by writing and rereading */
14
{ short i,j; short l,*p,*q;
15
op=fopen(outft,"w");
16
for (i=0;i<ng;i++) for (j=1;j<=maxcos;j++) if ((p=coeff[i][j])!=0)
17
{ l= *p; q=p+l; while (p<=q) {fprintf(op," %d",*p); p++; }
18
l= *p; q=p+l; while (p<=q) {fprintf(op," %d",*p); p++; }
19
}
20
fclose(op);
21
ip=fopen(outft,"r");
22
cst=ocst;
23
for (i=0;i<ng;i++) for (j=1;j<=maxcos;j++) if (coeff[i][j]!=0)
24
{ coeff[i][j]=cst; fscanf(ip,"%hd",cst); p=cst; q=p+ *p;
25
while (++p<=q) fscanf(ip,"%hd",p); cst=q+1;
26
fscanf(ip,"%hd",cst); p=cst; q=p+ *p;
27
while (++p<=q) fscanf(ip,"%hd",p); cst=q+1;
28
}
29
fclose(ip); unlink("gctemp");
30
rsp=cend+1-cst;
31
printf("Performed garbage collection. rsp=%d.\n",rsp);
32
return(0);
33
}
34
35
int
36
comp (short *a, short **dp)
37
/* Compress string + vector in "a" into string in *dp
38
Vectors always occupy the last dim entries of words.
39
*/
40
{ short *a1,ol,nl,nl2,*p,*q,*r,*ae;
41
a1=a+mwdl; ae=a1+dim; p=a1; nl2=0;
42
while (++p<=ae) if (*p!=0) nl2+=2;
43
ol= (*dp==0) ? 0 : **dp+ *(*dp+ **dp+1);
44
nl=nl2+ *a;
45
if (nl==0) {*dp=0; return(0); }
46
if (nl>ol)
47
{ nl+=2; if (rsp<nl) gc();
48
if (rsp<nl)
49
{ fprintf(stderr,"Out of cspace. Increase CSPACE.\n"); return(-1); }
50
*dp=cst; cst+=nl; rsp-=nl;
51
}
52
p= *dp; q=a; r=q+ *a;
53
while (q<=r) {*p= *q; p++; q++; }
54
*p=nl2; q=a1;
55
while (++q<=ae) if (*q!=0) {*(++p)=q-a1; *(++p)= *q; }
56
return(0);
57
}
58
59
int
60
compb (short *a, short **dp)
61
/* Similar, but rewrites word at end of short space */
62
{ short *a1,nl,nl2,*p,*q,*r,*ae;
63
a1=a+mwdl; ae=a1+dim; p=a1; nl2=0;
64
while (++p<=ae) if (*p!=0) nl2+=2;
65
nl=nl2+ *a;
66
if (nl==0) {*dp=0; return(0);}
67
nl+=2;
68
if (rsp<nl) gc();
69
if (rsp<nl)
70
{ fprintf(stderr,"Out of cspace(b). Increase CSPACE.\n"); return(-1); }
71
cend-=nl; rsp-=nl; *dp=cend+1;
72
p= *dp; q=a; r=q+ *a;
73
while (q<=r) {*p= *q; p++; q++; }
74
*p=nl2; q=a1;
75
while (++q<=ae) if (*q!=0) {*(++p)=q-a1; *(++p)= *q; }
76
return(0);
77
}
78
79
int
80
expand (short *a, short *b)
81
/* expand string b to string + vector a */
82
{ short *a1,*ae,*p,*q,*r;
83
a1=a+mwdl; ae=a1+dim; p=a1;
84
while (++p<=ae) *p=0;
85
if (b==0) { *a=0; return(0);}
86
*a= *b; p=a; q=a+ *a; r=b;
87
while (++p<=q) *p= *(++r);
88
r++; q=r+ *r;
89
while (++r<q) {a1[*r]= *(r+1); r++; }
90
return(0);
91
}
92
93
int
94
action (short *a, short *b)
95
/* Replace vector a by its image under action by matrices of gens in word b
96
*/
97
{ short z,*be,c,*p,*ae; short *spve,*s,*v;
98
z=1; p=a; ae=a+dim;
99
while (++p<=ae) if (*p!=0) {z=0; break;}
100
if (z) return(0);
101
spve=spv+dim; be=b+ *b;
102
while (++b<=be)
103
{ s=spv;
104
while (++s<=spve) *s=0;
105
p=a;
106
while (++p<=ae) if ((c= *p)!=0)
107
{ v=mat[*b][p-a]; s=spv;
108
while (++s<=spve) {*s+=(c* *(++v)); *s%=prime; }
109
}
110
p=a; s=spv;
111
while (++p<=ae) *p= *(++s);
112
}
113
return(0);
114
}
115
116
int
117
concat (short *a, short *b)
118
/* Concatenate strings+vectors "a" and "b" */
119
{ short *a1,*bb,*be,c,*p,*q,*r,canct,min;
120
if (b==0) return(0);
121
a1=a+mwdl; bb=b+ *b+1; be=bb+ *bb;
122
if (mult)
123
{ while (++bb<be) {c= *bb; bb++; a1[c]+= *bb; a1[c]%=cord[c]; }}
124
else
125
{ action(a1,b);
126
while (++bb<be) {c= *bb; bb++; a1[c]+= *bb; a1[c]%=prime;}
127
}
128
min= (*a<= *b) ? *a : *b;
129
canct=0; p=a+ *a; q=b+1;
130
while (canct<min && *p==invg[*q]) {canct++; p--; q++;}
131
r=b+ *b;
132
while (q<=r) *(++p)= *(q++);
133
*a+= (*b-2*canct);
134
if (*a>mwl2) if (reduce(a)== -1) return(-1);
135
return(0);
136
}
137
138
int
139
concatl (short *b)
140
/* Similar, but concatenate b to the long word rwd */
141
{ short *a1,*bb,*be,c,*p,*q,*r,canct,min;
142
if (b==0) return(0);
143
a1=rwd+mlwdl; bb=b+ *b+1; be=bb+ *bb;
144
if (mult)
145
{ while (++bb<be) {c= *bb; bb++; a1[c]+= *bb; a1[c]%=cord[c]; }}
146
else
147
{ action(a1,b);
148
while (++bb<be) {c= *bb; bb++; a1[c]+= *bb; a1[c]%=prime;}
149
}
150
min= (rwl<= *b) ? rwl : *b;
151
canct=0; p=rwd+ rwl; q=b+1;
152
while (canct<min && *p==invg[*q]) {canct++; p--; q++;}
153
r=b+ *b;
154
rwl+= (*b-2*canct);
155
if (rwl>mlwdl)
156
{ fprintf(stderr,"Word too long. Increase MLWDL.\n"); return(-1);}
157
while (q<=r) *(++p)= *(q++);
158
return(0);
159
}
160
161
int
162
invwd (short *a, short *b)
163
/* Invert the word+vector a into b */
164
{ short *a1,*b1,*be,*p,*q;
165
a1=a+mwdl; p=a1; b1=b+mwdl; be=b1+dim; q=b1;
166
while (++q<=be) *q=0;
167
q=b1;
168
if (mult) {while (++q<=be) if (*(++p)!=0) *q= cord[p-a1]- *p; }
169
else while (++q<=be) if (*(++p)!=0) *q= prime - *p;
170
*b= *a; p=a+ *a; q=b+1;
171
while (p>a) {*q=invg[*p]; p--; q++; }
172
if (mult==0) action(b1,b);
173
return(0);
174
}
175
176
int
177
ainvb (short *a, short *b, short *c)
178
/* Concatenate word+vector "a" with inverse of word+vector "b" and write into c
179
*/
180
{ short min,canct,n,*p,*q,*r,*c1,*ce,*a1;
181
min= (*a<= *b) ? *a : *b;
182
p=a+1; q=b+1; canct=0;
183
while (canct<min && *p== *q) {canct++; p++; q++; }
184
p= a+ *a+1; q=a+canct+1; r=c; *r= *a+ *b-2*canct;
185
while (--p>=q) *(++r)= invg[*p];
186
p= b+canct; q=b+ *b;
187
while (++p<=q) *(++r)= *p;
188
a1=a+mwdl; c1=c+mwdl; ce=c1+dim; p=c1;
189
while (++p<=ce) *p=0;
190
p=c1; q=a1; r= b+ mwdl;
191
if (mult)
192
{ while (++p<=ce) if (*(++q)!=0) *p=cord[p-c1]- *q;
193
p=c1;
194
while (++p<=ce) if (*(++r)!=0) {*p+= *r; *p%= cord[p-c1]; }
195
}
196
else
197
{ while (++p<=ce) if (*(++q)!=0) *p=prime- *q;
198
action(c1,c);
199
p=c1;
200
while (++p<=ce) if (*(++r)!=0) {*p+= *r; *p%= prime; }
201
}
202
if (*c>mwl2) if (reduce(c)== -1) return(-1);
203
return(0);
204
}
205
206
int
207
reduce (short *a)
208
/* Attempt to reduce length of word+vector "a", using coefficients computed
209
from higher values of bno
210
*/
211
{ short *q,*r,*a1,*rwd1,*rwde; short ol,nl,cos,i,j,*p,*s,*cp1,*cpe;
212
ol= *a; *cp=ol; p=cp; q=a; r=a+ol; cp1=cp+mlwdl; cpe=cp1+dim;
213
while (++q<=r) *(++p)= *q;
214
p=cp1;
215
while (++p<=cpe) *p=0;
216
for (i=bno+1;i<=nb;i++) addsv(image(base[i]),svptr[i]);
217
nl= *cp- ol;
218
if (nl<ol)
219
{ *a=nl; p=cp+ *cp+1; q=a; r=a+nl;
220
while (++q<=r) *q= invg[*(--p)];
221
rwd1=rwd+mlwdl; rwde=rwd1+dim;
222
for (i=bno+1;i<=nb;i++) if (lorb[i]>1)
223
{ q=rwd1;
224
while (++q<=rwde) *q=0;
225
cos=1; rwl=0; p=cp; s=p+ *cp;
226
while (++p<=s)
227
{ if (concatl(scoeff[i][*p][cos])== -1) return(-1);
228
cos= simcos[i][*p][cos];
229
}
230
if (cos!=1) {fprintf(stderr,"Reduction error.\n"); return(-1); }
231
*cp= rwl; p=cp; s=p+rwl; q=rwd;
232
while (++p<=s) *p= *(++q);
233
q=rwd1; r=rwde; p=cp1;
234
if (mult) while (++q<=r) {*(++p)+= *q; j=cord[q-rwd1]; *p%=j; }
235
else while (++q<=r) {*(++p)+= *q; *p%=prime; }
236
}
237
p=cp1; r=rwd1;
238
while (++p<=cpe) *(++r)= *p;
239
a1=a+mwdl; r=rwd1; q=a1;
240
if (mult) {while (++r<=rwde) {*(++q)+= *r; *q%=cord[q-a1]; }}
241
else
242
{ action(rwd1,a);
243
while (++r<=rwde) {*(++q)+= *r; *q%=prime;}
244
}
245
}
246
if (*a>mwl2)
247
{ fprintf(stderr,"Reduction unsuccessful.\n"); return(-1); }
248
return(0);
249
}
250
251
int
252
concheck (void)
253
/* Consistency check */
254
{ short *p,*q,ok;
255
if (ainvb(wd1,wd2,wd3)== -1) return(-1);
256
if (reduce(wd3)== -1) return(-1);
257
ok= *wd3==0;
258
if (ok)
259
{ p=wd3+mwdl; q=p+dim;
260
while (++p<=q) if (*p!=0) {ok=0; break;}
261
}
262
if (ok==0)
263
{ fprintf(stderr,"Inconsistent relation.\n"); return(-1);}
264
return(0);
265
}
266
267
int
268
setpinv (void)
269
{ short i,j;
270
for (i=0;i<prime;i++) pinv[i]=0;
271
for (i=1;i<prime;i++) if (pinv[i]==0) for (j=1;j<prime;j++)
272
if (i*j % prime ==1) { pinv[i]=j; pinv[j]=i; break; }
273
return(0);
274
}
275
276