Skip to content

Commit

Permalink
ENHANCE: Use DAG structure for rewriting
Browse files Browse the repository at this point in the history
Utility functions/data structure for finding rewriting rule that would apply
to word at give position. This is faster (and cleaner) than the
caching/sorting kludges used before.

If code manipulates the `tzrules` entry (as the `fr` package does), the
functionality is disabled.
  • Loading branch information
hulpke committed Feb 9, 2022
1 parent 80374b1 commit 65ca9e6
Show file tree
Hide file tree
Showing 4 changed files with 265 additions and 143 deletions.
1 change: 1 addition & 0 deletions lib/gpfpiso.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1904,6 +1904,7 @@ local isob,isos,iso,gens,u,a,rels,l,i,j,bgens,cb,cs,b,f,k,w,monoid,
rels:=[];
mytzf:=maketzf(rels);

directerr:=false;
if newstyle then directerr:=true;fi;

addrule:=function(rule)
Expand Down
34 changes: 34 additions & 0 deletions lib/kbsemi.gd
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,37 @@ DeclareGlobalFunction("ReduceWordUsingRewritingSystem");
## </ManSection>
##
DeclareAttribute( "TzRules", IsKnuthBendixRewritingSystem );

# utility functions for identifying applicable rules through a DAG
############################################################################
##
#F EmptyKBDAG(<genids>)
##
## takes a list of generator id's (signed integers, used to check how far
## indices have to be shifted) and returns a record that represents such
## a DAG.
DeclareGlobalFunction("EmptyKBDAG");

############################################################################
##
#F AddRuleKBDAG(<dag>,<left>,<index>)
##
## Adds rule with given left side to the DAG at given index position
DeclareGlobalFunction("AddRuleKBDAG");

############################################################################
##
#F DeleteRuleKBDAG(<dag>,<left>,<index>)
##
## removes a rule with given left side (sgtored at position <index> from the
## DAG. Index numbers of all rules with higher index number will be shifted
## one down.
DeclareGlobalFunction("DeleteRuleKBDAG");

############################################################################
##
#F RuleAtPosKBDAG(<dag>,<w>,<p>)
##
## returns the index position of the rule that applies at position <p> in
## word <w> (or `fail` if no rule applies.
DeclareGlobalFunction("RuleAtPosKBDAG");
Loading

0 comments on commit 65ca9e6

Please sign in to comment.