Exemple #1
0
rsgp()
/* Used to read in intermediate subgroups when subgp is true */
{ short i,np,k,l,n,*ptr;
  if ((ip=fopen(inf3,"r"))==0)
  { fprintf(stderr,"Cannot open %s.\n",inf3); return(-1); }
  fscanf(ip,"%hd%hd%hd%hd",&i,&np,&k,&l);
  if (i!=npt || k!=nb || l<=0)
  { fprintf(stderr,"Intermediate group has wrong input format.\n");return(-1);}
  seeknln(); seeknln(); seeknln();
  if (4*exp+2*np+ngads>mxp)
  { fprintf(stderr,"Out of perm space. Increase PSP (or MP).\n"); return(-1); }
  for (i=1;i<=np;i++)
  { readvec(pptr[stig+i+1],1); invert(pptr[stig+i+1],pptr[stig+i]); }
  for (i=1;i<=nb;i++)
  { readvec(sv2ptr[i],0);
    for (n=1;n<=npt;n++)
    { ptr=sv2ptr[i]+n; if (*ptr>0) *ptr=stig+(*ptr+1)/2; }
  }
  fclose(ip);
  return(0);
}
Exemple #2
0
int 
main (void)
{ short i,j,m,n,y,np,nb,mxp,ord,im,len,*p,*q;
  int quot;
  int chct;
  char nt,f,id,eq,fault,flnm[80];
reenter:
  printf("Do you wish to read permutations from a file (y/n)?  ");
  if (getchar()=='y')
  { f=1; snl();
    printf("Input filename:    "); scanf("%s",flnm); snl();
    if ((ip=fopen(flnm,"r"))==0)
    { fprintf(stderr,"Cannot open %s.\n",flnm); goto reenter; }
    fscanf(ip,"%hd%hd%hd%hd",&npt,&np,&nb,&m); seeknln();
    if (nb!=0) 
    { if (nb>=mb)
      { fprintf(stderr,"Too many base points. Increase MB.\n"); return(-1);}
      for (i=1;i<=nb;i++) fscanf(ip,"%hd",base+i);
      seeknln();
    }
    if (m!=0) seeknln();
  }
  else
  { f=0; snl(); printf("Input npt:   "); scanf("%hd",&npt); snl(); nb=0; }
  if (npt>mpt) {fprintf(stderr,"npt too big. Increase NPT.\n"); exit(1); }
  quot=psp/npt; if (quot>mp) mxp=mp; else mxp=quot;
  printf("Perm nos 1 - %d can be read. Perm no 0 is always the identity\n",
          mxp-1);
  for (i=0;i<mxp;i++) { pptr[i]=perm-1+npt*i; pno[i]=0; }
  p=pptr[0]; for (i=1;i<=npt;i++) p[i]=i;
  pno[0]=1;
  if (f)
  { if (np>=mxp)
    { fprintf(stderr,"Not enough perm space to read perms from file.");
      fprintf(stderr," Increase PSP (or MP).\n"); exit(1);
    }
    for (i=1;i<=np;i++)
    { if (readperm(pptr[i])==2)
      { fprintf(stderr,"Perm no %i is not a permutation.\n"); exit(1);}
      pno[i]=1; seeknln();
    }
    fclose(ip);
  }

  while(1)
  { printf("Choose option. Print 'l' for list.\n");
    scanf("%s",opt);
    if (strcmp(opt,"l")==0)
    { snl();
      printf("rp  n                = read perm no n.\n");
      printf("pp  n                = print perm no n.\n");
      printf("ppc  n               = print perm no n in cycles.\n");
      printf("inv m n              = calc inverse p[n] of p[m].\n");
      printf("pr n l i(1)...i(l)   = calc prod p[n] of p[i(1)]...p[i(l)].\n");
      printf("im m x               = print image of point x under p[m].\n");
      printf("fp n                 = print fixed pts of p[n].\n");
      printf("fpn l i(1)...i(l)    = print common fixed pts of p[i(1)],...,p[i(l)].\n");
      printf("cyc n x              = print cycle of point x under p[n].\n");
      printf("ord n                = print order of p[n].\n");
      printf("orb l i(1)...i(l)    = print orbits of p[i(1)]...p[i(l)].\n");
      printf("rb                   = read in a base for the group.\n");
      printf("op filename          = output some perms to 'filename'.\n");
      printf("opord filename       = output some perms to 'filename' and\n");
      printf("                       compute order of group they generate.\n");
      printf("                      (Only works if base known for G!).\n");
      printf("rf n filename        = read in additional perms from filename\n");
      printf("                       starting at perm. no. n.\n");
      printf("q                    = quit.\n");
    }
    else if (strcmp(opt,"rp")==0)
    { scanf("%hd",&n); snl();
      if (n<=0 || n>=mxp)  fprintf(stderr,"Invalid perm.no %d.\n",n);
      else
      { while (rp(pptr[n])==2)
        { fprintf(stderr,"That is not a permutation. Try again!\n"); snl(); }
        pno[n]=1;
      }
    }
    else if (strcmp(opt,"pp")==0)
    { scanf("%hd",&n); snl();
      if (n<0 || n>=mxp || pno[n]==0)
      { fprintf(stderr,"Perm no %d is not defined.\n",n); continue;}
      p=pptr[n];
      for (i=1;i<=npt;i++) printf("%4d",p[i]); printf("\n");
    }
    else if (strcmp(opt,"ppc")==0)
    { scanf("%hd",&n); snl();
      if (n<0 || n>=mxp || pno[n]==0)
      { fprintf(stderr,"Perm no %d is not defined.\n",n); continue;}
      for (i=1;i<=npt;i++) orb[i]=1;
      p=pptr[n]; id=1;
      chct=0;
      for (m=1;m<=npt;m++) if (orb[m])
      { if ((im=p[m])!=m)
        { id=0; orb[im]=0; printf("(%d,%d",m,im);
          chct += (num_digits(m)+num_digits(im)+2);
          while ((im=p[im])!=m)
          { if (chct>=75) { printf(",\n%d",im); chct=num_digits(im);}
            else {printf(",%d",im); chct += (1+num_digits(im));}
            orb[im]=0;
          }
          printf(")");
          chct++;
          if (chct>=72) { printf("\n"); chct=0;}
        }
      }
      if (id) printf("Perm no %d is the identity.\n",n);
      else printf("\n");
    }
    else if (strcmp(opt,"inv")==0)
    { scanf("%hd%hd",&m,&n); snl();
      if (m<0 || m>=mxp || pno[m]==0)
      { fprintf(stderr,"Perm no %d is not defined.\n",m); continue;}
      if (n<=0 || n>=mxp)
      { fprintf(stderr,"Invalid perm. no. %d.\n",n); continue;}
      invert(pptr[m],pptr[n]); pno[n]=1;
    }
    else if (strcmp(opt,"pr")==0)
    { scanf("%hd%hd",&m,cp);
      if (m<=0 || m>=mxp)
      { fprintf(stderr,"Invalid perm no. %d\n",m);snl(); continue;}
      fault=0;
      for (i=1;i<= *cp;i++)
      { scanf("%hd",cp+i); n= *(cp+i);
        if (n<0 || n>=mxp || pno[n]==0)
        { fprintf(stderr,"Perm no %d is not defined.\n",n);fault=1; snl();
          break;
        }
      }
      if (fault) continue;
      snl();
      p=pptr[m];
      for (i=1;i<=npt;i++) p[i]=image(i);
      pno[m]=1;
    }
    else if (strcmp(opt,"im")==0)
    { scanf("%hd%hd",&n,&i); snl();
      if (n<0 || n>=mxp || pno[n]==0)
      { fprintf(stderr,"Perm no %d is not defined.\n",n); continue;}
      if (i<=0 || i>npt)
      { fprintf(stderr,"Inappropriate point %d.\n",i); continue;}
      printf("%d\n",pptr[n][i]);
    }
    else if (strcmp(opt,"fp")==0)
    { scanf("%hd",&n); snl();
      if (n<0 || n>=mxp || pno[n]==0)
      { fprintf(stderr,"Perm no %d is not defined.\n",n); continue;}
      p=pptr[n]; nt=1;
      for (i=1;i<=npt;i++) if (p[i]==i) { nt=0; printf("%4d",i);}
      if (nt) printf("No fixed points.\n"); else printf("\n");
    }
    else if (strcmp(opt,"fpn")==0)
    { scanf("%hd",cp);
      fault=0;
      for (i=1;i<= *cp;i++)
      { scanf("%hd",cp+i); n= *(cp+i);
        if (n<0 || n>=mxp || pno[n]==0)
        { fprintf(stderr,"Perm no %d is not defined.\n",n); fault=1; snl();
          break;
        }
      }
      if (fault) continue;
      snl(); nt=1;
      for (n=1;n<=npt;n++)
      { f=1;
        for (i=1;i<= *cp;i++) if (pptr[cp[i]][n]!=n) { f=0; break;}
        if (f) { nt=0; printf("%4d",n); }
      }
      if (nt) printf("No fixed points.\n"); else printf("\n");
    }
    else if (strcmp(opt,"cyc")==0)
    { scanf("%hd%hd",&n,&i); snl();
      if (i<=0 || i>npt)
      { fprintf(stderr,"Inappropriate point %d.\n",i); continue;}
      if (n<0 || n>=mxp || pno[n]==0)
      { fprintf(stderr,"Perm no %d is not defined.\n",n); continue;}
      p=pptr[n];
      if ((im=p[i])==i) printf("%d is fixed under p[%d].\n",i,n);
      else
      { printf("(%d,%d",i,im);
        while ((im=p[im])!=i) printf(",%d",im);
        printf(")\n");
      }
    }
    else if (strcmp(opt,"ord")==0)
    { scanf("%hd",&n); snl();
      if (n<0 || n>=mxp || pno[n]==0)
      { fprintf(stderr,"Perm no %d is not defined.\n",n); continue;}
      p=pptr[n]; id=1;
      for (i=1;i<=npt;i++) orb[i]=1;
      ord=1;
      for (m=1;m<=npt;m++) if (orb[m])
      { if ((im=p[m])!=m)
        { id=0; orb[im]=0; len=2;
          while ((im=p[im])!=m) { orb[im]=0; len++; }
          ord=lcm(ord,len);
        }
      }
      if (id) printf("Perm no %d is the identity.\n",n);
      else printf("%d\n",ord);
    }
    else if (strcmp(opt,"orb")==0)
    { scanf("%hd",cp);
      fault=0;
      for (i=1;i<= *cp;i++)
      { scanf("%hd",cp+i); n= *(cp+i);
        if (n<0 || n>=mxp || pno[n]==0)
        { fprintf(stderr,"Perm no %d is not defined.\n",n); fault=1; snl();
          break;
        }
      }
      if (fault) continue;
      snl();
      allorbs();
    }
    else if (strcmp(opt,"eq")==0)
    { scanf("%hd%hd",&m,&n); snl();
      if (n<0 || n>=mxp || pno[n]==0)
      { fprintf(stderr,"Perm no %d is not defined.\n",n); continue;}
      if (m<0 || m>=mxp || pno[m]==0)
      { fprintf(stderr,"Perm no %d is not defined.\n",m); continue;}
      p=pptr[m]; q=pptr[n]; eq=1;
      for (i=1;i<=npt;i++) if (p[i]!=q[i]) {eq=0; break;}
      if (eq) printf("Permutations are equal.\n");
      else printf("Permutations are not equal on point %d.\n",i);
    }
    else if (strcmp(opt,"rb")==0)
    { snl(); printf("Input base points, preceded by their number.\n");
      scanf("%hd",&nb);
      if (nb>=mb)
      { fprintf(stderr,"Too many base points. Increase MB.\n"); return(-1);}
      for (i=1;i<=nb;i++) scanf("%hd",base+i);
      snl();
    }
    else if ((y=strcmp(opt,"opord"))==0 || strcmp(opt,"op")==0)
    { if (y==0 && nb==0)
      { fprintf(stderr,"Order can only be computed when base is known.\n");
        continue;
      }
      scanf("%s",flnm); snl(); op=fopen(flnm,"w");
      printf("Input perm nos to be saved, preceded by their number.\n");
      scanf("%hd",&n); fprintf(op,"%3d %4d%4d%4d\n",npt,n,nb,0);
      if (nb!=0)
      if (npt>=10000)
      { for (i=1;i<=nb;i++) fprintf(op,"%6d",base[i]); fprintf(op,"\n");}
      else
      if (npt>=1000)
      { for (i=1;i<=nb;i++) fprintf(op,"%5d",base[i]); fprintf(op,"\n");}
      else
      { for (i=1;i<=nb;i++) fprintf(op,"%4d",base[i]); fprintf(op,"\n");}
      f=0;
      for (i=1;i<=n;i++)
      { scanf("%hd",&m);
        if (m<0 || m>=mxp || pno[m]==0)
        { printf("Perm no %d is not defined.\n",m);
          fclose(op); snl(); unlink(flnm); f=1; break;
        }
        printvec(pptr[m],0);
      }
      if (f) continue;
      snl(); fclose(op);
      if (y==0)
      { sprintf(sysstring,"cp %s optxxx.ip",flnm);
        system(sysstring); system("gprun -b optxxx ip ip");
        unlink("optxxx.ip");
      }
    }
    else if (strcmp(opt,"rf")==0)
    { scanf("%hd",&n); scanf("%s",flnm); snl();
      if ((ip=fopen(flnm,"r"))==0)
      { fprintf(stderr,"Cannot open %s.\n",flnm); continue; }
      fscanf(ip,"%hd%hd%hd%hd",&i,&np,&j,&m); seeknln();
      if (i!=npt)
      { fprintf(stderr,"npt does not agree.\n"); fclose(ip); continue;}
      if (j!=0) seeknln();
      if (m!=0) seeknln();
      if (n<=0 || np+n-1>=mxp)
      { fprintf(stderr,"Not enough perm space to read perms from file.");
        fclose(ip); continue;
      }
      for (i=1;i<=np;i++)
      { if (readperm(pptr[i+n-1])==2)
        { fprintf(stderr,"Perm no %i is not a permutation.\n");
          pno[i+n-1]=0; break;
        }
        pno[i+n-1]=1; seeknln();
      }
      fclose(ip);
    }
    else if (strcmp(opt,"q")==0) {snl(); break;}
    else {printf("Invalid option.\n"); snl();}
  }
  exit(0);
}
Exemple #3
0
/* This program differs from most other permutation programs in that perms are
   all stored in the single array sp. Schreier vectors are stored in the short
   array csp. This assumes that there are at most 127 perms, which will
   probably always be the case. The first half of the program (crprog1)
   involves relatively little short space, so it is assumed that there is enough
   In the first half, coefficients as words in H generated by the relators
   of G are computed using the output of conrun.
*/
crprog1()
{ short *pc,*qc,ex,neg; int x;
  short i,j,k,l,m,n,cl,rl,*p,ocl,im,pt,pt1,pn,ipt;
  if ((ip=fopen(inf2,"r"))== 0)
  { fprintf(stderr,"Cannot open %s.\n",inf2); return(-1);}
  fscanf(ip,"%hd%hd%hd%hd",&npt,&nph,&nb,&k);
  if (nb>=mb) {fprintf(stderr,"nb too big. Increase MB.\n"); return(-1);}
  if (k<=2) {fprintf(stderr,"inf2 has illegal format.\n"); return(-1); }
  seeknln(); seeknln();
  for (i=1;i<=nb;i++) fscanf(ip,"%hd",lorb+i);
  pptr=psp-1; pspst=psp+nph; svptr=cpsp-1;  cpst=cpsp+nb;
  invg=sp; nph2=2*nph; spst=sp+nph2;
  for (i=1;i<=nph;i++)
  { pptr[i]=spst+(i-1)*npt-1; p=pptr[i];
    for (j=1;j<=npt;j++) {fscanf(ip,"%hd",&k); p[k]=j; }
    invg[2*i-2]=2*i-1; invg[2*i-1]=2*i-2;
    seeknln();
  }
  spst+=(npt*nph);
  for (i=1;i<=nb;i++)
  { svptr[i]=csp+(i-1)*npt-1; pc=svptr[i];
    for (j=1;j<=npt;j++) {fscanf(ip,"%hd",&k); pc[j]= k>0 ? (k+1)/2 : k;}
  }
  cp=csp+nb*npt; rel=cp+wdl;
  fclose(ip);
/* It is assumed that there is enough space so far. */

  strcpy(inf1,inf0); strcat(inf1,".cp");
  if ((ip=fopen(inf1,"r"))==0)
  { fprintf(stderr,"Cannot open %s.\n",inf1); return(-1);}
  fscanf(ip,"%hd%hd",&coh_index,&npg); npg2=2*npg-1;
  x= (nb+2)*npg*coh_index;
  if (spst+x-sp>space)
  { fprintf(stderr,"Not enough space. Increase SPACE.\n"); return(-1); }
  if (pspst+(nb+2)*npg-psp>ptrsp)
  { fprintf(stderr,"Not enough ptrsp. Increase PTRSP.\n"); return(-1); }
  cpptr=pspst; pspst+=2*npg;
  for (i=0;i<=npg2;i++) { cpptr[i]=spst-1; spst+=coh_index; }
  for (i=1;i<=nb;i++)
  { cpco[i]=pspst-1; pspst+=npg;
    for (j=1;j<=npg;j++) {cpco[i][j]=spst-1; spst+=coh_index;}
  }
  for (i=1;i<=npg;i++)
  { j=2*i-2; k=j+1;
    for (l=1;l<=coh_index;l++)
    { for (m=1;m<=nb;m++) fscanf(ip,"%hd",cpco[m][i]+l);
      fscanf(ip,"%hd",&m); cpptr[j][l]=m; cpptr[k][m]=l;
    }
  }
  fclose(ip);

  strcpy(inf1,inf0); strcat(inf1,".rel");
  if ((ip=fopen(inf1,"r"))==0)
  { fprintf(stderr,"Cannot open %s.\n",inf1); return(-1);}
  fscanf(ip,"%hd%hd",&k,&rno); seeknln();
  op=fopen(outft,"w");
/* Now we have read everything in, and the computation can start */
  orno=0;
  for (i=1;i<=rno;i++)
  { fscanf(ip,"%hd",&rl);
    printf("Scanning rel no %d.\n",i);
    for (j=1;j<=rl;j++) { fscanf(ip,"%hd",&k); rel[j]=k; }
    for (j=1;j<=coh_index;j++)
    { pt=j; cl=0;
      for (k=rl;k>=1;k--)
      { l=rel[k]; im=cpptr[l][pt];
        if (l%2==1) {neg=1;pt1=im; m=(l+1)/2;}
        else {neg=0; pt1=pt; m=(l+2)/2;}
        ocl=cl;
        for (n=1;n<=nb;n++)
        { ipt=cpco[n][m][pt1]; pn=svptr[n][ipt];
          while (pn!= -1)
          { cl++; cp[cl]=2*(pn-1); ipt=pptr[pn][ipt]; pn=svptr[n][ipt]; }
        }
        if (neg)
        { pc=cp+ocl+1; qc=cp+cl;
          while (pc<=qc)
          { if (pc==qc) (*pc)++;
            else {ex= *pc; *pc= *qc+1; *qc= ex+1;}
            pc++; qc--;
          }
        }
        pt=im;
      }
      if (pt!=j) 
      { fprintf(stderr,
                "Relation number %d is not satisfied by the permutations.\n",i);
         return(-1);
      }
      fprintf(op,"%4d",cl);
      for (k=cl;k>=1;k--) fprintf(op," %2d",cp[k]);
      fprintf(op,"\n");
    } /* j loop */
    if (i==rno && orno==0)
    { orno=rno; if (fscanf(ip,"%hd",&j)>0) rno+=j;}
      
  } /* i loop */
  printf("All relations scanned.\n");
  fclose(op); fclose(ip);
  return(0);
}