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
3
extern int npt,cp[],orb[],*pptr[],pno[];
4
extern FILE *ip,*op;
5
6
int
7
orbitsv (int pt, int *sv, int lo)
8
/* Computes orbit of pt under perms listed in pno, and writes
9
Schreier vector into sv
10
*/
11
{ int u,v,w,x,y,z;
12
if (lo==0)
13
{ for (u=1;u<=npt;u++) sv[u]=0;
14
orb[1]=pt; lo=1; sv[pt]= -1;
15
}
16
for (x=1;x<=lo;x++)
17
{ z=orb[x];
18
for (y=1;y<= *pno;y++)
19
{ w=pno[y]; v=pptr[w][z];
20
if (sv[v]==0) { lo++; orb[lo]=v; sv[v]=w+1; }
21
}
22
}
23
return(lo);
24
}
25
26
int
27
addsv (int pt, int *sv)
28
/* The Schreier vector sv is applied to the point pt, and the resulting word
29
added to the end of cp. It is assumed that pt is in the orbit. If not, the
30
program will break down.
31
Externals: cp.
32
*/
33
{ int pn;
34
pn=sv[pt]; while (pn!= -1)
35
{ (*cp)++; cp[*cp]=pn; pt=pptr[pn][pt]; pn=sv[pt]; }
36
return(0);
37
}
38
39
int
40
image (int pt)
41
/* The image of pt under cp is computed and returned.
42
Externals: pptr,cp.
43
*/
44
{ int i;
45
for (i=1;i<= *cp;i++) pt=pptr[cp[i]][pt];
46
return(pt);
47
}
48
49
int
50
invert (int *ptr1, int *ptr2)
51
/* permutation ptr1 is inverted and put in ptr2.
52
Externals: npt.
53
*/
54
{ int i;
55
for (i=1;i<=npt;i++) ptr2[ptr1[i]]=i;
56
return(0);
57
}
58
59
int
60
readperm (int *ptr)
61
/* The next npt numbers from input ip are read. These should form a
62
permutation on 1,2,3,...,npt. If not 2 is returned. If the perm is the
63
identity, 1 is returned, otherwise 0.
64
Externals: npt,orb,ip.
65
*/
66
{ int i,j,id; id=1;
67
for (i=1;i<=npt;i++) orb[i]=0;
68
for (i=1;i<=npt;i++)
69
{ fscanf(ip,"%d",ptr+i); j=ptr[i];
70
if (j<=0 || j>npt || orb[j])
71
{ fprintf(stderr,"perm[%d]=%d\n",i,j); return(2);}
72
orb[j]=1; if (id && j!=i) id=0;
73
}
74
return(id);
75
}
76
77
int
78
printvec (int *ptr, int e)
79
/* Points ptr[1] to ptr[npt+e] are output to op, followed by new line. The
80
first npt of these will be a permutation or a Schreier vector. e=0 or 1.
81
Externals: npt,op.
82
*/
83
{ int i;
84
if (npt>=10000)
85
for (i=1;i<=npt;i++) fprintf(op,"%6d",ptr[i]);
86
else
87
if (npt>=1000)
88
for (i=1;i<=npt;i++) fprintf(op,"%5d",ptr[i]);
89
else for (i=1;i<=npt;i++) fprintf(op,"%4d",ptr[i]);
90
fprintf(op," ");
91
for (i=npt+1;i<=npt+e;i++) fprintf(op,"%4d",ptr[i]);
92
fprintf(op,"\n");
93
return(0);
94
}
95
96
int
97
readvec (int *ptr, int e)
98
/* The next npt+e points from ip are read into array ptr.
99
Externals: npt,ip.
100
*/
101
{ int i; for (i=1;i<=npt+e;i++) fscanf(ip,"%d",ptr+i); return(0);}
102
103
int
104
readbaselo (int nb, int *base, int *lorb)
105
/* The nb base points are read into base, and the nb orbit lengths into lorb,
106
from ip.
107
Externals: ip.
108
*/
109
{ int i;
110
for (i=1;i<=nb;i++) fscanf(ip,"%d",base+i);
111
for (i=1;i<=nb;i++) fscanf(ip,"%d",lorb+i);
112
return(0);
113
}
114
115
int
116
printbaselo (int nb, int *base, int *lorb)
117
/* base and lorb are printed to op.
118
Externals: op.
119
*/
120
{ int i;
121
if (npt>=1000)
122
{ for (i=1;i<=nb;i++) fprintf(op,"%5d",base[i]); fprintf(op,"\n");
123
for (i=1;i<=nb;i++) fprintf(op,"%5d",lorb[i]); fprintf(op,"\n");
124
} else
125
{ for (i=1;i<=nb;i++) fprintf(op,"%4d",base[i]); fprintf(op,"\n");
126
for (i=1;i<=nb;i++) fprintf(op,"%4d",lorb[i]); fprintf(op,"\n");
127
}
128
return(0);
129
}
130
131
int
132
printpsv (int nb, int *gno, int **svptr)
133
/* Permutationsnos gno[1],...,gno[*gno] are output (up to npt+1), and then
134
Schreier vectors svptr[1],...,svptr[nb] are output to op.
135
Externals: npt,pptr,orb,op.
136
*/
137
{ int i,j,k;
138
for (i=1;i<= *gno;i++)
139
{ j=gno[i]; orb[j+1]=2*i-1; printvec(pptr[j],1); }
140
for (i=1;i<=nb;i++)
141
{ for (j=1;j<=npt;j++)
142
{ k=svptr[i][j]; if (k>0) k=orb[k]; fprintf(op,"%4d",k); }
143
fprintf(op,"\n");
144
}
145
return(0);
146
}
147
148
int
149
readpsv (int e, int nb, int nperms, int **svptr)
150
/* nperms permutations (up to npt+1) are read into perm nos pptr[e],pptr[e+2],.
151
and pptr[e+2x] is inverted into pptr[e+2x+1], for x=1,...,nperms. Then the
152
Screier vectors svptr[1],...,svptr[nb] are read from ip.
153
Externals: pptr,npt,ip.
154
*/
155
{ int i,j,*k;
156
for (i=1;i<=nperms;i++)
157
{ j=e+2*i-2; readvec(pptr[j],1); invert(pptr[j],pptr[j+1]); }
158
for (i=1;i<=nb;i++)
159
{ readvec(svptr[i],0);
160
for (j=1;j<=npt;j++) { k=svptr[i]+j; if (*k>0) *k +=e;}
161
}
162
return(0);
163
}
164
165
int seeknln (void) { while (getc(ip)!='\n'); }
166
167