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