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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
|
% This file was created automatically from rws.msk.
% DO NOT EDIT!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%A rws.msk GAP documentation Andrew Solomon
%%
%A @(#)$Id: rws.msk,v 1.11 2003/07/31 20:04:19 gap Exp $
%%
%Y (C) 1999 School Math and Comp. Sci., University of St. Andrews, Scotland
%Y Copyright (C) 2002 The GAP Group
%%
\Chapter{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*.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Operations on rewriting systems}
\>IsRewritingSystem( <obj> ) C
This is the category in which all rewriting systems lie.
\>Rules( <rws> ) A
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> ) A
\>OrderingOfRewritingSystem( <rws> ) A
return the ordering of the rewriting system <rws>.
%the synonym here guarantees compatibility with {\GAP}~4.1 and {\GAP}~4.2.
\>ReducedForm( <rws>, <u> ) O
Given an element <u> in the free (or term) algebra 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> ) P
\>IsConfluent( <A> ) P
return `true' if and only if the rewriting system <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(<rws>,<u>) = ReducedForm(<rws>,<v>)' as words in the
free algebra <T>. This element is the *unique normal form*
of the element represented by <u>.
In its second
form, if <A> is an algebra with a canonical rewriting system associated
with it, `IsConfluent' checks whether that rewriting system is confluent.
Also see~"IsConfluent!for pc groups".
\>ConfluentRws( <rws> ) A
Return a new rewriting system defining the same algebra as <rws>
which is confluent.
\>IsReduced( <rws> ) P
A rewriting system is reduced if for each rule (<l>, <r>),
<l> and <r> are both reduced.
\>ReduceRules( <rws> ) O
Reduce rules and remove redundant rules to make <rws> reduced.
\>AddRule( <rws>, <rule> ) O
Add <rule> to a rewriting system <rws>.
\>AddRuleReduced( <rws>, <rule> ) O
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> ) O
Add rules (and perhaps reduce) in order to make <rws> confluent
% Don't know what to make of these.
\>GeneratorsOfRws( <rws> ) A
\>AddGenerators( <rws>, <gens> ) O
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{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>.
\>ReducedProduct( <rws>, <u>, <v> ) O
The result is <w> where <[w]> = <[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).
\>ReducedSum( <rws>, <left>, <right> ) O
\>ReducedOne( <rws> ) O
\>ReducedAdditiveInverse( <rws>, <obj> ) O
\>ReducedComm( <rws>, <left>, <right> ) O
\>ReducedConjugate( <rws>, <left>, <right> ) O
\>ReducedDifference( <rws>, <left>, <right> ) O
\>ReducedInverse( <rws>, <obj> ) O
\>ReducedLeftQuotient( <rws>, <left>, <right> ) O
\>ReducedPower( <rws>, <obj>, <pow> ) O
\>ReducedQuotient( <rws>, <left>, <right> ) O
\>ReducedScalarProduct( <rws>, <left>, <right> ) O
\>ReducedZero( <rws> ) O
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Properties of rewriting systems}
The following properties may be used to identify the
type of term algebra over which the rewriting system is defined.
\>IsBuiltFromAdditiveMagmaWithInverses( <obj> ) P
\>IsBuiltFromMagma( <obj> ) P
\>IsBuiltFromMagmaWithOne( <obj> ) P
\>IsBuiltFromMagmaWithInverses( <obj> ) P
\>IsBuiltFromSemigroup( <obj> ) P
\>IsBuiltFromGroup( <obj> ) P
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{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'.)
\beginexample
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^-1, f1, f2^-1, f2, f3^-1, f3
]>, function( x ) ... end, function( x ) ... end )
gap> mon:=Image(mhom);
<fp monoid on the generators [ f1^-1, f1, f2^-1, f2, f3^-1, f3 ]>
gap> k:=KnuthBendixRewritingSystem(mon);
Knuth Bendix Rewriting System for Monoid( [ f1^-1, f1, f2^-1, f2, f3^-1, f3
], ... ) with rules
[ [ f1^-1*f1, <identity ...> ], [ f1*f1^-1, <identity ...> ],
[ f2^-1*f2, <identity ...> ], [ f2*f2^-1, <identity ...> ],
[ f3^-1*f3, <identity ...> ], [ f3*f3^-1, <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^-1*f1*f2^-1*f2*f3^-1*f3
gap> ReducedForm(k,UnderlyingElement(a));
<identity ...>
\endexample
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.
% this example uses random and would be a hassle to modify every time
% something changes
\begintt
gap> r:=PseudoRandom(g);;
gap> Length(r);
3704
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" ]
\endtt
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'
to `KBMAG_REW'. Assignment to `GAPKB_REW' reverts to the built-in
implementation. (See section~"KB_REW".)
\begintt
gap> LoadPackage("kbmag");
true
gap> KB_REW:=KBMAG_REW;;
\endtt
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Developing rewriting systems}
The key point to note about rewriting systems is that they have
properties such as `IsConfluent' and attributes such as `Rules', 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~"Finitely Presented Semigroups and Monoids"), the function
`CreateKnuthBendixRewritingSystem' creating the
rewriting system (in `kbsemi.gi') uses
\begintt
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));
\endtt
In particular, since we don't use the filter `IsAttributeStoringRep'
in the `Objectify', whenever `IsConfluent' is called, the appropriate
method to determine confluence is called.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%E
|