CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

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

Path: gap4r8 / pkg / anupq-3.2 / src / GAP.c
Views: 418346
1
/****************************************************************************
2
**
3
*A GAP.c ANUPQ source Eamonn O'Brien
4
*A & Frank Celler
5
**
6
*Y Copyright 1995-1997, Lehrstuhl D fuer Mathematik, RWTH Aachen, Germany
7
*Y Copyright 1997-1997, School of Mathematical Sciences, ANU, Australia
8
**
9
*/
10
#include "pq_defs.h"
11
#include "pga_vars.h"
12
#include "pcp_vars.h"
13
#include "pq_functions.h"
14
#include "constants.h"
15
16
#if defined(GAP_LINK)
17
18
19
/****************************************************************************
20
**
21
*V p1, p2
22
*/
23
int p1[2], p2[2];
24
25
26
/****************************************************************************
27
**
28
*F WriteGap( <str> )
29
** write <str> to gap via input pipe
30
*/
31
void WriteGap(char *str)
32
{
33
write(p2[1], str, strlen(str));
34
}
35
36
37
/****************************************************************************
38
**
39
*F ReadGap( <str> )
40
** read string from gap via output pipe into buffer <str>
41
*/
42
void ReadGap(char *str)
43
{
44
char *ptr;
45
46
/* read next line */
47
ptr = str;
48
do
49
while (read(p1[0], ptr, 1) != 1)
50
;
51
while (*ptr++ != '\n');
52
53
/* append a trailing '\0' */
54
*(--ptr) = 0;
55
56
/* if line begins with a '#' ignore this line and start again */
57
if (*str == '#') {
58
fprintf(stderr, "%s\n", str);
59
ReadGap(str);
60
}
61
}
62
63
64
/****************************************************************************
65
**
66
*F WriteGapInfo( <auts>, <pga> )
67
** write initial information to GAP input pipe
68
*/
69
void WriteGapInfo(int ***auts, struct pga_vars *pga)
70
{
71
int i;
72
char str[MAXWORD];
73
74
/* we need the GAP library files defined in the package "anupq" */
75
WriteGap("LoadPackage( \"anupq\" );\n");
76
77
/* give debug information if 'ANUPQlog' is set to 'LogTo' */
78
WriteGap("ANUPQlog( \"debug.out\" );\n");
79
80
/* use a record 'ANUPQglb' to hold all global variables */
81
WriteGap("ANUPQglb := rec();;\n");
82
sprintf(str, "ANUPQglb.d := %d;\n", pga->ndgen);
83
WriteGap(str);
84
ReadGap(str);
85
sprintf(str, "ANUPQglb.F := GF(%d);\n", pga->p);
86
WriteGap(str);
87
ReadGap(str);
88
sprintf(str, "ANUPQglb.q := %d;\n", pga->q);
89
WriteGap(str);
90
ReadGap(str);
91
sprintf(str, "ANUPQglb.genD := [];\n");
92
WriteGap(str);
93
ReadGap(str);
94
sprintf(str, "ANUPQglb.genQ := [];\n");
95
WriteGap(str);
96
ReadGap(str);
97
for (i = 1; i <= pga->m; ++i)
98
write_GAP_matrix(0, "ANUPQglb.genD", auts[i], pga->ndgen, 1, i);
99
}
100
101
102
/****************************************************************************
103
**
104
*F start_GAP_file( <auts>, <pga> )
105
** start GAP process or write necessary information to existing process
106
*/
107
void start_GAP_file(int ***auts, struct pga_vars *pga)
108
{
109
int pid;
110
char *path;
111
int i;
112
char tmp[200];
113
114
pipe(p1);
115
pipe(p2);
116
#ifdef HAVE_WORKING_VFORK
117
if ((pid = vfork()) == 0)
118
#else
119
if ((pid = fork()) == 0)
120
#endif
121
{
122
dup2(p1[1], 1);
123
dup2(p2[0], 0);
124
if ((path = (char *)getenv("ANUPQ_GAP_EXEC")) == NULL)
125
#if defined(ANUPQ_GAP_EXEC)
126
path = ANUPQ_GAP_EXEC;
127
#else
128
path = "gap";
129
#endif
130
if (execlp(path, path, "-r -q", 0) == -1) {
131
perror("Error in system call to GAP");
132
exit(FAILURE);
133
}
134
} else if (pid == -1) {
135
perror("cannot fork");
136
exit(FAILURE);
137
} else {
138
139
/* write GAP information to file */
140
WriteGapInfo(auts, pga);
141
142
/* try to syncronise with gap process */
143
WriteGap("165287638495312637;\n");
144
for (i = 0; i < 100; i++) {
145
ReadGap(tmp);
146
if (!strcmp(tmp, "165287638495312637"))
147
break;
148
}
149
if (i == 100)
150
fprintf(stderr, "WARNING: did not got magic number, got '%s'\n", tmp);
151
}
152
}
153
154
155
/****************************************************************************
156
**
157
*F QuitGap()
158
** close the pipes to GAP
159
*/
160
void QuitGap(void)
161
{
162
WriteGap("quit;\n");
163
close(p1[1]);
164
close(p2[1]);
165
close(p1[0]);
166
close(p2[0]);
167
wait((int *)0);
168
}
169
170
171
/****************************************************************************
172
**
173
*F ReadFromGapPipe( <value> )
174
** read a string from the GAP output pipe and check whether it is an integer
175
*/
176
void ReadFromGapPipe(int *value)
177
{
178
Logical error;
179
char str[MAXWORD];
180
181
ReadGap(str);
182
*value = string_to_int(str, &error);
183
if (error) {
184
fprintf(stderr, "Error in reading stabiliser data from GAP pipe\n");
185
fprintf(stderr, "got line: '%s'\n", str);
186
exit(FAILURE);
187
}
188
}
189
190
191
/****************************************************************************
192
**
193
*F read_stabiliser_gens( <nr>, <sol>, <pga> )
194
** read the insoluble stabiliser generators from the pipe;
195
** each list of stabilisers is preceded by two integers --
196
** the first indicates whether the stabiliser is soluble;
197
** the second is the number of generators for the stabiliser
198
*/
199
int ***read_stabiliser_gens(int nr_gens, int ***sol_gens, struct pga_vars *pga)
200
{
201
int ndgen = pga->ndgen;
202
int gamma, i, j;
203
int ***stabiliser;
204
int current;
205
206
/* check if any gens for the stabiliser have already been computed */
207
current = pga->nmr_stabilisers;
208
209
/* read the first two integers (is soluble and number of generators) */
210
ReadFromGapPipe(&pga->soluble);
211
ReadFromGapPipe(&pga->nmr_stabilisers);
212
213
/* get enough room for the generators */
214
pga->nmr_stabilisers += current;
215
216
/* memory leakage September 1996 */
217
stabiliser = reallocate_array(sol_gens,
218
current,
219
ndgen,
220
nr_gens,
221
pga->nmr_stabilisers,
222
ndgen,
223
nr_gens,
224
TRUE);
225
/*
226
if (current != 0) {
227
stabiliser = reallocate_array( sol_gens, current, ndgen,
228
nr_gens, pga->nmr_stabilisers,
229
ndgen, nr_gens, TRUE );
230
}
231
else {
232
stabiliser = allocate_array( pga->nmr_stabilisers, ndgen,
233
nr_gens, TRUE );
234
}
235
*/
236
237
/* now read in the insoluble generators */
238
for (gamma = current + 1; gamma <= pga->nmr_stabilisers; ++gamma)
239
for (i = 1; i <= ndgen; ++i)
240
for (j = 1; j <= ndgen; ++j)
241
ReadFromGapPipe(&stabiliser[gamma][i][j]);
242
243
/* return the result */
244
return stabiliser;
245
}
246
247
248
/****************************************************************************
249
**
250
*F insoluble_stab_gens( <rep>, <orbit_length> )
251
** calculate the stabiliser of the supplied representative using GAP
252
*/
253
void insoluble_stab_gens(int rep, int orbit_length)
254
{
255
char str[MAXWORD];
256
257
sprintf(str,
258
"stab := ANUPQstabilizer( %d, %d, ANUPQglb );;1;\n",
259
rep,
260
orbit_length);
261
WriteGap(str);
262
ReadGap(str);
263
sprintf(str, "ANUPQoutputResult( stab, \"*stdout*\" );;\n");
264
WriteGap(str);
265
}
266
267
268
/****************************************************************************
269
**
270
*F write_GAP_matrix
271
** write out a matrix in a GAP input form
272
**
273
*/
274
void write_GAP_matrix(
275
FILE *GAP_input, char *gen, int **A, int size, int start, int nr)
276
{
277
int i, j;
278
char str[MAXWORD];
279
280
sprintf(str, "%s[%d] := [\n", gen, nr);
281
WriteGap(str);
282
for (i = start; i < start + size; ++i) {
283
WriteGap("[");
284
for (j = start; j < start + size - 1; ++j) {
285
sprintf(str, "%d, ", A[i][j]);
286
WriteGap(str);
287
}
288
if (i != start + size - 1)
289
sprintf(str, "%d],\n", A[i][j]);
290
else
291
sprintf(str, "%d]] * One( ANUPQglb.F );;\n", A[i][j]);
292
WriteGap(str);
293
}
294
}
295
296
297
/****************************************************************************
298
**
299
*F StartGapFile( <pga> )
300
** write basic input information to GAP input pipe
301
*/
302
void StartGapFile(struct pga_vars *pga)
303
{
304
char str[MAXWORD];
305
306
sprintf(str, "ANUPQglb.s := %d;\n", pga->s);
307
WriteGap(str);
308
ReadGap(str);
309
sprintf(str, "ANUPQglb.r := %d;\n", pga->r);
310
WriteGap(str);
311
ReadGap(str);
312
}
313
314
315
#endif
316
317