Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
Project: cocalc-sagemath-dev-slelievre
Views: 418346#include "defs.h"12extern char inf1[],inf2[],inf3[],outf1[],outf2[],outf3[],temp1[],temp2[],3expg,exph,cr,dcr,triv;4extern int psp,trsp,svsp;5extern int mpt,mb,6tree[],perm[],gorb[],lorbg[],lorbh[],base[],7fpt[],bpt[],coh_index[],*cp[],*trad[],*sv[],8*tailad[],**cpad[],**svgptr[],**svhptr[];9int trptr;10int npt,**lcp,**ucp,*stop,dummy,*pst,*pend,nb,fnt,lnt,11ind,coind,oind,cind,bno,pt,**expp,npg;12FILE *ip,*op,*opx;1314void advance (void);1516/* The data structures of this program differ from other permutation group17programs. Permutations are not numbered, but are located by their base18adresses. Consequently, arrays sv and cp are arrays of pointers. The19current permutation in cp is stored in the middle of cp (since it has to be20expanded in both directions), between adresses lcp and ucp of cp.21The next six procedures are the equivlents of the corresponding ones22in permfns.c, but addsv can go in both directions.23In this half of the program, coset reps of H in G are computed.24*/2526int image (int pt)27{ int **p;28p=lcp;29while (p<=ucp) {pt=(*p)[pt]; p++;}30return(pt);31}3233void addsvb (int pt, int **sv)34{ int *p;35while ((p=sv[pt])!=stop) {pt=p[pt]; lcp--; *lcp =p-npt; }36}3738void addsvf (int pt, int **sv)39{ int *p;40while ((p=sv[pt])!=stop) {pt=p[pt]; ucp++; *ucp=p; }41}4243void invert (int *a, int *b)44{int i; for (i=1;i<=npt;i++) b[a[i]]=i; }4546void rdperm (int *a, int *b)47{ int i,*r;48for (i=1;i<=npt;i++) fscanf(ip,"%d",a+i);49r=pst+1; fscanf(ip,"%d",r); invert(a,b);50}5152void rdsv (int **sv)53{ int i,j;54for (i=1;i<=npt;i++)55{ fscanf(ip,"%d",&j); sv[i]= (j==0) ? 0 : (j== -1) ? stop : cp[j];}56}5758int cnprg1 (void)59{ int i,j,k,ad,sad,nph,*svpt,*p1,*p2,**csvg,**csvh,nexp;60char pthere,w,ok,allok; long fac;61stop = &dummy;62if ((ip=fopen(inf1,"r"))==0)63{ fprintf(stderr,"Cannot open %s.\n",inf1); return(-1); }64fscanf(ip,"%d%d%d%d",&npt,&npg,&nb,&k);65if (npt>mpt) {fprintf(stderr,"npt too big. Increase mpt.\n"); return(-1); }66if (nb>=mb) {fprintf(stderr,"nb too big. Increase MB.\n"); return(-1); }67if (2*nb*npt>svsp)68{ fprintf(stderr,"svsp too small. Increase SVSP.\n"); return(-1); }69if (k<=0) {fprintf(stderr,"Wrong input format for G.\n"); return(-1); }70for (i=1;i<=nb;i++) fscanf(ip,"%d",base+i);71for (i=1;i<=nb;i++) fscanf(ip,"%d",lorbg+i);72pst=perm-1; pend=perm+psp-1;73#ifdef __clang__74/* workaround for a bug in Apple LLVM version 7.0.2 (clang-700.1.81),75and possibly other versions. See also76https://github.com/gap-packages/cohomolo/issues/577*/78if (psp < 0) /* never should happen */79fprintf(stderr, "%d", psp);80#endif81if (pst+2*npg*npt>pend)82{ fprintf(stderr,"Out of space.Increase PSP.\n"); return(-1);}83for (i=1;i<=npg;i++)84{ p1=pst; p2=pst+npt; pst+=(2*npt); rdperm(p1,p2); cp[2*i-1]=p2; }85for (i=1;i<=nb;i++) {svgptr[i]=sv+npt*(i-1)-1; rdsv(svgptr[i]); }86fclose(ip);87/* G is read. Now read the subgroup H */88if (triv)89{ nph=0; for (i=1;i<=nb;i++)90{ lorbh[i]=1; svhptr[i]=sv+npt*(nb+i-1)-1;91for (j=1;j<=npt;j++) svhptr[i][j]=0; svhptr[i][base[i]]=stop;92}93}94else95{ if ((ip=fopen(inf2,"r"))==0)96{ fprintf(stderr,"Cannot open %s.\n",inf2); return(-1); }97fscanf(ip,"%d%d%d%d",&i,&nph,&j,&k); w=0;98if (k<=0) { fprintf(stderr,"Wrong input format for H.\n"); return(-1); }99if (i!=npt || j!=nb) w=1;100else for (i=1;i<=nb;i++)101{ fscanf(ip,"%d",lorbh+i); if (lorbh[i]!=base[i]) w=1; }102if (w)103{ fprintf(stderr,"npt or base for G and H do not agree.\n");return(-1);}104for (i=1;i<=nb;i++) fscanf(ip,"%d",lorbh+i);105if (pst+2*npt*nph+2>pend)106{ fprintf(stderr,"Out of space.Increase PSP.\n"); return(-1);}107for (i=1;i<=nph;i++)108{ p2=pend-npt; p1=p2-npt; pend-=(2*npt); rdperm(p1,p2); cp[2*i-1]=p2;}109for (i=1;i<=nb;i++) {svhptr[i]=sv+npt*(nb+i-1)-1; rdsv(svhptr[i]); }110fclose(ip);111}112for (i=1;i<=nb;i++) fpt[i]=0;113p1=pst; p2=p1+npt; pst+=(2*npt); lcp=cp; expp= cp+2*npt-1;114cind=1; fac=1; coh_index[nb+1]=1; lnt=0;115116/* Now we compute the indices of H in G in the stabilizer chain into the array117coh_index. The nontrivial indices are linked by fpt and bpt.118*/119for (i=nb;i>=1;i--)120{ j=lorbg[i]; fac=fac*j; j=lorbh[i]; fac=fac/j; ind=fac; coh_index[i]=ind;121if (ind>coh_index[i+1])122{ if (lnt==0) lnt=i;123else { fpt[i]=fnt; bpt[fnt]=i; }124fnt=i;125}126}127bpt[fnt]= -1; fpt[lnt]= -1;128printf("Indices: ");129for (i=1;i<=nb;i++) printf("%5d",coh_index[i]); printf("\n");130if (ind==1) { fprintf(stderr,"G=H.\n"); return(-1); }131nexp=0; ind=1; oind=1; trptr=0;132133/* Now we start the backtrack search for the left coset reps of H in G. The134necessary information about these is stored in the array tree. This is done135so as to make it as easy as possible to compute which coset an arbitrary136element of G lies in. If expg is true, then those perms in G which arise137are expanded and stored.138If dcr is true, then a small subset of the coset reps will need to be139output as perms, later. For this purpose, the base images of all coset reps140are output to a temporary file.141ind is the current coh_index coh_index[bno], and cind is the no of coset reps142found so far.143*/144for (i=fnt;i!= -1;i=fpt[i])145{ trad[i]=tree+trptr; tree[trptr]=base[i]; trptr+=2; }146if (dcr) opx=fopen(temp2,"w");147if (cr)148{ op=fopen(outf3,"w");149fprintf(op,"%4d %d%4d%4d\n",npt,coh_index[1]-1,0,0);150}151sad=trptr; tree[trptr]=1; trptr++;152for (bno=lnt;bno!= -1;bno=bpt[bno])153{ printf("bno=%d.\n",bno);154*gorb=1; gorb[1]=base[bno];155ind=coh_index[bno]; csvg=svgptr[bno]; csvh=svhptr[bno];156allok=(lorbh[bno]==1);157/* if allok, then all coset reps in this link of the stabilizer chain will be158coset reps of H in G.159*/160if (expg) {for (i=1;i<=npt;i++) expp[i]=0; expp[base[bno]]=stop; }161for (pt=1;pt<=npt;pt++)162{ svpt=csvg[pt];163if (svpt!=0 && svpt!=stop)164{ ucp=lcp-1; addsvf(pt,csvg); pthere=0;165if (expg)166{ for (i=1;i<=npt;i++) p1[i]=image(i);167invert(p1,p2); ucp=lcp; *ucp=p1;168}169j=sad;170for (i=fpt[bno];i!= -1;i=fpt[i])171{ tailad[i]=tree+j; cpad[i]=ucp+1; j+=2; }172/* In the search, for each basic coset rep g in the stabilizer chain, we have173to try out gh as a possible coset rep of H in G, for each h in the list of174coset reps of H[bno-1] in G[bno-1]. coind and oind record the search175through this list.176*/177coind=1;178while (coind<=oind)179{ if (coind>1) advance(); ok=1;180if (allok==0)181for (i=1;i<=*gorb && ok;i++) if (csvh[image(gorb[i])]!=0) ok=0;182/* That was the membership test. ok true means we have found a new rep */183if (ok)184{ if (pthere)185{ ad=fpt[bno];186while (*tailad[ad]== *trad[ad]) ad=fpt[ad];187tree[trptr]= *tailad[ad];188}189else190{ pthere=1; ad=bno; tree[trptr]=pt;191if (expg)192{ expp[pt]=p1; p1=pst; p2=p1+npt; pst+=(2*npt); nexp++;193if (pst>pend)194{ fprintf(stderr,"Out of perm space. Increase PSP.\n");195return(-1);196}197}198}199*(trad[ad]+1)=trptr; trad[ad]=tree+trptr; trptr+=2;200for (i=fpt[ad];i!= -1;i=fpt[i])201{ *(trad[i]+1)= -1; tree[trptr]= *tailad[i];202trad[i]=tree+trptr; trptr+=2;203}204cind++; tree[trptr]=cind; trptr++;205if (trptr>trsp)206{ fprintf(stderr,"Out of tree space. Increase TRSP.\n");207return(-1);208}209if (dcr) for (i=fnt;i!= -1;i=fpt[i]) fprintf(opx,"%5d",*trad[i]);210/* if cr, then we output each coset rep */211if (cr) {212if (npt>=1000)213{ for (i=1;i<=npt;i++) fprintf(op,"%5d",image(i));fprintf(op,"\n");}214else215{ for (i=1;i<=npt;i++) fprintf(op,"%4d",image(i));fprintf(op,"\n");}216}217if (cind==ind) goto nextbno;218} /* if (ok) */219coind++;220} /* while (coind<=oind) */221(*gorb)++; gorb[*gorb]=pt;222} /* if (svpt!=0 ... */223} /* for (pt=1;pt<=npt;... */224fprintf(stderr,"Premature end of search.\n"); return(-1);225nextbno:226if (expg) for (i=1;i<=npt;i++) svgptr[bno][i]=expp[i];227sad-=2; oind=ind;228} /* main bno loop */229if (dcr) fclose(opx); if (cr) fclose(op);230for (i=fnt;i!= -1;i=fpt[i]) *(trad[i]+1)= -1;231printf("Tree space used = %d.\n",trptr);232if (expg) printf("Number of perms expanded = %d.\n",nexp);233return(0);234}235236void advance (void)237/* This advances the element h in the search through elements gh */238{ int ad,k,*p,*q;239ad=lnt;240while ((k= *(tailad[ad]+1)) == -1) ad=bpt[ad];241q=tree+k; ucp=cpad[ad]-1;242while (ad!= -1)243{ tailad[ad]=q; cpad[ad]=ucp+1;244if (expg) { p=svgptr[ad][*q]; if (p!=stop) {ucp++; *ucp=p; }}245else addsvf(*q,svgptr[ad]);246q+=2; ad=fpt[ad];247}248}249250251