/* Reduce "w", by replacing any occurrences of the LHS of the current *equationsintherewritingsystembytheirRHS. *Thereductionfsafortherewritingsystemrwsisusedforthis,anditis *assumedtobestoredindenseformat.Thecompletesequenceof *statesthatitgoesthroughonreading"w"isrememberedinthearray *"rws.history".
*/ int rws_reduce(gen *w, reduction_struct *rs_rws)
{ int len, st, **table, longer, *history;
gen *midwd, *ptr1, *ptr2, *ptr;
rewriting_system *rwsptr = rs_rws->rws;
reduction_equation *eqn;
history = rwsptr->history;
table = rwsptr->reduction_fsa->table->table_data_ptr;
midwd = w;
len = 0;
history[0] = 1;
st = 1; while (*midwd != 0) {
st = history[++len] = dense_target(table, *midwd, st); if (st == 0) {
fprintf(stderr, "#The word for reduction is invalid.\n"); return -1;
} if (st < 0) /* st= -n means that we have just read the LHS or *relationn.ReplaceitbyRHS,andgobacktothe
* beginning of that subword. */
{
st = -st;
eqn = &(rwsptr->eqns[st]);
ptr1 = midwd;
ptr2 = eqn->rhs - 1; if ((longer = genstrlen(eqn->rhs) - genstrlen(eqn->lhs)) > 0) { if (genstrlen(w) + longer >= rwsptr->maxreducelen) {
fprintf(stderr, "#Error: word too long in reduction - try increasing " "maxreducelen.\n"); return -1;
}
ptr = w + genstrlen(w); while (ptr > midwd) {
*(ptr + longer) = *ptr;
ptr--;
}
ptr1 += longer; if (genstrlen(w) > rwsptr->maxreducelen / 2) return0; /* To save time when length is getting out of control */
}
len -= genstrlen(eqn->lhs);
midwd = w + len - 1;
ptr = midwd; while (*(++ptr2) != 0)
*(++ptr) = *ptr2; if (ptr != ptr1) { while (*(++ptr1) != 0)
*(++ptr) = *ptr1;
*(++ptr) = 0;
}
st = history[len]; /* midwd--;*/
}
midwd++;
} return0;
}
/* The version of reduce for the reduction automaton that recognises *lefthandsidesofrelationsonly. *Thisisbothslower,andneedsmorespace,sincethehistoryhasto *bestoredasalistofsubsetsofthestates,ratherthanalistofstates. *Thesubsetsarestoredcontiguouslyinthearrayrws.slowhistorysp,and *pointedatbyrws.slowhistory.
*/ int slow_rws_reduce(gen *w, reduction_struct *rs_rws)
{ int len, st, **table, *histptr, *histptre, *nextptr, subrelno, longer,
*slowhistorysp, **slowhistory;
gen *midwd, *ptr1, *ptr2, *ptr;
rewriting_system *rwsptr = rs_rws->rws;
reduction_equation *eqn;
slowhistorysp = rwsptr->slowhistorysp, slowhistory = rwsptr->slowhistory;
restart:
midwd = w;
len = 0;
table = rwsptr->reduction_fsa->table->table_data_ptr;
nextptr = slowhistory[0] = slowhistorysp; while (*midwd != 0) {
subrelno = 0;
histptr = slowhistory[len++];
slowhistory[len] = histptre = nextptr; if (nextptr + len - slowhistorysp > rwsptr->maxslowhistoryspace) { if (kbm_print_level >= 3)
printf(" #maxslowhistoryspace too small; doubling it.\n");
tfree(rwsptr->slowhistorysp);
rwsptr->maxslowhistoryspace *= 2;
tmalloc(rwsptr->slowhistorysp, int, rwsptr->maxslowhistoryspace);
slowhistorysp = rwsptr->slowhistorysp; goto restart;
} /* First adjoin image of start state */
st = dense_target(table, *midwd, 1); if (st < 0)
subrelno = -st; else { if (st > 0)
*(nextptr++) = st; while (histptr < histptre) {
st = dense_target(table, *midwd, *(histptr++)); if (st > 0)
*(nextptr++) = st; elseif (st < 0) {
subrelno = -st; break;
}
}
} if (subrelno > 0) { /* subrelno=n means that we have just read the LHS of *relationn.ReplaceitbyRHS,andgobacktothe *beginningofthatsubword.
*/
eqn = &(rwsptr->eqns[subrelno]);
ptr1 = midwd;
ptr2 = eqn->rhs - 1; if ((longer = (genstrlen(eqn->rhs) - genstrlen(eqn->lhs))) > 0) { if (genstrlen(w) + longer >= rwsptr->maxreducelen) {
fprintf(stderr, "#Error: word too long in reduction - try increasing " "maxreducelen.\n"); return -1;
}
ptr = w + genstrlen(w); while (ptr > midwd) {
*(ptr + longer) = *ptr;
ptr--;
}
ptr1 += longer; if (genstrlen(w) > rwsptr->maxreducelen / 2) return -1; /* To save time when length is getting out of control */
}
len -= genstrlen(eqn->lhs);
midwd = w + len - 1;
ptr = midwd; while (*(++ptr2) != 0)
*(++ptr) = *ptr2; if (ptr != ptr1) { while (*(++ptr1) != 0)
*(++ptr) = *ptr1;
*(++ptr) = 0;
}
histptr = slowhistory[len];
nextptr = slowhistory[len + 1];
}
midwd++;
} return0;
}
/* This is similar to slow_rws_reduce, but it does not change the word w. *Itmerelycheckswhetheritisreducedornot,andreturnstrueorfalse. *Ifthesecondparameteriisgreaterthan0,thenthecheckisfor *reducibilityignoringequationnumberi.(Usuallythisisusedontheleft- *hand-sideofequationiitself.
*/
boolean slow_check_rws_reduce(gen *w, int i, rewriting_system *rwsptr)
{ int st, **table, *histptr, *histptre, *nextptr,
*slowhistorysp = rwsptr->slowhistorysp,
**slowhistory = rwsptr->slowhistory;
gen *wc = w;
restart:
table = rwsptr->reduction_fsa->table->table_data_ptr;
histptr = nextptr = slowhistory[0] = slowhistorysp; while (*wc != 0) {
histptre = nextptr; if (nextptr + (wc - w) - slowhistorysp > rwsptr->maxslowhistoryspace) { if (kbm_print_level >= 3)
printf(" #maxslowhistoryspace too small doubling it.\n");
tfree(rwsptr->slowhistorysp);
rwsptr->maxslowhistoryspace *= 2;
tmalloc(rwsptr->slowhistorysp, int, rwsptr->maxslowhistoryspace);
slowhistorysp = rwsptr->slowhistorysp; goto restart;
} while (histptr < histptre) {
st = dense_target(table, *wc, *(histptr++)); if (st > 0)
*(nextptr++) = st; elseif (st < 0 && st != -i) returnFALSE;
}
st = dense_target(table, *wc, 1); if (st > 0)
*(nextptr++) = st; elseif (st < 0 && st != -i) returnFALSE;
wc++;
} returnTRUE;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-06-17)
¤
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.