Goto Chapter: Top 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 Bib Ind

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\) cannot be rewritten using any rule of the rewriting system we sat that \(u\) is *reduced*.

`‣ IsRewritingSystem` ( obj ) | ( category ) |

This is the category in which all rewriting systems lie.

`‣ Rules` ( rws ) | ( attribute ) |

The rules comprising the rewriting system. Note that these may change through the life of the rewriting system, however they will always be a set of defining relations of the algebra described by the rewriting system.

`‣ OrderOfRewritingSystem` ( rws ) | ( attribute ) |

`‣ OrderingOfRewritingSystem` ( rws ) | ( attribute ) |

return the ordering of the rewriting system `rws`.

`‣ ReducedForm` ( rws, u ) | ( operation ) |

Given an element `u` in the free (or term) algebra \(T\) over which `rws` is defined, rewrite `u` by successive applications of the rules of `rws` until no further rewriting is possible, and return the resulting element of \(T\).

`‣ IsConfluent` ( rws ) | ( property ) |

`‣ IsConfluent` ( A ) | ( property ) |

For a rewriting system `rws`, `IsConfluent`

returns `true`

if and only if `rws` is confluent. A rewriting system is *confluent* if, for every two words \(u\) and \(v\) in the free algebra \(T\) which represent the same element of the algebra \(A\) defined by `rws`, `ReducedForm( `

\(u\) `rws`, `) = ReducedForm( `

\(v\)`rws`, `)`

as words in the free algebra \(T\). This element is the *unique normal form* of the element represented by \(u\).

For an algebra `A` with a canonical rewriting system associated with it, `IsConfluent`

checks whether that rewriting system is confluent.

Also seeĀ `IsConfluent`

(46.4-7).

`‣ ConfluentRws` ( rws ) | ( attribute ) |

Return a new rewriting system defining the same algebra as `rws` which is confluent.

`‣ IsReduced` ( rws ) | ( property ) |

A rewriting system is reduced if for each rule \((l, r)\), \(l\) and \(r\) are both reduced.

`‣ ReduceRules` ( rws ) | ( operation ) |

Reduce rules and remove redundant rules to make `rws` reduced.

`‣ AddRule` ( rws, rule ) | ( operation ) |

Add `rule` to a rewriting system `rws`.

`‣ AddRuleReduced` ( rws, rule ) | ( operation ) |

Add `rule` to rewriting system `rws`. Performs a reduction operation on the resulting system, so that if `rws` is reduced it will remain reduced.

`‣ MakeConfluent` ( rws ) | ( operation ) |

Add rules (and perhaps reduce) in order to make `rws` confluent

`‣ GeneratorsOfRws` ( rws ) | ( attribute ) |

Returns the list of generators of the rewriting system `rws`.

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

`‣ ReducedProduct` ( rws, u, v ) | ( operation ) |

`‣ ReducedSum` ( rws, left, right ) | ( operation ) |

`‣ ReducedOne` ( rws ) | ( operation ) |

`‣ ReducedAdditiveInverse` ( rws, obj ) | ( operation ) |

`‣ ReducedComm` ( rws, left, right ) | ( operation ) |

`‣ ReducedConjugate` ( rws, left, right ) | ( operation ) |

`‣ ReducedDifference` ( rws, left, right ) | ( operation ) |

`‣ ReducedInverse` ( rws, obj ) | ( operation ) |

`‣ ReducedLeftQuotient` ( rws, left, right ) | ( operation ) |

`‣ ReducedPower` ( rws, obj, pow ) | ( operation ) |

`‣ ReducedQuotient` ( rws, left, right ) | ( operation ) |

`‣ ReducedScalarProduct` ( rws, left, right ) | ( operation ) |

`‣ ReducedZero` ( rws ) | ( operation ) |

The result of `ReducedProduct`

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).

`‣ IsBuiltFromAdditiveMagmaWithInverses` ( obj ) | ( property ) |

`‣ IsBuiltFromMagma` ( obj ) | ( property ) |

`‣ IsBuiltFromMagmaWithOne` ( obj ) | ( property ) |

`‣ IsBuiltFromMagmaWithInverses` ( obj ) | ( property ) |

`‣ IsBuiltFromSemigroup` ( obj ) | ( property ) |

`‣ IsBuiltFromGroup` ( obj ) | ( property ) |

These properties may be used to identify the type of term algebra over which the rewriting system is defined.

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 `KB_REW`

(52.5-2) to `KBMAG_REW`

. Assignment to `GAPKB_REW`

reverts to the built-in implementation.

gap> LoadPackage("kbmag"); true gap> KB_REW:=KBMAG_REW;;

The key point to note about rewriting systems is that they have properties such as `IsConfluent`

(38.1-5) and attributes such as `Rules`

(38.1-2), however they are rarely stored, but rather computed afresh each time they are asked for, from data stored in the private members of the rewriting system object. This is because a rewriting system often evolves through a session, starting with some rules which define the algebra `A` as relations, and then adding more rules to make the system confluent. For example, in the case of Knuth-Bendix rewriting systems (see ChapterĀ 52), the function `CreateKnuthBendixRewritingSystem`

creating the rewriting system (in the file `lib/kbsemi.gi`

) uses

kbrws := Objectify(NewType(rwsfam, IsMutable and IsKnuthBendixRewritingSystem and IsKnuthBendixRewritingSystemRep), rec(family:= fam, reduced:=false, tzrules:=List(relwco,i-> [LetterRepAssocWord(i[1]),LetterRepAssocWord(i[2])]), pairs2check:=CantorList(Length(r)), ordering:=wordord, freefam:=freefam));

In particular, since we don't use the filter `IsAttributeStoringRep`

in the `Objectify`

(79.1-1), whenever `IsConfluent`

(38.1-5) is called, the appropriate method to determine confluence is called.

Goto Chapter: Top 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 Bib Ind

generated by GAPDoc2HTML