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/****************************************************************************1**2*A GAP.c ANUPQ source Eamonn O'Brien3*A & Frank Celler4**5*Y Copyright 1995-1997, Lehrstuhl D fuer Mathematik, RWTH Aachen, Germany6*Y Copyright 1997-1997, School of Mathematical Sciences, ANU, Australia7**8*/9#include "pq_defs.h"10#include "pga_vars.h"11#include "pcp_vars.h"12#include "pq_functions.h"13#include "constants.h"1415#if defined(GAP_LINK)161718/****************************************************************************19**20*V p1, p221*/22int p1[2], p2[2];232425/****************************************************************************26**27*F WriteGap( <str> )28** write <str> to gap via input pipe29*/30void WriteGap(char *str)31{32write(p2[1], str, strlen(str));33}343536/****************************************************************************37**38*F ReadGap( <str> )39** read string from gap via output pipe into buffer <str>40*/41void ReadGap(char *str)42{43char *ptr;4445/* read next line */46ptr = str;47do48while (read(p1[0], ptr, 1) != 1)49;50while (*ptr++ != '\n');5152/* append a trailing '\0' */53*(--ptr) = 0;5455/* if line begins with a '#' ignore this line and start again */56if (*str == '#') {57fprintf(stderr, "%s\n", str);58ReadGap(str);59}60}616263/****************************************************************************64**65*F WriteGapInfo( <auts>, <pga> )66** write initial information to GAP input pipe67*/68void WriteGapInfo(int ***auts, struct pga_vars *pga)69{70int i;71char str[MAXWORD];7273/* we need the GAP library files defined in the package "anupq" */74WriteGap("LoadPackage( \"anupq\" );\n");7576/* give debug information if 'ANUPQlog' is set to 'LogTo' */77WriteGap("ANUPQlog( \"debug.out\" );\n");7879/* use a record 'ANUPQglb' to hold all global variables */80WriteGap("ANUPQglb := rec();;\n");81sprintf(str, "ANUPQglb.d := %d;\n", pga->ndgen);82WriteGap(str);83ReadGap(str);84sprintf(str, "ANUPQglb.F := GF(%d);\n", pga->p);85WriteGap(str);86ReadGap(str);87sprintf(str, "ANUPQglb.q := %d;\n", pga->q);88WriteGap(str);89ReadGap(str);90sprintf(str, "ANUPQglb.genD := [];\n");91WriteGap(str);92ReadGap(str);93sprintf(str, "ANUPQglb.genQ := [];\n");94WriteGap(str);95ReadGap(str);96for (i = 1; i <= pga->m; ++i)97write_GAP_matrix(0, "ANUPQglb.genD", auts[i], pga->ndgen, 1, i);98}99100101/****************************************************************************102**103*F start_GAP_file( <auts>, <pga> )104** start GAP process or write necessary information to existing process105*/106void start_GAP_file(int ***auts, struct pga_vars *pga)107{108int pid;109char *path;110int i;111char tmp[200];112113pipe(p1);114pipe(p2);115#ifdef HAVE_WORKING_VFORK116if ((pid = vfork()) == 0)117#else118if ((pid = fork()) == 0)119#endif120{121dup2(p1[1], 1);122dup2(p2[0], 0);123if ((path = (char *)getenv("ANUPQ_GAP_EXEC")) == NULL)124#if defined(ANUPQ_GAP_EXEC)125path = ANUPQ_GAP_EXEC;126#else127path = "gap";128#endif129if (execlp(path, path, "-r -q", 0) == -1) {130perror("Error in system call to GAP");131exit(FAILURE);132}133} else if (pid == -1) {134perror("cannot fork");135exit(FAILURE);136} else {137138/* write GAP information to file */139WriteGapInfo(auts, pga);140141/* try to syncronise with gap process */142WriteGap("165287638495312637;\n");143for (i = 0; i < 100; i++) {144ReadGap(tmp);145if (!strcmp(tmp, "165287638495312637"))146break;147}148if (i == 100)149fprintf(stderr, "WARNING: did not got magic number, got '%s'\n", tmp);150}151}152153154/****************************************************************************155**156*F QuitGap()157** close the pipes to GAP158*/159void QuitGap(void)160{161WriteGap("quit;\n");162close(p1[1]);163close(p2[1]);164close(p1[0]);165close(p2[0]);166wait((int *)0);167}168169170/****************************************************************************171**172*F ReadFromGapPipe( <value> )173** read a string from the GAP output pipe and check whether it is an integer174*/175void ReadFromGapPipe(int *value)176{177Logical error;178char str[MAXWORD];179180ReadGap(str);181*value = string_to_int(str, &error);182if (error) {183fprintf(stderr, "Error in reading stabiliser data from GAP pipe\n");184fprintf(stderr, "got line: '%s'\n", str);185exit(FAILURE);186}187}188189190/****************************************************************************191**192*F read_stabiliser_gens( <nr>, <sol>, <pga> )193** read the insoluble stabiliser generators from the pipe;194** each list of stabilisers is preceded by two integers --195** the first indicates whether the stabiliser is soluble;196** the second is the number of generators for the stabiliser197*/198int ***read_stabiliser_gens(int nr_gens, int ***sol_gens, struct pga_vars *pga)199{200int ndgen = pga->ndgen;201int gamma, i, j;202int ***stabiliser;203int current;204205/* check if any gens for the stabiliser have already been computed */206current = pga->nmr_stabilisers;207208/* read the first two integers (is soluble and number of generators) */209ReadFromGapPipe(&pga->soluble);210ReadFromGapPipe(&pga->nmr_stabilisers);211212/* get enough room for the generators */213pga->nmr_stabilisers += current;214215/* memory leakage September 1996 */216stabiliser = reallocate_array(sol_gens,217current,218ndgen,219nr_gens,220pga->nmr_stabilisers,221ndgen,222nr_gens,223TRUE);224/*225if (current != 0) {226stabiliser = reallocate_array( sol_gens, current, ndgen,227nr_gens, pga->nmr_stabilisers,228ndgen, nr_gens, TRUE );229}230else {231stabiliser = allocate_array( pga->nmr_stabilisers, ndgen,232nr_gens, TRUE );233}234*/235236/* now read in the insoluble generators */237for (gamma = current + 1; gamma <= pga->nmr_stabilisers; ++gamma)238for (i = 1; i <= ndgen; ++i)239for (j = 1; j <= ndgen; ++j)240ReadFromGapPipe(&stabiliser[gamma][i][j]);241242/* return the result */243return stabiliser;244}245246247/****************************************************************************248**249*F insoluble_stab_gens( <rep>, <orbit_length> )250** calculate the stabiliser of the supplied representative using GAP251*/252void insoluble_stab_gens(int rep, int orbit_length)253{254char str[MAXWORD];255256sprintf(str,257"stab := ANUPQstabilizer( %d, %d, ANUPQglb );;1;\n",258rep,259orbit_length);260WriteGap(str);261ReadGap(str);262sprintf(str, "ANUPQoutputResult( stab, \"*stdout*\" );;\n");263WriteGap(str);264}265266267/****************************************************************************268**269*F write_GAP_matrix270** write out a matrix in a GAP input form271**272*/273void write_GAP_matrix(274FILE *GAP_input, char *gen, int **A, int size, int start, int nr)275{276int i, j;277char str[MAXWORD];278279sprintf(str, "%s[%d] := [\n", gen, nr);280WriteGap(str);281for (i = start; i < start + size; ++i) {282WriteGap("[");283for (j = start; j < start + size - 1; ++j) {284sprintf(str, "%d, ", A[i][j]);285WriteGap(str);286}287if (i != start + size - 1)288sprintf(str, "%d],\n", A[i][j]);289else290sprintf(str, "%d]] * One( ANUPQglb.F );;\n", A[i][j]);291WriteGap(str);292}293}294295296/****************************************************************************297**298*F StartGapFile( <pga> )299** write basic input information to GAP input pipe300*/301void StartGapFile(struct pga_vars *pga)302{303char str[MAXWORD];304305sprintf(str, "ANUPQglb.s := %d;\n", pga->s);306WriteGap(str);307ReadGap(str);308sprintf(str, "ANUPQglb.r := %d;\n", pga->r);309WriteGap(str);310ReadGap(str);311}312313314#endif315316317