staticvoid badusage(void); int (*reduce_word)(gen *w, reduction_struct *rs_rws);
int main(int argc, char *argv[])
{ int arg, i, ct, *inv, old_ndiff, maxneweqns, numeqns, ngens, maxwdiffs;
fsa diff2, genmult; char gpname[100], cosgpname[100], inf1[100], inf2[100], inf3[100], outf[100],
outfwg[100], outfec[100], fsaname[100];
fsa *wd_fsa; /* This is for doing word-reductions in the case that we *correctthediff2machine
*/
fsa wa; /* The word-acceptor in the wtlex case */ int weight[MAXGEN + 1]; /* The weights of the generators in the wtlex case */
gen testword[MAXREDUCELEN]; /* for word reduction */ char **names; /* generator names in case we need to output words */
reduction_equation *eqnptr;
reduction_struct rs_wd;
storage_type ip_store = DENSE; int dr = 0;
boolean seengpname, seencosname;
boolean cosets = FALSE;
boolean wtlex = FALSE;
rewriting_system rws;
boolean outputwords = FALSE; int separator = 0;
tmalloc(eqnptr, reduction_equation, maxneweqns) if (cosets) separator =
rs_wd.separator = genmult.alphabet->base->size + 1; if ((numeqns = fsa_checkmult(&genmult, eqnptr, maxneweqns, cosets,
separator)) > 0) { /* A multiplier was not valid, so groupname.(mi)diff2 will need updating. */
if (outputwords) { /* We do not update gpname.diff2, but output the offending words. */ if (cosets)
strcpy(outfwg, cosgpname); else
strcpy(outfwg, gpname);
strcat(outfwg, ".wg");
wfile = fopen(outfwg, "w");
base_prefix(fsaname);
fprintf(wfile, "%s.wg := [\n", fsaname);
names = genmult.alphabet->base->names; for (i = 0; i < numeqns; i++) {
strcpy(kbm_buffer, " ["); if (cosets)
add_word_to_buffer(wfile, eqnptr[i].lhs + 1, names); else
add_word_to_buffer(wfile, eqnptr[i].lhs, names);
strcat(kbm_buffer, ",");
add_word_to_buffer(wfile, eqnptr[i].rhs, names); if (i < numeqns - 1)
strcat(kbm_buffer, "],"); else
strcat(kbm_buffer, "]");
fprintf(wfile, "%s\n", kbm_buffer);
}
fprintf(wfile, "];\n");
fclose(wfile);
fsa_clear(&genmult); for (i = 0; i < numeqns; i++) {
tfree(eqnptr[i].lhs);
tfree(eqnptr[i].rhs);
}
tfree(eqnptr);
wfile = fopen(outfec, "w");
fprintf(wfile, "_ExitCode := 2;\n");
fclose(wfile); exit(2);
}
fsa_clear(&genmult); if (cosets)
strcat(inf2, ".midiff2"); else
strcat(inf2, ".diff2");
strcpy(outf, inf2); if (kbm_print_level > 1)
printf(" #Altering wd-machine to make it accept new equations.\n"); if ((rfile = fopen(inf2, "r")) == 0) {
fprintf(stderr, "Cannot open file %s.\n", inf2); exit(1);
} /* We read groupname.(mi)diff2 into diff2, and then copy it into *wd_fsa.Thecopyisusedforreducingwords-Notsurprisingly, *wegetproblemsifwetrytoalteritwhileusingitat *thesametime!
*/
fsa_read(rfile, &diff2, DENSE, 0, maxwdiffs, TRUE, fsaname);
fclose(rfile);
tmalloc(wd_fsa, fsa, 1);
fsa_copy(wd_fsa, &diff2); if (wtlex) { /* we have to read in the weights from the group file */ if ((rfile = fopen(gpname, "r")) == 0) {
fprintf(stderr, "Cannot open file %s.\n", gpname); exit(1);
}
read_kbinput_simple(rfile, TRUE, &rws);
fclose(rfile); /* we only need the weights, which we can simply copy */ for (i = 1; i <= rws.num_gens; i++)
weight[i] = rws.weight[i];
weight[rws.num_gens + 1] = 0; /* padding symbol */
rws_clear(&rws);
strcpy(inf3, gpname);
strcat(inf3, ".wa"); if ((rfile = fopen(inf3, "r")) == 0) {
fprintf(stderr, "Cannot open file %s.\n", inf3); exit(1);
}
fsa_read(rfile, &wa, DENSE, 0, 0, TRUE, fsaname);
fclose(rfile);
}
rs_wd.wd_fsa = wd_fsa;
reduce_word =
cosets ? diff_reduce_cos : wtlex ? diff_reduce_wl : diff_reduce; if (fsa_table_dptr_init(wd_fsa) == -1) return -1; if (fsa_table_dptr_init(&diff2) == -1) return -1; if (cosets) {
tmalloc(diff2.is_initial, boolean, maxwdiffs + 1); for (i = 1; i <= maxwdiffs; i++)
diff2.is_initial[i] = FALSE; for (i = 1; i <= diff2.num_initial; i++)
diff2.is_initial[diff2.initial[i]] = TRUE;
} elseif (wtlex) {
rs_wd.wa = &wa;
rs_wd.weight = weight;
rs_wd.maxreducelen = MAXREDUCELEN;
} /* We need to know the inverses of generators - let's just work them out! */
ngens = diff2.alphabet->base->size; if (calculate_inverses(&inv, ngens, &rs_wd) == -1) return -1;
old_ndiff = diff2.states->size;
/* Now add the new equations *Therighthandsideoftheequationtobeaddedwillbethereductionof *thelhstimesthegeneratorwhichiscurrentlyintherhs.
*/ for (i = 0; i < numeqns; i++) {
genstrcat(eqnptr[i].lhs, eqnptr[i].rhs);
tfree(eqnptr[i].rhs);
genstrcpy(testword, eqnptr[i].lhs);
reduce_word(testword, &rs_wd);
tmalloc(eqnptr[i].rhs, gen, genstrlen(testword) + 1);
genstrcpy(eqnptr[i].rhs, testword); if (cosets) { if (add_wd_fsa_cos(&diff2, eqnptr + i, inv, TRUE, &rs_wd) == -1) exit(1);
} elseif (add_wd_fsa(&diff2, eqnptr + i, inv, TRUE, &rs_wd) == -1) exit(1);
}
if (cosets) {
tfree(diff2.initial);
tmalloc(diff2.initial, int, diff2.num_initial + 1);
ct = 0; for (i = 1; i <= diff2.states->size; i++) if (diff2.is_initial[i])
diff2.initial[++ct] = i;
tfree(diff2.is_initial);
make_full_wd_fsa_cos(&diff2, inv, old_ndiff + 1, &rs_wd);
} else
make_full_wd_fsa(&diff2, inv, old_ndiff + 1, &rs_wd); if (kbm_print_level > 1)
printf(" #Word-difference machine now has %d states.\n",
diff2.states->size);
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.