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: 4183461/**************************************************************************23enum01.c4Colin Ramsay ([email protected])518 Oct 0067ADVANCED COSET ENUMERATOR, Version 3.00189Copyright 200010Centre for Discrete Mathematics and Computing,11Department of Mathematics and12Department of Computer Science & Electrical Engineering,13The University of Queensland, QLD 4072.14(http://staff.itee.uq.edu.au/havas)1516This is the code for the al0_rpefn() routine; i.e., R*-style. In concept,17it's closest to C-style; except that the defns are done using relator18application, instead of via fill-factor/next hole. It could also be viewed19as R-style with all dedns stacked & processed. We `borrow' heavily from20the _cdefn()/_rdefn() routines; see the comments therein for a less terse21code run-through. Note that we use the _cdefn()/_rdefn() stats package22variables; since statistics are accumulated on a `per call to _enum()'23basis, there's no possibility of confusion.2425Originally, termination was judged only on knr. However, for a (big)26collapse this required what was effectively an RA phase to count knr up27from the collapse point to nextdf. This is expensive if mendel is on (it's28switched off in a genuine RA phase). Since there is no way in advance of29detecting this state, we elect to keep track of knh (ie, holes) also. We30can terminate on either; the final check phase may invoke either an RA or31an UH phase (or neither), depending on circumstances. Since we have to do32some work anyway to terminate/check the result, this seems to be the33fastest way; the only `unnecessary' work is counting up knh.3435The orignial version of this routine processed deductions on a row by row36basis. The current version processes deductions on a scan by scan basis;37ie, much more frequently. It is closer in spirit to Felsch mode, and tends38to have smaller max/tot statistics (esp. if there are any very long39relators).4041**************************************************************************/4243static int al0_rpefn(int cnt, Logic fill)44{45int icol, rcol, irow, ires, col;46int first, last, i, ii, j, ifront, iback, k, l, m, mi, n;47int *beg, *end, *fwd, *bwd;4849INCR(xrdefn);5051#include "enum02.c" /* `empty' deduction stack */5253/* Count up knh to its `correct' value; its current value may be54redundant and/or we may already have a complete (hole-free) table. Ditto55knr; its current value may be redundant and/or we may already have56scanned all non-redundant cosets. */5758for ( ; knh < nextdf; knh++)59{60if (COL1(knh) >= 0)61{62for (icol = 1; icol <= ncol; icol++)63{64if (CT(knh, icol) == 0)65{ goto hfill1; }66}67}68}69return(nalive);7071hfill1:7273while (knr < nextdf && COL1(knr) < 0)74{ knr++; }75if (knr == nextdf)76{ return(nalive); }7778/* The main loop. Provided cnt is non-zero, each pass through this scans79and closes one row. */8081while (cnt != 0)82{83/* Scan through all relators for this coset. The code here is84essentially the same as that in al0_apply. We inline for speed (and85flexibility; the code's not _exactly_ the same). */8687for (ii = 1; ii <= ndrel; ii++)88{89j = (mendel ? rellen[ii]/relexp[ii] : 1);90for (k = 0; k < j; k++)91{9293/* <-- cancel indent */9495/* Setup start & stop positions for scan, and the coset at the current96scan positions. */9798beg = &(relators[relind[ii]+k]);99end = beg-1 + rellen[ii];100ifront = iback = knr;101102/* Forward scan, leaving ifront set to coset at left of leftmost hole in103relator or to the last coset in the relator if no hole. */104105for (fwd = beg; fwd <= end; fwd++)106{107if ((l = CT(ifront, *fwd)) > 0)108{ ifront = l; }109else110{ break; }111}112113/* If the scan completed, then l = ifront & iback = cos, and we'll fall114right through and check for a coincidence (i.e., has ifront cycled back115to cos or not?). Else, there's a hole & a backward scan is required. */116117if (l == 0)118{119for (bwd = end; bwd >= fwd; bwd--)120{121m = *bwd;122mi = invcol[m];123124if ((l = CT(iback, mi)) > 0)125{ iback = l; }126else /* Scan stalled */127{128if (bwd == fwd)129{130/* The backward scan has only one gap, so note the deduction to131complete the cycle & prime for coincidence check. */132133CT(iback, mi) = ifront;134SAVED(iback, mi);135136if (CT(ifront, m) > 0)137{ ifront = CT(ifront, m); }138else139{140CT(ifront, m) = iback;141ifront = iback;142}143144INCR(rddedn);145}146else /* Need to define a new coset */147{148/* Note that, if m is an involution, and occurs next to itself,149then after the first defn, the remainder of the string of m's150will close. Note that if m^2 = 1 & m is _not_ being treated as151an involution, then `removing' it is a Tietze transformation, not152a free reduction! */153154if (nextdf > maxrow) /* Overflow */155{ return(0); }156157NEXTC(n); /* Making a definition ... */158159CT(iback,mi) = n;160CT(n,m) = iback;161SAVED(iback,mi);162163iback = n; /* Advance to next spot */164165INCR(rddefn);166167if (msgctrl && --msgnext == 0)168{169msgnext = msgincr;170ETINT;171fprintf(fop, "RD: a=%d r=%d h=%d n=%d;",172nalive, knr, knh, nextdf);173MSGMID;174fprintf(fop, " m=%d t=%d\n", maxcos, totcos);175BTINT;176}177}178}179}180}181182/* If we get here, the scan has been completed. Check to see if we've183found a pair of coincident cosets. Recall that _coinc (if it does not184return >0) is guaranteed _not_ to change knc/knh, although it may render185them redundant. */186187if (ifront != iback)188{189INCR(rdcoinc);190if ((l = al0_coinc(ifront,iback,TRUE)) > 0)191{ return(l); }192if (COL1(knr) < 0)193{ goto do_next; } /* knr now redundant */194}195196/* --> restore indent */197198#include "enum02.c" /* `empty' deduction stack */199200if (COL1(knr) < 0)201{ goto do_next; } /* knr now redundant */202}203}204205/* All relators close at this coset, any row-filling to do? Only206(formally) necessary if some g/G does _not_ appear in any relator,207but it's usually a good thing to do. Also, don't bother if the row208is guaranteed hole-free. */209210if (fill && knr >= knh)211{212for (i = 1; i <= ncol; i++)213{214if (CT(knr,i) == 0)215{216if (nextdf > maxrow) /* Overflow */217{ return(0); }218219NEXTC(k); /* Make definition */220CT(knr,i) = k;221CT(k,invcol[i]) = knr;222SAVED(knr,i);223224INCR(rdfill);225226if (msgctrl && --msgnext == 0)227{228msgnext = msgincr;229ETINT;230fprintf(fop, "RF: a=%d r=%d h=%d n=%d;",231nalive, knr, knh, nextdf);232MSGMID;233fprintf(fop, " m=%d t=%d\n", maxcos, totcos);234BTINT;235}236}237}238#include "enum02.c" /* `empty' deduction stack */239}240241/* Row knr is fully scanned (or redundant), so we adjust knr up,242jumping over any redundancies & checking to see if we've finished. We243have also used up one of our allowed rows, if there's a limit. We also244check to see if the table if complete. */245246do_next: /* from al0_coinc() or dedn processing: knr redundant */247248do249{ knr++; }250while (knr < nextdf && COL1(knr) < 0);251252if (knr == nextdf)253{ return(nalive); }254255if (cnt > 0)256{ cnt--; }257258for ( ; knh < nextdf; knh++)259{260if (COL1(knh) >= 0)261{262for (icol = 1; icol <= ncol; icol++)263{264if (CT(knh, icol) == 0)265{ goto hfill2; }266}267}268}269return(nalive);270271hfill2:272;273} /* end of "while(cnt!=0)" */274275return(-1); /* `normal' return */276}277278279280