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