boolean kbm_onintr; staticchar gpname[100], /* groupname */
inf[100], /* name of input file - groupname.cosname */
outf[100], /* name of output file for rewriting system
= inf.kbprog */
outfr[100], /* name of output file for rws->reduction_fsa
for rewriting system - inf.reduce */
outf1[100], /* name of output file for first wd-machine
= inf.midiff1 */
outf2[100], /* name of output file for second wd-machine
= inf.midiff2 */
outflog[100]; /* name of logfile for automata run */ static FILE *rfile, *wfile;
/* Functions defined in this file: */ staticvoid badusage(void); staticvoid output_and_exit_kbprogcos(rewriting_system *rwsptr);
/* When the program receives an interrupt signal, it continues until the *nexttidying,andthenstopsandoutputs.
*/ void interrupt_kbprogcos(int sig)
{
kbm_onintr = TRUE;
signal(SIGINT, SIG_DFL);
signal(SIGKILL, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
}
int main(int argc, char *argv[])
{
rewriting_system rws;
rewriting_system *rwsptr; int i, j, k, l;
gen *lhs, *rhs, *w;
boolean ss;
if (rws.resume) { if ((rfile = fopen(outf, "r")) == 0) {
fprintf(stderr, "Error: cannot open file %s\n", outf); exit(1);
}
read_kbinput(rfile, FALSE, rwsptr); /* If we are re-running from previous output, validity checks on input *shouldnotbenecessary.
*/
} else { if ((rfile = fopen(inf, "r")) == 0) {
fprintf(stderr, "Error: cannot open file %s\n", inf); exit(1);
}
read_kbinput(rfile, TRUE, rwsptr);
}
fclose(rfile);
if (rws.resume_with_orig) { if ((rfile = fopen(inf, "r")) == 0) {
fprintf(stderr, "Error: cannot open file %s\n", inf); exit(1);
}
read_extra_kbinput(rfile, FALSE, rwsptr);
fclose(rfile);
}
if (rws.maxlenleft > 0) {
k = rws.maxlenleft > rws.maxlenright ? rws.maxlenleft : rws.maxlenright; if (rws.maxreducelen > MAXREDUCELENFAC * k)
rws.maxreducelen = 50 * k;
}
if (rws.ordering != WREATHPROD) {
fprintf(stderr, "Error - ordering must be WREATHPROD in cosets program.\n"); exit(1);
}
/* Check all initial equations have correct form - either equations in *Ggens,equationsinHgens,orequationsofform_H*Gword=Hword*_H*Gword
*/ if (!rws.resume) for (i = 1; i <= rws.num_eqns; i++) {
lhs = rws.eqns[i].lhs; if (Ggen(*lhs)) { /* Equation should be in Ggens only */ for (j = 1; j < genstrlen(lhs); j++) if (!Ggen(lhs[j])) {
fprintf(stderr, "Error: lhs of equation of incorrect form.\n"); exit(1);
}
rhs = rws.eqns[i].rhs; for (j = 0; j < genstrlen(rhs); j++) if (!Ggen(rhs[j])) {
fprintf(stderr, "Error: rhs of equation of incorrect form.\n"); exit(1);
}
} if (Hgen(*lhs)) { /* Equation should be in Hgens only */ for (j = 1; j < genstrlen(lhs); j++) if (!Hgen(lhs[j])) {
fprintf(stderr, "Error: lhs of equation of incorrect form.\n"); exit(1);
}
rhs = rws.eqns[i].rhs; for (j = 0; j < genstrlen(rhs); j++) if (!Hgen(rhs[j])) {
fprintf(stderr, "Error: rhs of equation of incorrect form.\n"); exit(1);
}
} elseif (*lhs == rws.separator) { /* Equation should be of form _H*Gword = Hword*_H*Gword */ for (j = 1; j < genstrlen(lhs); j++) if (!Ggen(lhs[j])) {
fprintf(stderr, "Error: lhs of equation of incorrect form.\n"); exit(1);
}
rhs = rws.eqns[i].rhs;
ss = FALSE; for (j = 0; j < genstrlen(rhs); j++) if (rhs[j] == rws.separator)
ss = TRUE; elseif ((ss && !Ggen(rhs[j])) || (!ss && !Hgen(rhs[j]))) {
fprintf(stderr, "Error: rhs of equation of incorrect form.\n"); exit(1);
}
}
}
/* find rws.maxlhsrellen and rws.maxsubgenlen */
rws.maxlhsrellen = rws.maxsubgenlen = 0; if (rws.worddiffs) {
tmalloc(rws.subwordsG, gen *, rws.num_gens + 1); for (i = 1; i <= rws.num_gens; i++)
rws.subwordsG[i] = 0;
} for (i = 1; i <= rws.num_eqns; i++) {
lhs = rws.eqns[i].lhs; if (*lhs == rws.separator) { if (genstrlen(lhs + 1) > rws.maxsubgenlen)
rws.maxsubgenlen = genstrlen(lhs + 1); if (rws.worddiffs) { /* See if we have a definition of a subgroup generator - if so, record
* it! */
rhs = rws.eqns[i].rhs; if (rhs[1] == rws.separator) {
j = rhs[0];
tmalloc(rws.subwordsG[j], gen, genstrlen(lhs) + genstrlen(rhs) - 2);
genstrcpy(rws.subwordsG[j], lhs + 1);
l = genstrlen(rhs) - 2; if (l > 0) {
w = rws.subwordsG[j] + genstrlen(rws.subwordsG[j]); for (k = 0; k < l; k++)
w[k] = rws.inv_of[rhs[l + 1 - k]];
w[l] = '\0';
}
}
}
} elseif (Ggen(*lhs) && genstrlen(lhs) > rws.maxlhsrellen)
rws.maxlhsrellen = genstrlen(lhs);
}
if (rws.worddiffs) { if (!rws.confnumset)
rws.confnum *= 8; /* If we are calculating word-differences, we are not interested in *lotsofconfluencetests.
*/ for (i = 1; i <= rws.num_gens; i++) if (i != rws.separator && rws.inv_of[i] == 0) {
fprintf(stderr, "Word-difference calculation requires that all " "generators have inverses.\n"); exit(1);
} if (!rws.Gislevel || !rws.Hislevel) {
fprintf(stderr, "Word-difference calculation requires that all G-generators\n");
fprintf(stderr, "and all H-generators have the same levels.\n"); exit(1);
} for (i = 1; i <= rws.num_gens; i++) if (Hgen(i)) { if (rws.subwordsG[i] == 0) { /* Perhaps its inverse has a definition. */ if ((j = rws.inv_of[i]) && (w = rws.subwordsG[j])) {
l = genstrlen(w);
tmalloc(rws.subwordsG[i], gen, l + 1); for (k = 0; k < l; k++)
rws.subwordsG[i][k] = rws.inv_of[w[l - 1 - k]];
rws.subwordsG[i][l] = '\0';
} else {
fprintf(stderr, "Error: Subgroup generator number %d has no definition.\n",
i); exit(1);
}
}
} /* In the cosets situation, the base-alphabet for the word- *differencemachinescontainsonlytheG-generators,sowe *havetoconstructthisalphabet.
*/
tmalloc(rws.wd_alphabet, srec, 1);
rws.wd_alphabet->type = IDENTIFIERS;
rws.wd_alphabet->size = rws.separator - 1;
tmalloc(rws.wd_alphabet->names, char *, rws.separator); for (i = 1; i < rws.separator; i++) {
tmalloc(rws.wd_alphabet->names[i], char, genstrlen(rws.gen_name[i]) + 1);
strcpy(rws.wd_alphabet->names[i], rws.gen_name[i]);
}
tmalloc(rws.wd_fsa, fsa, 1); if (initialise_wd_fsa_cos(rws.wd_fsa, rws.wd_alphabet, rws.maxwdiffs) == -1) exit(1);
tmalloc(rws.wd_record, struct wdr, MAXCYCLES + 1);
rws.tot_eqns = 0;
}
if (kbprog(rwsptr) == -1) exit(1);
output_and_exit_kbprogcos(rwsptr); return0;
}
staticvoid output_and_exit_kbprogcos(rewriting_system *rwsptr)
{ int i, j, l;
gen **pref, *w; int ndiff1, ndiff2;
reduction_struct rs_rws;
rs_rws.rws = rwsptr;
rs_rws.separator = rwsptr->separator; if (rwsptr->worddiffs) {
rwsptr->new_wd = 0;
build_wd_fsa_cos(rwsptr->wd_fsa, rwsptr->new_wd, &rs_rws);
should_we_halt(rwsptr); /* to calculate factors */
ndiff1 = rwsptr->wd_fsa->states->size;
wfile = fopen(outf1, "w");
print_wdoutput(wfile, ".midiff1", rwsptr);
fclose(wfile); if (make_full_wd_fsa_cos(rwsptr->wd_fsa, rwsptr->inv_of, 1, &rs_rws) == -1) exit(1);
ndiff2 = rwsptr->wd_fsa->states->size;
wfile = fopen(outf2, "w");
print_wdoutput(wfile, ".midiff2", rwsptr);
fclose(wfile);
fsa_clear(rwsptr->wd_fsa);
tfree(rwsptr->wd_fsa); /* Writing info to a log-file - not sure if we want this at present. wfile=fopen(outflog,"w"); fprintf(wfile,"eqn_factor:\t\t%d\n",rwsptr->eqn_factor); fprintf(wfile,"states_factor:\t\t%d\n",rwsptr->states_factor); fprintf(wfile,"diff1:\t\t%d\n",ndiff1); fprintf(wfile,"diff2:\t\t%d\n",ndiff2); fclose(wfile);
*/ if (kbm_print_level > 0) {
printf("#Halting with %d equations.\n", rwsptr->num_eqns);
printf("#First word-difference machine with %d states computed.\n",
ndiff1);
printf("#Second word-difference machine with %d states computed.\n",
ndiff2);
} if (kbm_print_level >= 2) {
printf(" #eqn_factor=%d, states_factor=%d\n", rwsptr->eqn_factor,
rwsptr->states_factor);
} if (rwsptr->exit_status == 0 && kbm_print_level > 0)
printf("#System is confluent, or halting factor condition holds.\n");
tfree(rwsptr->wd_record); if (rwsptr->rk_on)
rk_clear(rwsptr); for (i = 1; i <= rwsptr->num_gens; i++)
tfree(rwsptr->subwordsG[i]);
srec_clear(rwsptr->wd_alphabet);
tfree(rwsptr->wd_alphabet);
tfree(rwsptr->subwordsG);
} else { if (rwsptr->sorteqns)
typelength_sort_eqns(rwsptr->maxoplen, rwsptr); else
type_sort_eqns_final(rwsptr);
make_fsa_nice(rwsptr);
wfile = fopen(outf, "w");
print_kboutput(wfile, rwsptr);
fclose(wfile); /* We complete the definition of the fsa before printing it */
strcat(rwsptr->name, ".reductionFSA");
rwsptr->reduction_fsa->states->size = rwsptr->num_states;
rwsptr->reduction_fsa->num_accepting = rwsptr->num_states; if (rwsptr->num_states == 1) {
tmalloc(rwsptr->reduction_fsa->accepting, int, 2);
rwsptr->reduction_fsa->accepting[1] = 1;
} if (rwsptr->outputprefixes) { /* In this case we want to output the prefixes of the left-hand sides of *equationsassociatedwiththestates.Firstwemustcalculatethem.
*/
rwsptr->reduction_fsa->states->type = WORDS;
rwsptr->reduction_fsa->states->alphabet_size =
rwsptr->reduction_fsa->alphabet->size; for (i = 1; i <= rwsptr->reduction_fsa->alphabet->size; i++) {
tmalloc(rwsptr->reduction_fsa->states->alphabet[i], char,
stringlen(rwsptr->reduction_fsa->alphabet->names[i]) + 1);
strcpy(rwsptr->reduction_fsa->states->alphabet[i],
rwsptr->reduction_fsa->alphabet->names[i]);
}
tmalloc(rwsptr->reduction_fsa->states->words, gen *,
rwsptr->num_states + 1);
pref = rwsptr->reduction_fsa->states->words; for (i = 1; i <= rwsptr->num_states; i++) {
l = rwsptr->preflen[i];
w = rwsptr->eqns[rwsptr->prefno[i]].lhs; /* Copy prefix from w to pref[i] */
tmalloc(pref[i], gen, l + 1); for (j = 0; j < l; j++)
pref[i][j] = w[j];
pref[i][l] = 0;
}
}
wfile = fopen(outfr, "w");
fsa_print(wfile, rwsptr->reduction_fsa, rwsptr->name);
fclose(wfile); if (kbm_print_level > 0)
printf("#Halting with %d equations.\n", rwsptr->num_eqns);
}
rws_clear(rwsptr);
fsa_clear(rwsptr->reduction_fsa);
tfree(rwsptr->reduction_fsa); if (rwsptr->lostinfo && kbm_print_level > 0) {
printf( "WARNING: The monoid defined by the presentation may have changed, since\n\
equations have been discarded.\n\ If you re-run, include the original equations.\n");
} if (kbm_print_level > 1)
printf(" #Exit status is %d\n", rwsptr->exit_status); exit(rwsptr->exit_status);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.