boolean kbm_onintr; /* set true on interrupt signal */ staticchar inf[100], /* name of input file */
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.diff1 */
outf2[100], /* name of output file for second wd-machine
= inf.diff2 */
outfec[100], /* name of output file for GAP exit code
= inf.kbprog.ec */
outflog[100]; /* name of logfile for automata run */ static FILE *rfile, *wfile;
/* Functions defined in this file: */ staticvoid badusage(void); staticvoid output_and_exit_kbprog(rewriting_system *rwsptr);
/* When the program receives an interrupt signal, it continues until the *nexttidying,andthenstopsandoutputs.
*/ void interrupt_kbprog(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, k;
/* First set some default values of the rewriting-system fields. They may be *overriddenbycommand-lineorinputinfile.
*/
rwsptr = &rws;
set_defaults(rwsptr, FALSE);
read_kbprog_command(argc, argv, rwsptr);
rws.print_eqns = kbm_print_level > 2 && kbm_print_level % 5 == 0;
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.worddiffs) { /* if(rws.ordering!=SHORTLEX){ fprintf(stderr, "Word-differencecalculationonlymakessensefortheshortlex ordering.\n");exit(1); }
*/ 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 (rws.inv_of[i] == 0) {
fprintf(stderr, "Word-difference calculation requires that all " "generators have inverses.\n"); exit(1);
}
tmalloc(rws.wd_fsa, fsa, 1); if (initialise_wd_fsa(rws.wd_fsa, rws.reduction_fsa->alphabet,
rws.maxwdiffs) == -1) exit(1);
tmalloc(rws.wd_record, struct wdr, MAXCYCLES + 1);
rws.hadct = 0;
rws.tot_eqns = 0;
}
if (kbprog(rwsptr) == -1) exit(1);
output_and_exit_kbprog(rwsptr); return0;
}
staticvoid output_and_exit_kbprog(rewriting_system *rwsptr)
{ int i, j, l;
gen **pref, *w; int ndiff1, ndiff2;
reduction_struct rs_rws;
rs_rws.rws = rwsptr; if (rwsptr->exit_status == 1) exit(rwsptr->exit_status); if (rwsptr->worddiffs) {
rwsptr->new_wd = 0;
build_wd_fsa(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, ".diff1", rwsptr);
fclose(wfile); if (make_full_wd_fsa(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, ".diff2", rwsptr);
fclose(wfile);
fsa_clear(rwsptr->wd_fsa);
tfree(rwsptr->wd_fsa); 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);
} else { if (rwsptr->sorteqns)
sort_eqns(rwsptr->maxoplen, 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);
wfile = fopen(outfec, "w");
fprintf(wfile, "_ExitCode := %d;\n", rwsptr->exit_status);
fclose(wfile); 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.