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 collectp2.c ANUPQ source Eamonn O'Brien3**4*Y Copyright 1995-2001, Lehrstuhl D fuer Mathematik, RWTH Aachen, Germany5*Y Copyright 1995-2001, School of Mathematical Sciences, ANU, Australia6**7*/89#include "pq_defs.h"10#include "pcp_vars.h"11#include "constants.h"1213void14add_p2string(int string, int length, int collected_part, struct pcp_vars *pcp);1516/* collection procedure for the prime 2;17this routine is documented in the file collect.c */1819void collectp2(int pointer, int collected_part, struct pcp_vars *pcp)20{21register int *y = y_address;2223register int p1; /* string pointer */24register int cg; /* collected generator */25register int ug; /* uncollected generator */26register int sp = 0; /* stack pointer */27register int len = 1; /* length */28register int str; /* string pointer */29register int halfwt; /* last generator with weight <= cc/2 */30register int weight_diff; /* current class - weight of ug */31register int firstcg; /* first collected generator for loop counter */32register int lastcg; /* last collected generator for loop counter */3334register int cp = collected_part;35register int class_end = pcp->clend;36register int current_class = pcp->cc;37register int p_pcomm = pcp->ppcomm;38register int p_power = pcp->ppower;39register int structure = pcp->structure;4041int strstk[STACK_SIZE]; /* string stack */42int lenstk[STACK_SIZE]; /* length stack */4344register int i;4546#include "access.h"4748/* Step (0) --49initialize collector */5051if (pointer < 0)52lenstk[0] = y[-pointer + 1];53else if (pointer == 0)54return;5556halfwt = y[class_end + current_class / 2];57strstk[0] = pointer;5859/* Step (1) --60process next word on stack */6162while (sp >= 0) {63str = strstk[sp];64if (str < 0) {65/* we have a genuine string */66len = lenstk[sp];67sp--;6869/* get first generator from string */70i = y[-str + 2];71ug = FIELD2(i);72/* if ug > halfwt, whole string can be added to the73collected part without creating any commutators */74if (ug > halfwt) {75add_p2string(str, len, cp, pcp);76continue;77}7879if (len != 1) {80/* stack remainder of string */81strstk[++sp] = str - 1;82lenstk[sp] = len - 1;83}84} else {85/* str is a generator */86ug = str;87sp--;88/* if ug > halfwt, ug commutes with all higher generators */89if (ug > halfwt) {90add_p2string(ug, 1, cp, pcp);91continue;92}93}9495/* Step (2) --96combinatorial collection;97move ug past entries in the collected part, adding98commutators directly to the collected part;99if 2 * WT(cg) + WT(ug) > current_class then [cg, ug]100commutes with all generators k such that k >= cg;101scan collected part towards the left, bypassing102generators we know must commute with ug */103104weight_diff = current_class - WT(y[structure + ug]);105firstcg = y[class_end + weight_diff];106lastcg = y[class_end + weight_diff / 2];107108for (cg = firstcg; cg > ug; cg--) {109if (y[cp + cg] != 0) {110/* add [cg, ug] directly to the collected part */111p1 = y[p_pcomm + cg];112p1 = y[p1 + ug];113if (p1 != 0) {114if (cg <= lastcg)115break;116if (p1 < 0)117len = y[-p1 + 1];118add_p2string(p1, len, cp, pcp);119}120}121}122123if (cg == ug) {124/* we have reached the ug position during combinatorial collection;125check whether we can avoid stacking collected part */126if (y[cp + ug] == 0) {127y[cp + ug] = 1;128continue;129} else {130if (y[p_power + ug] == 0) {131y[cp + ug] = 0;132continue;133}134}135}136137/* we do have to stack some of the collected part */138for (i = firstcg; i > cg; i--) {139if (y[cp + i] != 0) {140/* set entry to zero and stack i */141y[cp + i] = 0;142if (++sp >= STACK_SIZE)143stack_overflow();144strstk[sp] = i;145}146}147148/* Step (3) --149ordinary collection; continue scanning towards the left,150stacking up commutators and entries in collected part151until we reach ug position */152153for (; cg > ug; cg--) {154if (y[cp + cg] != 0) {155/* zero the cg entry of collected part */156y[cp + cg] = 0;157/* get [cg, ug] */158p1 = y[p_pcomm + cg];159p1 = y[p1 + ug];160161/* move ug past cg stacking [cg, ug] and cg */162if (sp + 2 >= STACK_SIZE)163stack_overflow();164if (p1 != 0) {165/* stack [cg, ug] if it is non-trivial */166strstk[++sp] = p1;167if (p1 < 0)168lenstk[sp] = y[-p1 + 1];169}170171/* stack cg */172strstk[++sp] = cg;173}174}175176add_p2string(ug, 1, cp, pcp);177continue;178}179}180181/* prime = 2;182add the string with address string and length length183directly to the collected part with base address collected_part,184recursively adding powers as required */185186void187add_p2string(int string, int length, int collected_part, struct pcp_vars *pcp)188{189register int *y = y_address;190191register int cp = collected_part;192register int str = string;193register int len = length;194register int ug;195196register int class_begin = pcp->ccbeg;197register int p_power = pcp->ppower;198199register int i;200int lower, upper;201#include "access.h"202203if (str > 0) {204/* Step (4) --205we have moved generator str to the correct position;206add 1 to the str entry of the collected part; reduce207entry modulo 2 and add str^2 to collected part if necessary */208209if (y[cp + str] == 0)210y[cp + str] = 1;211else {212/* we need to recursively add in str^2 */213y[cp + str] = 0;214if (str < class_begin) {215str = y[p_power + str];216if (str != 0) {217if (str < 0)218len = y[-str + 1];219add_p2string(str, len, cp, pcp);220}221}222}223} else {224/* Step (5) --225add string with base address -str and length len directly226to the collected part; if this creates an entry >= 2, reduce227entry modulo 2 and recursively add in the appropriate power */228229lower = -str + 2;230upper = -str + len + 1;231232/* get one generator exponent pair at a time from string */233234for (i = lower; i <= upper; i++) {235ug = FIELD2(y[i]);236if (y[cp + ug] == 0)237y[cp + ug] = 1;238else {239y[cp + ug] = 0;240if (ug < class_begin) {241/* we need to recursively add in ug^2 */242str = y[p_power + ug];243if (str != 0) {244if (str < 0)245len = y[-str + 1];246add_p2string(str, len, cp, pcp);247}248}249}250}251}252}253254255