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
#include "permfns.h"
3
4
#define RD(A,B) (done[(B)/32][(A)]&(one<<((B)%32)))
5
#define WD(A,B) done[(B)/32][(A)]|=(one<<((B)%32))
6
extern char inf[],outf[],outfg[],gap,firstnew;
7
extern int imsp[],*done[],*imcos[];
8
extern short perm[],sv[],cp[],orb[],
9
base[],lorb[],pno[], *pptr[],*svptr[],
10
inv[],rno[],mp,mrel,dnwds,mpt,mb;
11
extern int psp,svsp,space;
12
int nr,endr,maxcos,*fpt,*bpt,*def,scanno,nscan,nelim,bno,lo,
13
ccos,lastd,cind,nfree,stcr,endcr,fcos,bcos,lcl,np2,*rel,one=1;
14
short npt;
15
int rsp;
16
char fullsc,clsd,lkah;
17
FILE *ip,*op;
18
/* Many of the variables are as in program tcrun */
19
20
int
21
grprog (void)
22
{ int i,j,k,l,m,n,b,l1,l2,nb,rn1,nperms,npt1,mxp,min,mini;
23
int spn,quot; float a;
24
ip=fopen(inf,"r");
25
if (ip==0) { fprintf(stderr,"Cannot open %s\n",inf); return(-1); }
26
fscanf(ip,"%hd%d%d%d",&npt,&nperms,&nb,&k);
27
if (npt>mpt) { fprintf(stderr,"npt too big. Increase NPT.\n"); return(-1);}
28
if (nb>=mb) { fprintf(stderr,"nb too big. Increase MB.\n"); return(-1); }
29
if (nb*npt>svsp)
30
{ fprintf(stderr,"Out of sv space.Increase SVSP.\n"); return(-1);}
31
if (k<=0) {fprintf(stderr,"Wrong input format.\n"); return(-1); }
32
npt1=npt+1; np2=2*nperms-1;
33
quot=psp/npt1; if (quot>mp) quot=mp; mxp=quot;
34
for (i=0;i<mxp;i++) pptr[i]=perm+i*npt1-1;
35
for (i=1;i<=nb;i++) svptr[i]=sv+(i-1)*npt-1;
36
if (np2>=mxp)
37
{ fprintf(stderr,"nperms too big. Increase PSP (or MP).\n"); return(-1); }
38
readbaselo(nb,base,lorb); readpsv(0,nb,nperms,svptr);
39
fclose(ip);
40
for (i=0;i<np2;i+=2) { inv[i]=i+1; inv[i+1]=i; }
41
42
/* Group is read in. Now initialize coset table for enumaration. */
43
printf("Input a,b,l1,l2.\nmaxcos = a*lorb+b\n");
44
printf("Exit lookahead after scanning l1 or eliminating l2 cosets.\n");
45
scanf("%f%d%d%d",&a,&b,&l1,&l2);
46
mrel=dnwds*32; maxcos=a*npt+b; spn=maxcos*(np2+4+dnwds)+1;
47
if (spn>space)
48
{ fprintf(stderr,"Not enough space in coset table. Increase SPACE.\n");
49
return(-1);
50
}
51
rel=imsp+spn; rsp=space-spn;
52
for (i=0;i<=np2;i++) imcos[i]=imsp+i*maxcos-1;
53
fpt=imcos[np2]+maxcos+1; bpt=fpt+maxcos; def=bpt+maxcos;
54
for (i=0;i<dnwds;i++) done[i]=def+maxcos*(i+1);
55
56
if (gap) {op=fopen(outfg,"w"); fprintf(op,"COHOMOLO.PermRels := [\n");}
57
nr=0; endr= -1;
58
for (bno=nb;bno>=1;bno--)
59
{ printf("bno=%d.\n",bno);
60
/* We are going to do a coset enumeration of the group G[bno] (in the stabilizer
61
chain), using genrators of G[bno+1] as subgroup.
62
First we write in as many entries in the coset table as possible, making
63
definitions of the cosets corresponding to the points in the orbit of bno
64
under G[bno], using the Schreier vector sv[bno]. At the end of the
65
enumeration, only these cosets should remain, and none of them should get
66
eliminated.
67
*/
68
lo=lorb[bno]; rno[bno]=nr; maxcos=lo*a+b; rn1=nr-1; *pno=0;
69
for (i=0;i<=np2;i++) for (j=1;j<=maxcos;j++) imcos[i][j]=0;
70
for (i=0;i<np2;i+=2) if (pptr[i][npt1]>=bno)
71
{ (*pno)++; pno[*pno]=i;
72
if (pptr[i][npt1]>bno) {imcos[i][1]=1; imcos[i+1][1]=1;}
73
}
74
if (orbitsv(base[bno],svptr[bno],0)!=lo)
75
{ fprintf(stderr,"Orbit length wrong!\n"); return(-1); }
76
if (lo==1) continue;
77
def[1]= -1;
78
for (l=1;l<=lo;l++)
79
{ n=orb[l]; cp[n]=l;
80
if ((k=svptr[bno][n])!= -1)
81
{ j=pptr[k][n]; m=cp[j]; imcos[k-1][m]=l; imcos[k][l]=m; def[l]=k; }
82
}
83
/* Now we initialize the relator set, by putting in one relator for each
84
generator in G[bno].
85
*/
86
for (i=0;i<np2;i+=2) if (pptr[i][npt1]==bno)
87
{ *cp=1; cp[1]=i+1;
88
for (j=bno;j<=nb;j++) addsv(image(base[j]),svptr[j]);
89
if (addrel()== -1) return(-1);
90
}
91
92
/* Since new relators will be added in the course of the enumeration, we want
93
to avoid scanning the same coset under the same relator more than once.
94
The array done records which pairs have been scanned in compressed form,
95
using one bit for each coset-relator pair.
96
WD(a,b) writes a one into the bit corresponding to coset a and relator b.
97
RD(a,b) returns the value of this bit.
98
*/
99
for (j=0;j<dnwds;j++) for (i=1;i<=lo;i++) done[j][i]=0;
100
for (i=0;i<=rn1;i++) WD(1,i);
101
/* Now we start the enumeration, as in tcrun */
102
lastd=lo; cind=lo; nfree=lo+1;
103
for (i=1;i<=lo;i++) bpt[i]=i-1;
104
for (i=0;i<maxcos;i++) fpt[i]=i+1;
105
fpt[lo]=0; fpt[maxcos]=0;
106
while(1)
107
{ ccos=1; lkah=0;
108
while (ccos!=0)
109
{ clsd=1; endcr= -1; scanno= -1;
110
while (endcr!=endr)
111
{ scanno++; fullsc=1;
112
stcr=endcr+2; endcr+=(1+rel[stcr-1]);
113
if (RD(ccos,scanno)==0) scanrel();
114
if (fullsc==0)
115
{ clsd=0;
116
if (lkah==0)
117
{ lcl=bpt[ccos]; lkah=1; nscan=0; nelim=0;
118
/* printf("Entering lookahead.\n"); */
119
}
120
}
121
}
122
ccos=fpt[ccos];
123
if (lkah)
124
{ nscan++;
125
if (nscan>l1 || nelim>=l2 || ccos==0)
126
{ if (cind!=maxcos)
127
{ /* printf("Exiting lookahead. cind=%d.\n",cind); */
128
ccos=fpt[lcl]; lkah=0;
129
}
130
else ccos=0;
131
}
132
}
133
}
134
if (cind==lo) break;
135
/* The enumeration did not complete, so we add a new relator */
136
if (firstnew) i=fpt[lo]; else
137
{ min=0;
138
for (n=fpt[lo];n!=0;n=fpt[n])
139
{ *cp=0; i=n;
140
for (j=def[i];j!= -1;j=def[i]) { (*cp)++; cp[*cp]=j; i=imcos[j][i]; }
141
for (i=1,j= *cp;i<=j;i++,j--)
142
{ if (i==j) cp[i]=inv[cp[i]];
143
else { k=cp[i]; cp[i]=inv[cp[j]]; cp[j]=inv[k]; }
144
}
145
for (i=bno;i<=nb;i++) addsv(image(base[i]),svptr[i]);
146
if (min==0 || *cp<min) { min= *cp; mini=n;}
147
}
148
i=mini;
149
}
150
*cp=0;
151
for (j=def[i];j!= -1;j=def[i]) { (*cp)++; cp[*cp]=j; i=imcos[j][i]; }
152
for (i=1,j= *cp;i<=j;i++,j--)
153
{ if (i==j) cp[i]=inv[cp[i]];
154
else { k=cp[i]; cp[i]=inv[cp[j]]; cp[j]=inv[k]; }
155
}
156
for (i=bno;i<=nb;i++) addsv(image(base[i]),svptr[i]);
157
if (addrel()== -1) return(-1);
158
}
159
}
160
if (gap) {fprintf(op,"];\n"); fclose(op);}
161
op=fopen(outf,"w");
162
fprintf(op,"%3d ",nb); for (i=1;i<=nb;i++) fprintf(op,"%4d",rno[i]);
163
fprintf(op,"\n");
164
m= -1;
165
while (m!=endr)
166
{ m++; l=rel[m];
167
for (i=0;i<=l;i++) fprintf(op,"%4d",rel[m+i]);
168
fprintf(op,"\n"); m+=l;
169
}
170
return(0);
171
}
172
173
int
174
addrel (void)
175
/* Adds a relator */
176
{ int i,j,k;
177
nr++;
178
if (nr>mrel)
179
{ fprintf(stderr,"Too many relations. Increase MREL.\n"); return(-1); }
180
if (endr+ *cp+1 >=rsp)
181
{ fprintf(stderr,"Out of relation space. Increase SPACE.\n"); return(-1); }
182
endr++; rel[endr]= *cp;
183
for (i=1;i<= *cp;i++) rel[endr+i]=inv[cp[*cp+1-i]];
184
rno[bno]++; endr+= *cp;
185
if (gap)
186
{ if (nr>1) fprintf(op,",\n");
187
putc('[',op);
188
for (i=1;i<= *cp;i++)
189
{ j=cp[*cp+1-i]; k= (j%2==0) ? -(j/2 +1) : (j/2 +1);
190
fprintf(op,"%d",k);
191
if (i< *cp) putc(',',op); else putc(']',op);
192
}
193
}
194
for (i=1;i<= *cp;i++)
195
{ j=cp[*cp+1-i]; k= (j%2==0) ? -(j/2 +1) : (j/2 +1);
196
printf("%2d",k);
197
if (i< *cp) printf(" * "); else printf("\n");
198
}
199
return(0);
200
}
201
202
int
203
scanrel (void)
204
{ int i,j,k,l,m; char comp;
205
fcos=ccos; bcos=ccos;
206
comp=1;
207
for (i=stcr;i<=endcr;i++)
208
{ k=imcos[rel[i]][fcos];
209
if (k==0) { comp=0; break;}
210
fcos=k;
211
}
212
if (comp) { if (fcos!=bcos) coinc(fcos,bcos); WD(ccos,scanno); return(0); }
213
stcr=i;
214
for (i=endcr;i>=stcr;i--)
215
{ l=rel[i]; m=inv[l]; k=imcos[m][bcos];
216
if (k==0)
217
{ if (i==stcr)
218
{ k=imcos[l][fcos];
219
if (k==0) { imcos[l][fcos]=bcos; imcos[m][bcos]=fcos; }
220
else if (k!=bcos) coinc(k,bcos);
221
WD(ccos,scanno); return(0);
222
}
223
if (lkah || nfree==0) { fullsc=0; return(0); }
224
for (j=0;j<=np2;j++) imcos[j][nfree]=0;
225
for (j=0;j<dnwds;j++) done[j][nfree]=0;
226
cind++; def[nfree]=l;
227
imcos[m][bcos]=nfree; imcos[l][nfree]=bcos; bcos=nfree;
228
bpt[nfree]=lastd; fpt[lastd]=nfree; lastd=nfree;
229
nfree=fpt[nfree]; fpt[lastd]=0;
230
}
231
else bcos=k;
232
}
233
if (fcos!=bcos) coinc(fcos,bcos);
234
WD(ccos,scanno);
235
return(0);
236
}
237
238
int
239
coinc (int c1, int c2)
240
{ int lc,hc,qh,qt,i,j,y,fhc,bhc,lim,him,x; char sw;
241
lc=1;
242
while (lc!=c1 && lc!=c2) lc=fpt[lc];
243
hc= lc==c1 ? c2 : c1;
244
if (hc<=lo) {fprintf(stderr,"Impossible coincidence.\n"); return(-1); }
245
/* Cosets with numbers <=lo should certainly not be eliminated! */
246
qh=0; qt=0;
247
fhc=fpt[hc]; bhc=bpt[hc]; fpt[bhc]=fhc;
248
if (fhc==0) lastd=bhc; else bpt[fhc]=bhc;
249
if (ccos==hc) { ccos=bhc; endcr=endr; clsd=0; }
250
if (lkah && lcl==hc) lcl=bhc;
251
while (1)
252
{ fpt[hc]=nfree; nfree=hc; cind--; nelim++;
253
x=1; sw=0;
254
while (x<= *pno)
255
{ if (sw) i++; else i=pno[x];
256
him=imcos[i][hc];
257
if (him!=0)
258
{ j=inv[i]; lim=imcos[i][lc];
259
if (him==hc) him=lc; else imcos[j][him]=0;
260
if (lim==0) imcos[i][lc]=him;
261
else
262
{ if (lim==hc) { imcos[i][lc]=lc; lim=lc; }
263
while (fpt[him]<0) him= -fpt[him];
264
while (fpt[lim]<0) lim= -fpt[lim];
265
if (him!=lim)
266
{ y=1;
267
while (y!=him && y!=lim) y=fpt[y];
268
if (y==him) { him=lim; lim=y; }
269
if (him<=lo)
270
{ fprintf(stderr,"Impossible coincidence(q).\n"); return(-1); }
271
fhc=fpt[him]; bhc=bpt[him]; fpt[bhc]=fhc;
272
if (fhc==0) lastd=bhc; else bpt[fhc]=bhc;
273
if (ccos==him) { ccos=bhc; endcr=endr; clsd=0; }
274
if (lkah && lcl==him) lcl=bhc;
275
fpt[him]= -lim;
276
if (qh==0) qh=him; else bpt[qt]=him;
277
qt=him; bpt[qt]=0;
278
}
279
}
280
y=imcos[i][lc];
281
if (imcos[j][y]==0) imcos[j][y]=lc;
282
}
283
if (sw) x++; sw= sw ? 0 : 1;
284
}
285
if (qh==0) break;
286
hc=qh; qh=bpt[qh]; lc= -fpt[hc]; bpt[hc]=0;
287
}
288
return(0);
289
}
290
291