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

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