Rewriting Systems

Rewriting systems in &GAP; are a framework for dealing with the very general task of rewriting elements of a free (or term) algebra in some normal form. Although most rewriting systems currently in use are string rewriting systems (where the algebra has only one binary operation which is associative) the framework in &GAP; is general enough to encompass the task of rewriting algebras of any signature from groups to semirings.

Rewriting systems are already implemented in &GAP; for finitely presented semigroups and for pc groups. The use of these particular rewriting systems is described in the corresponding chapters. We describe here only the general framework of rewriting systems with a particular emphasis on material which would be helpful for a developer implementing a rewriting system.

We fix some definitions and terminology for the rest of this chapter. Let T be a term algebra in some signature. A term rewriting system for T is a set of ordered pairs of elements of T of the form (l, r). Viewed as a set of relations, the rewriting system determines a presentation for a quotient algebra A of T.

When we take into account the fact that the relations are expressed as ordered pairs, we have a way of reducing the elements of T. Suppose an element u of T has a subword l and (l, r) is a rule of the rewriting system, then we can replace the subterm l of u by the term r and obtain a new word v. We say that we have rewritten u as v. Note that u and v represent the same element of A. If u can not be rewritten using any rule of the rewriting system we sat that u is reduced.

Operations on rewriting systems
<#Include Label="IsRewritingSystem"> <#Include Label="Rules"> <#Include Label="OrderOfRewritingSystem"> <#Include Label="ReducedForm"> <#Include Label="IsConfluent"> <#Include Label="ConfluentRws"> <#Include Label="IsReduced"> <#Include Label="ReduceRules"> <#Include Label="AddRule"> <#Include Label="AddRuleReduced"> <#Include Label="MakeConfluent"> <#Include Label="GeneratorsOfRws">

Operations on elements of the algebra

In this section let u denote an element of the term algebra T representing [u] in the quotient algebra A.

The result of is w where [w] equals [u][v] in A and w is in reduced form.

The remaining operations are defined similarly when they are defined (as determined by the signature of the term algebra).
Properties of rewriting systems
These properties may be used to identify the type of term algebra over which the rewriting system is defined.
Rewriting in Groups and Monoids

One application of rewriting is to reduce words in finitely presented groups and monoids. The rewriting system still has to be built for a finitely presented monoid (using IsomorphismFpMonoid for conversion). Rewriting then can take place for words in the underlying free monoid. (These can be obtained from monoid elements with the command UnderlyingElement.)

gap> f:=FreeGroup(3);; gap> rels:=[f.1*f.2^2/f.3,f.2*f.3^2/f.1,f.3*f.1^2/f.2];; gap> g:=f/rels; <fp group on the generators [ f1, f2, f3 ]> gap> mhom:=IsomorphismFpMonoid(g); MappingByFunction( <fp group on the generators [ f1, f2, f3 ]>, <fp monoid on the generators [ f1, f1^-1, f2, f2^-1, f3, f3^-1 ]>, function( x ) ... end, function( x ) ... end ) gap> mon:=Image(mhom); <fp monoid on the generators [ f1, f1^-1, f2, f2^-1, f3, f3^-1 ]> gap> k:=KnuthBendixRewritingSystem(mon); Knuth Bendix Rewriting System for Monoid( [ f1, f1^-1, f2, f2^-1, f3, f3^-1 ] ) with rules [ [ f1*f1^-1, <identity ...> ], [ f1^-1*f1, <identity ...> ], [ f2*f2^-1, <identity ...> ], [ f2^-1*f2, <identity ...> ], [ f3*f3^-1, <identity ...> ], [ f3^-1*f3, <identity ...> ], [ f1*f2^2*f3^-1, <identity ...> ], [ f2*f3^2*f1^-1, <identity ...> ] , [ f3*f1^2*f2^-1, <identity ...> ] ] gap> MakeConfluent(k); gap> a:=Product(GeneratorsOfMonoid(mon)); f1*f1^-1*f2*f2^-1*f3*f3^-1 gap> ReducedForm(k,UnderlyingElement(a)); <identity ...>

To rewrite a word in the finitely presented group, one has to convert it to a word in the monoid first, rewrite in the underlying free monoid and convert back (by forming first again an element of the fp monoid) to the finitely presented group.

gap> r:=PseudoRandom(g);; gap> Length(r); 3704 gap> melm:=Image(mhom,r);; gap> red:=ReducedForm(k,UnderlyingElement(melm)); f1^-1^3*f2^-1*f1^2 gap> melm:=ElementOfFpMonoid(FamilyObj(One(mon)),red); f1^-1^3*f2^-1*f1^2 gap> gpelm:=PreImagesRepresentative(mhom,melm); f1^-3*f2^-1*f1^2 gap> r=gpelm; true gap> CategoriesOfObject(red); [ "IsExtLElement", "IsExtRElement", "IsMultiplicativeElement", "IsMultiplicativeElementWithOne", "IsAssociativeElement", "IsWord" ] gap> CategoriesOfObject(melm); [ "IsExtLElement", "IsExtRElement", "IsMultiplicativeElement", "IsMultiplicativeElementWithOne", "IsAssociativeElement", "IsElementOfFpMonoid" ] gap> CategoriesOfObject(gpelm); [ "IsExtLElement", "IsExtRElement", "IsMultiplicativeElement", "IsMultiplicativeElementWithOne", "IsMultiplicativeElementWithInverse", "IsAssociativeElement", "IsElementOfFpGroup" ]

Note, that the elements red (free monoid) melm (fp monoid) and gpelm (group) differ, though they are displayed identically.

Under Unix, it is possible to use the `kbmag` package to replace the built-in rewriting by this packages efficient C implementation. You can do this (after loading the `kbmag` package) by assigning the variable to KBMAG_REW. Assignment to GAPKB_REW reverts to the built-in implementation. gap> LoadPackage("kbmag"); true gap> KB_REW:=KBMAG_REW;;

Developing rewriting systems
<#Include Label="[2]{rws}">