  
  [1X37 [33X[0;0YAssociative Words[133X[101X
  
  
  [1X37.1 [33X[0;0YCategories of Associative Words[133X[101X
  
  [33X[0;0YAssociative  words are used to represent elements in free groups, semigroups
  and  monoids  in  [5XGAP[105X  (see [14X37.2[114X). An associative word is just a sequence of
  letters,  where  each  letter is an element of an alphabet (in the following
  called  a [13Xgenerator[113X) or its inverse. Associative words can be multiplied; in
  free  monoids  also  the  computation  of  an identity is permitted, in free
  groups also the computation of inverses (see [14X37.4[114X).[133X
  
  [33X[0;0YDifferent  alphabets  correspond to different families of associative words.
  There is no relation whatsoever between words in different families.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xf:= FreeGroup( "a", "b", "c" );[127X[104X
    [4X[28X<free group on the generators [ a, b, c ]>[128X[104X
    [4X[25Xgap>[125X [27Xgens:= GeneratorsOfGroup(f);[127X[104X
    [4X[28X[ a, b, c ][128X[104X
    [4X[25Xgap>[125X [27Xw:= gens[1]*gens[2]/gens[3]*gens[2]*gens[1]/gens[1]*gens[3]/gens[2];[127X[104X
    [4X[28Xa*b*c^-1*b*c*b^-1[128X[104X
    [4X[25Xgap>[125X [27Xw^-1;[127X[104X
    [4X[28Xb*c^-1*b^-1*c*b^-1*a^-1[128X[104X
  [4X[32X[104X
  
  [33X[0;0YWords  are displayed as products of letters. The letters are usually printed
  like  [10Xf1[110X,  [10Xf2[110X,  [22X...[122X,  but it is possible to give user defined names to them,
  which  can  be  arbitrary strings. These names do not necessarily identify a
  unique  letter  (generator), it is possible to have several letters –even in
  the same family– that are displayed in the same way. Note also that [13Xthere is
  no  relation between the names of letters and variable names[113X. In the example
  above, we might have typed[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xa:= f.1;; b:= f.2;; c:= f.3;;[127X[104X
  [4X[32X[104X
  
  [33X[0;0Y([13XInteractively[113X,  the  function  [2XAssignGeneratorVariables[102X ([14X37.2-3[114X) provides a
  shorthand for this.) This allows us to define [10Xw[110X more conveniently:[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xw := a*b/c*b*a/a*c/b;[127X[104X
    [4X[28Xa*b*c^-1*b*c*b^-1[128X[104X
  [4X[32X[104X
  
  [33X[0;0YUsing  homomorphisms  it is possible to express elements of a group as words
  in terms of generators, see [14X39.5[114X.[133X
  
  [1X37.1-1 IsAssocWord[101X
  
  [29X[2XIsAssocWord[102X( [3Xobj[103X ) [32X Category
  [29X[2XIsAssocWordWithOne[102X( [3Xobj[103X ) [32X Category
  [29X[2XIsAssocWordWithInverse[102X( [3Xobj[103X ) [32X Category
  
  [33X[0;0Y[2XIsAssocWord[102X  is  the  category  of  associative  words  in  free semigroups,
  [2XIsAssocWordWithOne[102X  is  the  category  of  associative words in free monoids
  (which   admit   the  operation  [2XOne[102X  ([14X31.10-2[114X)  to  compute  an  identity),
  [2XIsAssocWordWithInverse[102X  is  the category of associative words in free groups
  (which  have an inverse). See [2XIsWord[102X ([14X36.1-1[114X) for more general categories of
  words.[133X
  
  
  [1X37.2 [33X[0;0YFree Groups, Monoids and Semigroups[133X[101X
  
  [33X[0;0YUsually  a family of associative words will be generated by constructing the
  free  object  generated  by  them.  See  [2XFreeMonoid[102X  ([14X51.2-9[114X), [2XFreeSemigroup[102X
  ([14X51.1-10[114X) for details.[133X
  
  
  [1X37.2-1 [33X[0;0YFreeGroup[133X[101X
  
  [29X[2XFreeGroup[102X( [[3Xwfilt[103X, ][3Xrank[103X[, [3Xname[103X] ) [32X function
  [29X[2XFreeGroup[102X( [[3Xwfilt[103X, ][3Xname1[103X, [3Xname2[103X, [3X...[103X ) [32X function
  [29X[2XFreeGroup[102X( [[3Xwfilt[103X, ][3Xnames[103X ) [32X function
  [29X[2XFreeGroup[102X( [[3Xwfilt[103X, ][3Xinfinity[103X, [3Xname[103X, [3Xinit[103X ) [32X function
  
  [33X[0;0YCalled  with a positive integer [3Xrank[103X, [2XFreeGroup[102X returns a free group on [3Xrank[103X
  generators.  If  the optional argument [3Xname[103X is given then the generators are
  printed as [3Xname[103X[10X1[110X, [3Xname[103X[10X2[110X etc., that is, each name is the concatenation of the
  string  [3Xname[103X  and  an  integer  from [10X1[110X to [3Xrange[103X. The default for [3Xname[103X is the
  string [10X"f"[110X.[133X
  
  [33X[0;0YCalled  in  the  second  form,  [2XFreeGroup[102X  returns  a  free group on as many
  generators as arguments, printed as [3Xname1[103X, [3Xname2[103X etc.[133X
  
  [33X[0;0YCalled  in  the  third  form,  [2XFreeGroup[102X  returns  a  free  group on as many
  generators as the length of the list [3Xnames[103X, the [22Xi[122X-th generator being printed
  as [3Xnames[103X[10X[[110X[22Xi[122X[10X][110X.[133X
  
  [33X[0;0YCalled in the fourth form, [2XFreeGroup[102X returns a free group on infinitely many
  generators,  where the first generators are printed by the names in the list
  [3Xinit[103X, and the other generators by [3Xname[103X and an appended number.[133X
  
  [33X[0;0YIf    the   extra   argument   [3Xwfilt[103X   is   given,   it   must   be   either
  [10XIsSyllableWordsFamily[110X  or  [10XIsLetterWordsFamily[110X  or  [10XIsWLetterWordsFamily[110X  or
  [10XIsBLetterWordsFamily[110X. This filter then specifies the representation used for
  the  elements  of  the  free group (see [14X37.6[114X). If no such filter is given, a
  letter representation is used.[133X
  
  [33X[0;0Y(For  interfacing to old code that omits the representation flag, use of the
  syllable   representation   is   also   triggered   by  setting  the  option
  [10XFreeGroupFamilyType[110X to the string [10X"syllable"[110X.)[133X
  
  [1X37.2-2 IsFreeGroup[101X
  
  [29X[2XIsFreeGroup[102X( [3Xobj[103X ) [32X Category
  
  [33X[0;0YAny  group consisting of elements in [2XIsAssocWordWithInverse[102X ([14X37.1-1[114X) lies in
  the  filter [2XIsFreeGroup[102X; this holds in particular for any group created with
  [2XFreeGroup[102X ([14X37.2-1[114X), or any subgroup of such a group.[133X
  
  [33X[0;0YAlso see Chapter [14X47[114X.[133X
  
  [1X37.2-3 AssignGeneratorVariables[101X
  
  [29X[2XAssignGeneratorVariables[102X( [3XG[103X ) [32X function
  
  [33X[0;0YIf  [3XG[103X is a group, whose generators are represented by symbols (for example a
  free  group, a finitely presented group or a pc group) this function assigns
  these generators to global variables with the same names.[133X
  
  [33X[0;0YThe  aim of this function is to make it easy in interactive use to work with
  (for  example) a free group. It is a shorthand for a sequence of assignments
  of the form[133X
  
  [4X[32X  Example  [32X[104X
    [4X[28Xvar1:=GeneratorsOfGroup(G)[1];[128X[104X
    [4X[28Xvar2:=GeneratorsOfGroup(G)[2];[128X[104X
    [4X[28X...[128X[104X
    [4X[28Xvarn:=GeneratorsOfGroup(G)[n];[128X[104X
  [4X[32X[104X
  
  [33X[0;0YHowever, since overwriting global variables can be very dangerous, [13Xit is not
  permitted to use this function within a function[113X. (If –despite this warning–
  this is done, the result is undefined.)[133X
  
  [33X[0;0YIf  the  assignment overwrites existing variables a warning is given, if any
  of the variables if write protected, or any of the generator names would not
  be a proper variable name, an error is raised.[133X
  
  
  [1X37.3 [33X[0;0YComparison of Associative Words[133X[101X
  
  [1X37.3-1 \=[101X
  
  [29X[2X\=[102X( [3Xw1[103X, [3Xw2[103X ) [32X function
  
  [33X[0;0YTwo associative words are equal if they are words over the same alphabet and
  if they are sequences of the same letters. This is equivalent to saying that
  the external representations of the words are equal, see [14X37.7[114X and [14X36.2[114X.[133X
  
  [33X[0;0YThere  is  no [21Xuniversal[121X empty word, every alphabet (that is, every family of
  words) has its own empty word.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xf:= FreeGroup( "a", "b", "b" );;[127X[104X
    [4X[25Xgap>[125X [27Xgens:= GeneratorsOfGroup(f);[127X[104X
    [4X[28X[ a, b, b ][128X[104X
    [4X[25Xgap>[125X [27Xgens[2] = gens[3];[127X[104X
    [4X[28Xfalse[128X[104X
    [4X[25Xgap>[125X [27Xx:= gens[1]*gens[2];[127X[104X
    [4X[28Xa*b[128X[104X
    [4X[25Xgap>[125X [27Xy:= gens[2]/gens[2]*gens[1]*gens[2];[127X[104X
    [4X[28Xa*b[128X[104X
    [4X[25Xgap>[125X [27Xx = y;[127X[104X
    [4X[28Xtrue[128X[104X
    [4X[25Xgap>[125X [27Xz:= gens[2]/gens[2]*gens[1]*gens[3];[127X[104X
    [4X[28Xa*b[128X[104X
    [4X[25Xgap>[125X [27Xx = z;[127X[104X
    [4X[28Xfalse[128X[104X
  [4X[32X[104X
  
  [1X37.3-2 \<[101X
  
  [29X[2X\<[102X( [3Xw1[103X, [3Xw2[103X ) [32X function
  
  [33X[0;0YThe  ordering  of  associative  words  is defined by length and lexicography
  (this  ordering  is  called  [13Xshort-lex[113X ordering), that is, shorter words are
  smaller  than  longer  words,  and  words  of  the  same length are compared
  w.r.t. the  lexicographical  ordering induced by the ordering of generators.
  Generators  are sorted according to the order in which they were created. If
  the  generators  are  invertible  then  each  generator [3Xg[103X is larger than its
  inverse  [3Xg[103X[10X^-1[110X,  and [3Xg[103X[10X^-1[110X is larger than every generator that is smaller than
  [3Xg[103X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xf:= FreeGroup( 2 );;  gens:= GeneratorsOfGroup( f );;[127X[104X
    [4X[25Xgap>[125X [27Xa:= gens[1];;  b:= gens[2];;[127X[104X
    [4X[25Xgap>[125X [27XOne(f) < a^-1;  a^-1 < a;  a < b^-1;  b^-1 < b; b < a^2;  a^2 < a*b;[127X[104X
    [4X[28Xtrue[128X[104X
    [4X[28Xtrue[128X[104X
    [4X[28Xtrue[128X[104X
    [4X[28Xtrue[128X[104X
    [4X[28Xtrue[128X[104X
    [4X[28Xtrue[128X[104X
  [4X[32X[104X
  
  [1X37.3-3 IsShortLexLessThanOrEqual[101X
  
  [29X[2XIsShortLexLessThanOrEqual[102X( [3Xu[103X, [3Xv[103X ) [32X function
  
  [33X[0;0Yreturns  [10XIsLessThanOrEqualUnder([3Xord[103X[10X,  [3Xu[103X[10X,  [3Xv[103X[10X)[110X  where  [3Xord[103X  is  the short less
  ordering  for  the  family  of [3Xu[103X and [3Xv[103X. (This is here for compatibility with
  [5XGAP[105X 4.2.)[133X
  
  [1X37.3-4 IsBasicWreathLessThanOrEqual[101X
  
  [29X[2XIsBasicWreathLessThanOrEqual[102X( [3Xu[103X, [3Xv[103X ) [32X function
  
  [33X[0;0Yreturns  [10XIsLessThanOrEqualUnder([3Xord[103X[10X,  [3Xu[103X[10X,  [3Xv[103X[10X)[110X  where  [3Xord[103X is the basic wreath
  product  ordering for the family of [3Xu[103X and [3Xv[103X. (This is here for compatibility
  with [5XGAP[105X 4.2.)[133X
  
  
  [1X37.4 [33X[0;0YOperations for Associative Words[133X[101X
  
  [33X[0;0YThe  product of two given associative words is defined as the freely reduced
  concatenation  of  the  words.  Besides the multiplication [2X\*[102X ([14X31.12-1[114X), the
  arithmetical  operators  [2XOne[102X  ([14X31.10-2[114X)  (if  the word lies in a family with
  identity)  and  (if  the  generators  are  invertible) [2XInverse[102X ([14X31.10-8[114X), [2X\/[102X
  ([14X31.12-1[114X),[2X\^[102X  ([14X31.12-1[114X),  [2XComm[102X  ([14X31.12-3[114X),  and  [2XLeftQuotient[102X  ([14X31.12-2[114X) are
  applicable to associative words, see [14X31.12[114X.[133X
  
  [33X[0;0YSee  also  [2XMappedWord[102X ([14X36.3-1[114X), an operation that is applicable to arbitrary
  words.[133X
  
  [33X[0;0YSee  Section  [14X37.6[114X  for  a  discussion  of  the  internal representations of
  associative words that are supported by [5XGAP[105X. Note that operations to extract
  or  act  on  parts  of  words  (letter or syllables) can carry substantially
  different costs, depending on the representation the words are in.[133X
  
  [1X37.4-1 Length[101X
  
  [29X[2XLength[102X( [3Xw[103X ) [32X attribute
  
  [33X[0;0YFor an associative word [3Xw[103X, [2XLength[102X returns the number of letters in [3Xw[103X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xf := FreeGroup("a","b");; gens := GeneratorsOfGroup(f);;[127X[104X
    [4X[25Xgap>[125X [27Xa := gens[1];; b := gens[2];;w := a^5*b*a^2*b^-4*a;;[127X[104X
    [4X[25Xgap>[125X [27X w; Length( w );  Length( a^17 );  Length( w^0 );[127X[104X
    [4X[28Xa^5*b*a^2*b^-4*a[128X[104X
    [4X[28X13[128X[104X
    [4X[28X17[128X[104X
    [4X[28X0[128X[104X
  [4X[32X[104X
  
  [1X37.4-2 ExponentSumWord[101X
  
  [29X[2XExponentSumWord[102X( [3Xw[103X, [3Xgen[103X ) [32X operation
  
  [33X[0;0YFor  an  associative word [3Xw[103X and a generator [3Xgen[103X, [2XExponentSumWord[102X returns the
  number  of  times  [3Xgen[103X  appears  in  [3Xw[103X minus the number of times its inverse
  appears  in  [3Xw[103X.  If  both  [3Xgen[103X  and  its inverse do not occur in [3Xw[103X then [22X0[122X is
  returned. [3Xgen[103X may also be the inverse of a generator.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xw;  ExponentSumWord( w, a );  ExponentSumWord( w, b );[127X[104X
    [4X[28Xa^5*b*a^2*b^-4*a[128X[104X
    [4X[28X8[128X[104X
    [4X[28X-3[128X[104X
    [4X[25Xgap>[125X [27XExponentSumWord( (a*b*a^-1)^3, a );  ExponentSumWord( w, b^-1 );[127X[104X
    [4X[28X0[128X[104X
    [4X[28X3[128X[104X
  [4X[32X[104X
  
  [1X37.4-3 Subword[101X
  
  [29X[2XSubword[102X( [3Xw[103X, [3Xfrom[103X, [3Xto[103X ) [32X operation
  
  [33X[0;0YFor  an  associative  word  [3Xw[103X and two positive integers [3Xfrom[103X and [3Xto[103X, [2XSubword[102X
  returns  the  subword of [3Xw[103X that begins at position [3Xfrom[103X and ends at position
  [3Xto[103X. Indexing is done with origin 1.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xw;  Subword( w, 3, 7 );[127X[104X
    [4X[28Xa^5*b*a^2*b^-4*a[128X[104X
    [4X[28Xa^3*b*a[128X[104X
  [4X[32X[104X
  
  [1X37.4-4 PositionWord[101X
  
  [29X[2XPositionWord[102X( [3Xw[103X, [3Xsub[103X, [3Xfrom[103X ) [32X operation
  
  [33X[0;0YLet   [3Xw[103X  and  [3Xsub[103X  be  associative  words,  and  [3Xfrom[103X  a  positive  integer.
  [2XPositionWord[102X  returns  the  position  of  the  first  occurrence of [3Xsub[103X as a
  subword  of  [3Xw[103X,  starting  at position [3Xfrom[103X. If there is no such occurrence,
  [9Xfail[109X is returned. Indexing is done with origin 1.[133X
  
  [33X[0;0YIn  other  words,  [10XPositionWord(  [3Xw[103X[10X,  [3Xsub[103X[10X,  [3Xfrom[103X[10X )[110X is the smallest integer [22Xi[122X
  larger  than or equal to [3Xfrom[103X such that [10XSubword( [3Xw[103X[10X, [110X[22Xi[122X[10X,[110X [22Xi[122X[10X+Length( [3Xsub[103X[10X )-1 ) =[110X
  [3Xsub[103X, see [2XSubword[102X ([14X37.4-3[114X).[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xw;  PositionWord( w, a/b, 1 );[127X[104X
    [4X[28Xa^5*b*a^2*b^-4*a[128X[104X
    [4X[28X8[128X[104X
    [4X[25Xgap>[125X [27XSubword( w, 8, 9 );[127X[104X
    [4X[28Xa*b^-1[128X[104X
    [4X[25Xgap>[125X [27XPositionWord( w, a^2, 1 );[127X[104X
    [4X[28X1[128X[104X
    [4X[25Xgap>[125X [27XPositionWord( w, a^2, 2 );[127X[104X
    [4X[28X2[128X[104X
    [4X[25Xgap>[125X [27XPositionWord( w, a^2, 6 );[127X[104X
    [4X[28X7[128X[104X
    [4X[25Xgap>[125X [27XPositionWord( w, a^2, 8 );[127X[104X
    [4X[28Xfail[128X[104X
  [4X[32X[104X
  
  
  [1X37.4-5 [33X[0;0YSubstitutedWord[133X[101X
  
  [29X[2XSubstitutedWord[102X( [3Xw[103X, [3Xfrom[103X, [3Xto[103X, [3Xby[103X ) [32X operation
  [29X[2XSubstitutedWord[102X( [3Xw[103X, [3Xsub[103X, [3Xfrom[103X, [3Xby[103X ) [32X operation
  
  [33X[0;0YLet [3Xw[103X be an associative word.[133X
  
  [33X[0;0YIn  the first form, [2XSubstitutedWord[102X returns the associative word obtained by
  replacing the subword of [3Xw[103X that begins at position [3Xfrom[103X and ends at position
  [3Xto[103X  by  the  associative  word  [3Xby[103X.  [3Xfrom[103X  and [3Xto[103X must be positive integers,
  indexing  is  done  with origin 1. In other words, [10XSubstitutedWord( [3Xw[103X[10X, [3Xfrom[103X[10X,
  [3Xto[103X[10X,  [3Xby[103X[10X )[110X is the product of the three words [10XSubword( [3Xw[103X[10X, 1, [3Xfrom[103X[10X-1 )[110X, [3Xby[103X, and
  [10XSubword( [3Xw[103X[10X, [3Xto[103X[10X+1, Length( [3Xw[103X[10X ) )[110X, see [2XSubword[102X ([14X37.4-3[114X).[133X
  
  [33X[0;0YIn the second form, [2XSubstitutedWord[102X returns the associative word obtained by
  replacing the first occurrence of the associative word [3Xsub[103X of [3Xw[103X, starting at
  position  [3Xfrom[103X,  by the associative word [3Xby[103X; if there is no such occurrence,
  [9Xfail[109X is returned.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xw;  SubstitutedWord( w, 3, 7, a^19 );[127X[104X
    [4X[28Xa^5*b*a^2*b^-4*a[128X[104X
    [4X[28Xa^22*b^-4*a[128X[104X
    [4X[25Xgap>[125X [27XSubstitutedWord( w, a, 6, b^7 );[127X[104X
    [4X[28Xa^5*b^8*a*b^-4*a[128X[104X
    [4X[25Xgap>[125X [27XSubstitutedWord( w, a*b, 6, b^7 );[127X[104X
    [4X[28Xfail[128X[104X
  [4X[32X[104X
  
  [1X37.4-6 EliminatedWord[101X
  
  [29X[2XEliminatedWord[102X( [3Xw[103X, [3Xgen[103X, [3Xby[103X ) [32X operation
  
  [33X[0;0YFor  an  associative  word  [3Xw[103X,  a generator [3Xgen[103X, and an associative word [3Xby[103X,
  [2XEliminatedWord[102X  returns  the  associative  word  obtained  by replacing each
  occurrence of [3Xgen[103X in [3Xw[103X by [3Xby[103X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xw;  EliminatedWord( w, a, a^2 );  EliminatedWord( w, a, b^-1 );[127X[104X
    [4X[28Xa^5*b*a^2*b^-4*a[128X[104X
    [4X[28Xa^10*b*a^4*b^-4*a^2[128X[104X
    [4X[28Xb^-11[128X[104X
  [4X[32X[104X
  
  
  [1X37.5 [33X[0;0YOperations for Associative Words by their Syllables[133X[101X
  
  [33X[0;0YFor an associative word [3Xw[103X [22X= x_1^{n_1} x_2^{n_2} ⋯ x_k^{n_k}[122X over an alphabet
  containing  [22Xx_1,  x_2,  ...,  x_k[122X, such that [22Xx_i ≠ x_{i+1}^{± 1}[122X for [22X1 ≤ i ≤
  k-1[122X,  the  subwords  [22Xx_i^{e_i}[122X  are  uniquely  determined;  these  powers of
  generators are called the [13Xsyllables[113X of [22Xw[122X.[133X
  
  [1X37.5-1 NumberSyllables[101X
  
  [29X[2XNumberSyllables[102X( [3Xw[103X ) [32X attribute
  
  [33X[0;0Y[2XNumberSyllables[102X returns the number of syllables of the associative word [3Xw[103X.[133X
  
  [1X37.5-2 ExponentSyllable[101X
  
  [29X[2XExponentSyllable[102X( [3Xw[103X, [3Xi[103X ) [32X operation
  
  [33X[0;0Y[2XExponentSyllable[102X   returns   the  exponent  of  the  [3Xi[103X-th  syllable  of  the
  associative word [3Xw[103X.[133X
  
  [1X37.5-3 GeneratorSyllable[101X
  
  [29X[2XGeneratorSyllable[102X( [3Xw[103X, [3Xi[103X ) [32X operation
  
  [33X[0;0Y[2XGeneratorSyllable[102X  returns  the  number of the generator that is involved in
  the [3Xi[103X-th syllable of the associative word [3Xw[103X.[133X
  
  [1X37.5-4 SubSyllables[101X
  
  [29X[2XSubSyllables[102X( [3Xw[103X, [3Xfrom[103X, [3Xto[103X ) [32X operation
  
  [33X[0;0Y[2XSubSyllables[102X  returns the subword of the associative word [3Xw[103X that consists of
  the  syllables from positions [3Xfrom[103X to [3Xto[103X, where [3Xfrom[103X and [3Xto[103X must be positive
  integers, and indexing is done with origin 1.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xw;  NumberSyllables( w );[127X[104X
    [4X[28Xa^5*b*a^2*b^-4*a[128X[104X
    [4X[28X5[128X[104X
    [4X[25Xgap>[125X [27XExponentSyllable( w, 3 );[127X[104X
    [4X[28X2[128X[104X
    [4X[25Xgap>[125X [27XGeneratorSyllable( w, 3 );[127X[104X
    [4X[28X1[128X[104X
    [4X[25Xgap>[125X [27XSubSyllables( w, 2, 3 );[127X[104X
    [4X[28Xb*a^2[128X[104X
  [4X[32X[104X
  
  
  [1X37.6 [33X[0;0YRepresentations for Associative Words[133X[101X
  
  [33X[0;0Y[5XGAP[105X  provides two different internal kinds of representations of associative
  words.  The first one are [21Xsyllable representations[121X in which words are stored
  in syllable (i.e. generator,exponent) form. (Older versions of [5XGAP[105X only used
  this  representation.)  The  second kind are [21Xletter representations[121X in which
  each  letter  in a word is represented by its index number. Negative numbers
  are  used  for  inverses.  Unless  the  syllable representation is specified
  explicitly  when  creating  the  free  group/monoid  or  semigroup, a letter
  representation is used by default.[133X
  
  [33X[0;0YDepending  on  the  task  in  mind, either of these two representations will
  perform  better in time or in memory use and algorithms that are syllable or
  letter  based  (for example [2XGeneratorSyllable[102X ([14X37.5-3[114X) and [2XSubword[102X ([14X37.4-3[114X))
  perform  substantially  better  in  the  corresponding  representation.  For
  example  when  creating  pc  groups  (see [14X46[114X),  it  is advantageous to use a
  syllable  representation  while  calculations in free groups usually benefit
  from using a letter representation.[133X
  
  [1X37.6-1 IsLetterAssocWordRep[101X
  
  [29X[2XIsLetterAssocWordRep[102X( [3Xobj[103X ) [32X Representation
  
  [33X[0;0YA  word in letter representation stores a list of generator/inverses numbers
  (as  given  by [2XLetterRepAssocWord[102X ([14X37.6-8[114X)). Letter access is fast, syllable
  access is slow for such words.[133X
  
  [1X37.6-2 IsLetterWordsFamily[101X
  
  [29X[2XIsLetterWordsFamily[102X( [3Xobj[103X ) [32X Category
  
  [33X[0;0YA letter word family stores words by default in letter form.[133X
  
  [33X[0;0YInternally,  there  are letter representations that use integers (4 Byte) to
  represent  a  generator  and letter representations that use single bytes to
  represent a character. The latter are more memory efficient, but can only be
  used  if  there are less than 128 generators (in which case they are used by
  default).[133X
  
  [1X37.6-3 IsBLetterAssocWordRep[101X
  
  [29X[2XIsBLetterAssocWordRep[102X( [3Xobj[103X ) [32X Representation
  [29X[2XIsWLetterAssocWordRep[102X( [3Xobj[103X ) [32X Representation
  
  [33X[0;0Ythese  two  subrepresentations  of  [2XIsLetterAssocWordRep[102X  ([14X37.6-1[114X)  indicate
  whether  the word is stored as a list of bytes (in a string) or as a list of
  integers).[133X
  
  [1X37.6-4 IsBLetterWordsFamily[101X
  
  [29X[2XIsBLetterWordsFamily[102X( [3Xobj[103X ) [32X Category
  [29X[2XIsWLetterWordsFamily[102X( [3Xobj[103X ) [32X Category
  
  [33X[0;0YThese  two subcategories of [2XIsLetterWordsFamily[102X ([14X37.6-2[114X) specify the type of
  letter representation to be used.[133X
  
  [1X37.6-5 IsSyllableAssocWordRep[101X
  
  [29X[2XIsSyllableAssocWordRep[102X( [3Xobj[103X ) [32X Representation
  
  [33X[0;0YA word in syllable representation stores generator/exponents pairs (as given
  by [2XExtRepOfObj[102X ([14X79.16-1[114X). Syllable access is fast, letter access is slow for
  such words.[133X
  
  [1X37.6-6 IsSyllableWordsFamily[101X
  
  [29X[2XIsSyllableWordsFamily[102X( [3Xobj[103X ) [32X Category
  
  [33X[0;0YA  syllable  word family stores words by default in syllable form. There are
  also  different  versions  of  syllable  representations,  which  compress a
  generator  exponent  pair  in  8,  16  or 32 bits or use a pair of integers.
  Internal mechanisms try to make this as memory efficient as possible.[133X
  
  [1X37.6-7 Is16BitsFamily[101X
  
  [29X[2XIs16BitsFamily[102X( [3Xobj[103X ) [32X Category
  [29X[2XIs32BitsFamily[102X( [3Xobj[103X ) [32X Category
  [29X[2XIsInfBitsFamily[102X( [3Xobj[103X ) [32X Category
  
  [33X[0;0YRegardless  of the internal representation used, it is possible to convert a
  word  in  a  list  of  numbers in letter or syllable representation and vice
  versa.[133X
  
  [1X37.6-8 LetterRepAssocWord[101X
  
  [29X[2XLetterRepAssocWord[102X( [3Xw[103X[, [3Xgens[103X] ) [32X operation
  
  [33X[0;0YThe  [13Xletter  representation[113X  of an associated word is as a list of integers,
  each  entry  corresponding  to a group generator. Inverses of the generators
  are represented by negative numbers. The generator numbers are as associated
  to the family.[133X
  
  [33X[0;0YThis operation returns the letter representation of the associative word [3Xw[103X.[133X
  
  [33X[0;0YIn  the  call  with  two  arguments, the generator numbers correspond to the
  generator order given in the list [3Xgens[103X.[133X
  
  [33X[0;0Y(For  words  stored  in  syllable  form  the letter representation has to be
  computed.)[133X
  
  [1X37.6-9 AssocWordByLetterRep[101X
  
  [29X[2XAssocWordByLetterRep[102X( [3XFam[103X, [3Xlrep[103X[, [3Xgens[103X] ) [32X operation
  
  [33X[0;0Ytakes  a  letter  representation  [3Xlrep[103X (see [2XLetterRepAssocWord[102X ([14X37.6-8[114X)) and
  returns  an  associative  word  in  family  [3Xfam[103X corresponding to this letter
  representation.[133X
  
  [33X[0;0YIf  [3Xgens[103X  is  given,  the numbers in the letter representation correspond to
  [3Xgens[103X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xw:=AssocWordByLetterRep( FamilyObj(a), [-1,2,1,-2,-2,-2,1,1,1,1]);[127X[104X
    [4X[28Xa^-1*b*a*b^-3*a^4[128X[104X
    [4X[25Xgap>[125X [27XLetterRepAssocWord( w^2 );[127X[104X
    [4X[28X[ -1, 2, 1, -2, -2, -2, 1, 1, 1, 2, 1, -2, -2, -2, 1, 1, 1, 1 ][128X[104X
  [4X[32X[104X
  
  [33X[0;0YThe  external  representation  (see  section [14X37.7[114X) can be used if a syllable
  representation is needed.[133X
  
  
  [1X37.7 [33X[0;0YThe External Representation for Associative Words[133X[101X
  
  [33X[0;0YThe external representation of the associative word [22Xw[122X is defined as follows.
  If  [22Xw = g_{i_1}^{e_1} * g_{i_2}^{e_2} * ⋯ * g_{i_k}^{e_k}[122X is a word over the
  alphabet  [22Xg_1,  g_2, ...[122X, i.e., [22Xg_i[122X denotes the [22Xi[122X-th generator of the family
  of [22Xw[122X, then [22Xw[122X has external representation [22X[ i_1, e_1, i_2, e_2, ..., i_k, e_k
  ][122X.  The empty list describes the identity element (if exists) of the family.
  Exponents  may  be  negative  if  the  family  allows inverses. The external
  representation  of  an  associative word is guaranteed to be freely reduced;
  for example, [22Xg_1 * g_2 * g_2^{-1} * g_1[122X has the external representation [10X[ 1,
  2 ][110X.[133X
  
  [33X[0;0YRegardless  of  the family preference for letter or syllable representations
  (see [14X37.6[114X),  [10XExtRepOfObj[110X  and  [10XObjByExtRep[110X can be used and interface to this
  [21Xsyllable[121X-like representation.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xw:= ObjByExtRep( FamilyObj(a), [1,5,2,-7,1,3,2,4,1,-2] );[127X[104X
    [4X[28Xa^5*b^-7*a^3*b^4*a^-2[128X[104X
    [4X[25Xgap>[125X [27XExtRepOfObj( w^2 );[127X[104X
    [4X[28X[ 1, 5, 2, -7, 1, 3, 2, 4, 1, 3, 2, -7, 1, 3, 2, 4, 1, -2 ][128X[104X
  [4X[32X[104X
  
  
  [1X37.8 [33X[0;0YStraight Line Programs[133X[101X
  
  [33X[0;0Y[13XStraight  line programs[113X describe an efficient way for evaluating an abstract
  word  at  concrete  generators, in a more efficient way than with [2XMappedWord[102X
  ([14X36.3-1[114X).  For  example,  the  associative  word  [22Xababbab[122X of length [22X7[122X can be
  computed  from  the generators [22Xa[122X, [22Xb[122X with only four multiplications, by first
  computing  [22Xc = ab[122X, then [22Xd = cb[122X, and then [22Xcdc[122X; Alternatively, one can compute
  [22Xc = ab[122X, [22Xe = bc[122X, and [22Xaee[122X. In each step of these computations, one forms words
  in terms of the words computed in the previous steps.[133X
  
  [33X[0;0YA  straight  line program in [5XGAP[105X is represented by an object in the category
  [2XIsStraightLineProgram[102X  ([14X37.8-1[114X))  that  stores a list of [21Xlines[121X each of which
  has one of the following three forms.[133X
  
  [31X1[131X   [33X[0;6Ya nonempty dense list [22Xl[122X of integers,[133X
  
  [31X2[131X   [33X[0;6Ya  pair  [22X[  l,  i  ][122X  where [22Xl[122X is a list of form 1. and [22Xi[122X is a positive
        integer,[133X
  
  [31X3[131X   [33X[0;6Ya  list  [22X[  l_1,  l_2, ..., l_k ][122X where each [22Xl_i[122X is a list of form 1.;
        this may occur only for the last line of the program.[133X
  
  [33X[0;0YThe lists of integers that occur are interpreted as external representations
  of  associative  words (see Section  [14X37.7[114X); for example, the list [22X[ 1, 3, 2,
  -1  ][122X  represents  the  word  [22Xg_1^3 g_2^{-1}[122X, with [22Xg_1[122X and [22Xg_2[122X the first and
  second abstract generator, respectively.[133X
  
  [33X[0;0YFor  the  meaning  of  the  list  of  lines, see [2XResultOfStraightLineProgram[102X
  ([14X37.8-5[114X).[133X
  
  [33X[0;0YStraight   line   programs  can  be  constructed  using  [2XStraightLineProgram[102X
  ([14X37.8-2[114X).[133X
  
  [33X[0;0YDefining      attributes      for     straight     line     programs     are
  [2XNrInputsOfStraightLineProgram[102X    ([14X37.8-4[114X)   and   [2XLinesOfStraightLineProgram[102X
  ([14X37.8-3[114X).    Another    operation    for    straight    line   programs   is
  [2XResultOfStraightLineProgram[102X ([14X37.8-5[114X).[133X
  
  [33X[0;0YSpecial  methods  applicable to straight line programs are installed for the
  operations   [2XDisplay[102X   ([14X6.3-6[114X),  [2XIsInternallyConsistent[102X  ([14X12.8-3[114X),  [2XPrintObj[102X
  ([14X6.3-5[114X), and [2XViewObj[102X ([14X6.3-5[114X).[133X
  
  [33X[0;0YFor  a straight line program [3Xprog[103X, the default [2XDisplay[102X ([14X6.3-6[114X) method prints
  the  interpretation  of  [3Xprog[103X  as  a  sequence of assignments of associative
  words; a record with components [10Xgensnames[110X (with value a list of strings) and
  [10Xlistname[110X (a string) may be entered as second argument of [2XDisplay[102X ([14X6.3-6[114X), in
  this  case  these names are used, the default for [10Xgensnames[110X is [10X[ g1, g2, [110X[22X...[122X[10X
  ][110X, the default for [10Xlistname[110X is [22Xr[122X.[133X
  
  [1X37.8-1 IsStraightLineProgram[101X
  
  [29X[2XIsStraightLineProgram[102X( [3Xobj[103X ) [32X Category
  
  [33X[0;0YEach    straight    line    program    in   [5XGAP[105X   lies   in   the   category
  [2XIsStraightLineProgram[102X.[133X
  
  [1X37.8-2 StraightLineProgram[101X
  
  [29X[2XStraightLineProgram[102X( [3Xlines[103X[, [3Xnrgens[103X] ) [32X function
  [29X[2XStraightLineProgram[102X( [3Xstring[103X, [3Xgens[103X ) [32X function
  [29X[2XStraightLineProgramNC[102X( [3Xlines[103X[, [3Xnrgens[103X] ) [32X function
  [29X[2XStraightLineProgramNC[102X( [3Xstring[103X, [3Xgens[103X ) [32X function
  
  [33X[0;0YIn  the  first  form,  [3Xlines[103X  must  be a list of lists that defines a unique
  straight  line  program  (see [2XIsStraightLineProgram[102X  ([14X37.8-1[114X)); in this case
  [2XStraightLineProgram[102X  returns  this program, otherwise an error is signalled.
  The optional argument [3Xnrgens[103X specifies the number of input generators of the
  program;  if a line of form 1. (that is, a list of integers) occurs in [3Xlines[103X
  except  in  the  last  position,  this number is not determined by [3Xlines[103X and
  therefore   [13Xmust[113X   be   specified  by  the  argument  [3Xnrgens[103X;  if  not  then
  [2XStraightLineProgram[102X returns [9Xfail[109X.[133X
  
  [33X[0;0YIn  the  second  form,  [3Xstring[103X  must  be  a  string describing an arithmetic
  expression in terms of the strings in the list [3Xgens[103X, where multiplication is
  denoted  by concatenation, powering is denoted by [10X^[110X, and round brackets [10X([110X, [10X)[110X
  may  be used. Each entry in [3Xgens[103X must consist only of uppercase or lowercase
  letters  (i.e.,  letters  in  [2XIsAlphaChar[102X ([14X27.4-4[114X)) such that no entry is an
  initial  part  of  another  one. Called with this input, [2XStraightLineProgram[102X
  returns  a straight line program that evaluates to the word corresponding to
  [3Xstring[103X when called with generators corresponding to [3Xgens[103X.[133X
  
  [33X[0;0YThe  [10XNC[110X  variant  does the same, except that the internal consistency of the
  program is not checked.[133X
  
  [1X37.8-3 LinesOfStraightLineProgram[101X
  
  [29X[2XLinesOfStraightLineProgram[102X( [3Xprog[103X ) [32X attribute
  
  [33X[0;0YFor  a  straight  line  program [3Xprog[103X, [2XLinesOfStraightLineProgram[102X returns the
  list  of program lines. There is no default method to compute these lines if
  they are not stored.[133X
  
  [1X37.8-4 NrInputsOfStraightLineProgram[101X
  
  [29X[2XNrInputsOfStraightLineProgram[102X( [3Xprog[103X ) [32X attribute
  
  [33X[0;0YFor  a straight line program [3Xprog[103X, [2XNrInputsOfStraightLineProgram[102X returns the
  number of generators that are needed as input.[133X
  
  [33X[0;0YIf  a  line  of form 1. (that is, a list of integers) occurs in the lines of
  [3Xprog[103X except the last line then the number of generators is not determined by
  the  lines, and must be set in the construction of the straight line program
  (see [2XStraightLineProgram[102X  ([14X37.8-2[114X)).  So  if [3Xprog[103X contains a line of form 1.
  other  than  the  last line and does [13Xnot[113X store the number of generators then
  [2XNrInputsOfStraightLineProgram[102X signals an error.[133X
  
  [1X37.8-5 ResultOfStraightLineProgram[101X
  
  [29X[2XResultOfStraightLineProgram[102X( [3Xprog[103X, [3Xgens[103X ) [32X operation
  
  [33X[0;0Y[2XResultOfStraightLineProgram[102X    evaluates    the    straight   line   program
  (see [2XIsStraightLineProgram[102X  ([14X37.8-1[114X)) [3Xprog[103X at the group elements in the list
  [3Xgens[103X.[133X
  
  [33X[0;0YThe  [13Xresult[113X  of  a  straight line program with lines [22Xp_1, p_2, ..., p_k[122X when
  applied to [3Xgens[103X is defined as follows.[133X
  
  [8X(a)[108X
        [33X[0;6YFirst  a  list [22Xr[122X of intermediate results is initialized with a shallow
        copy of [3Xgens[103X.[133X
  
  [8X(b)[108X
        [33X[0;6YFor  [22Xi  < k[122X, before the [22Xi[122X-th step, let [22Xr[122X be of length [22Xn[122X. If [22Xp_i[122X is the
        external  representation  of  an  associative  word  in  the  first  [22Xn[122X
        generators  then the image of this word under the homomorphism that is
        given  by  mapping [22Xr[122X to these first [22Xn[122X generators is added to [22Xr[122X; if [22Xp_i[122X
        is  a  pair [22X[ l, j ][122X, for a list [22Xl[122X, then the same element is computed,
        but instead of being added to [22Xr[122X, it replaces the [22Xj[122X-th entry of [22Xr[122X.[133X
  
  [8X(c)[108X
        [33X[0;6YFor  [22Xi  =  k[122X,  if [22Xp_k[122X is the external representation of an associative
        word  then  the element described in (b) is the result of the program,
        if  [22Xp_k[122X  is  a  pair  [22X[  l,  j ][122X, for a list [22Xl[122X, then the result is the
        element described by [22Xl[122X, and if [22Xp_k[122X is a list [22X[ l_1, l_2, ..., l_k ][122X of
        lists  then  the result is a list of group elements, where each [22Xl_i[122X is
        treated as in (b).[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xf:= FreeGroup( "x", "y" );;  gens:= GeneratorsOfGroup( f );;[127X[104X
    [4X[25Xgap>[125X [27Xx:= gens[1];;  y:= gens[2];;[127X[104X
    [4X[25Xgap>[125X [27Xprg:= StraightLineProgram( [ [] ] );[127X[104X
    [4X[28X<straight line program>[128X[104X
    [4X[25Xgap>[125X [27XResultOfStraightLineProgram( prg, [] );[127X[104X
    [4X[28X[  ][128X[104X
  [4X[32X[104X
  
  [33X[0;0YThe  above  straight  line  program  [10Xprg[110X  returns  –for  [13Xany[113X  list  of input
  generators– an empty list.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XStraightLineProgram( [ [1,2,2,3], [3,-1] ] );[127X[104X
    [4X[28Xfail[128X[104X
    [4X[25Xgap>[125X [27Xprg:= StraightLineProgram( [ [1,2,2,3], [3,-1] ], 2 );[127X[104X
    [4X[28X<straight line program>[128X[104X
    [4X[25Xgap>[125X [27XLinesOfStraightLineProgram( prg );[127X[104X
    [4X[28X[ [ 1, 2, 2, 3 ], [ 3, -1 ] ][128X[104X
    [4X[25Xgap>[125X [27Xprg:= StraightLineProgram( "(a^2b^3)^-1", [ "a", "b" ] );[127X[104X
    [4X[28X<straight line program>[128X[104X
    [4X[25Xgap>[125X [27XLinesOfStraightLineProgram( prg );[127X[104X
    [4X[28X[ [ [ 1, 2, 2, 3 ], 3 ], [ [ 3, -1 ], 4 ] ][128X[104X
    [4X[25Xgap>[125X [27Xres:= ResultOfStraightLineProgram( prg, gens );[127X[104X
    [4X[28Xy^-3*x^-2[128X[104X
    [4X[25Xgap>[125X [27Xres = (x^2 * y^3)^-1;[127X[104X
    [4X[28Xtrue[128X[104X
    [4X[25Xgap>[125X [27XNrInputsOfStraightLineProgram( prg );[127X[104X
    [4X[28X2[128X[104X
    [4X[25Xgap>[125X [27XPrint( prg, "\n" );[127X[104X
    [4X[28XStraightLineProgram( [ [ [ 1, 2, 2, 3 ], 3 ], [ [ 3, -1 ], 4 ] ], 2 )[128X[104X
    [4X[25Xgap>[125X [27XDisplay( prg );[127X[104X
    [4X[28X# input:[128X[104X
    [4X[28Xr:= [ g1, g2 ];[128X[104X
    [4X[28X# program:[128X[104X
    [4X[28Xr[3]:= r[1]^2*r[2]^3;[128X[104X
    [4X[28Xr[4]:= r[3]^-1;[128X[104X
    [4X[28X# return value:[128X[104X
    [4X[28Xr[4][128X[104X
    [4X[25Xgap>[125X [27XIsInternallyConsistent( StraightLineProgramNC( [ [1,2] ] ) );[127X[104X
    [4X[28Xtrue[128X[104X
    [4X[25Xgap>[125X [27XIsInternallyConsistent( StraightLineProgramNC( [ [1,2,3] ] ) );[127X[104X
    [4X[28Xfalse[128X[104X
    [4X[25Xgap>[125X [27Xprg1:= StraightLineProgram( [ [1,1,2,2], [3,3,1,1] ], 2 );;[127X[104X
    [4X[25Xgap>[125X [27Xprg2:= StraightLineProgram( [ [ [1,1,2,2], 2 ], [2,3,1,1] ] );;[127X[104X
    [4X[25Xgap>[125X [27Xres1:= ResultOfStraightLineProgram( prg1, gens );[127X[104X
    [4X[28X(x*y^2)^3*x[128X[104X
    [4X[25Xgap>[125X [27Xres1 = (x*y^2)^3*x;[127X[104X
    [4X[28Xtrue[128X[104X
    [4X[25Xgap>[125X [27Xres2:= ResultOfStraightLineProgram( prg2, gens );[127X[104X
    [4X[28X(x*y^2)^3*x[128X[104X
    [4X[25Xgap>[125X [27Xres2 = (x*y^2)^3*x;[127X[104X
    [4X[28Xtrue[128X[104X
    [4X[25Xgap>[125X [27Xprg:= StraightLineProgram( [ [2,3], [ [3,1,1,4], [1,2,3,1] ] ], 2 );;[127X[104X
    [4X[25Xgap>[125X [27Xres:= ResultOfStraightLineProgram( prg, gens );[127X[104X
    [4X[28X[ y^3*x^4, x^2*y^3 ][128X[104X
  [4X[32X[104X
  
  [1X37.8-6 StringOfResultOfStraightLineProgram[101X
  
  [29X[2XStringOfResultOfStraightLineProgram[102X( [3Xprog[103X, [3Xgensnames[103X[, [3X"LaTeX"[103X] ) [32X function
  
  [33X[0;0Y[2XStringOfResultOfStraightLineProgram[102X  returns  a  string  that  describes the
  result  of  the  straight  line program (see [2XIsStraightLineProgram[102X ([14X37.8-1[114X))
  [3Xprog[103X as word(s) in terms of the strings in the list [3Xgensnames[103X. If the result
  of    [3Xprog[103X    is    a    single   element   then   the   return   value   of
  [2XStringOfResultOfStraightLineProgram[102X is a string consisting of the entries of
  [3Xgensnames[103X,  opening  and  closing brackets [10X([110X and [10X)[110X, and powering by integers
  via  [10X^[110X. If the result of [3Xprog[103X is a list of elements then the return value of
  [2XStringOfResultOfStraightLineProgram[102X  is  a  comma separated concatenation of
  the strings of the single elements, enclosed in square brackets [10X[[110X, [10X][110X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xprg:= StraightLineProgram( [ [ 1, 2, 2, 3 ], [ 3, -1 ] ], 2 );;[127X[104X
    [4X[25Xgap>[125X [27XStringOfResultOfStraightLineProgram( prg, [ "a", "b" ] );[127X[104X
    [4X[28X"(a^2b^3)^-1"[128X[104X
    [4X[25Xgap>[125X [27XStringOfResultOfStraightLineProgram( prg, [ "a", "b" ], "LaTeX" );[127X[104X
    [4X[28X"(a^{2}b^{3})^{-1}"[128X[104X
  [4X[32X[104X
  
  [1X37.8-7 CompositionOfStraightLinePrograms[101X
  
  [29X[2XCompositionOfStraightLinePrograms[102X( [3Xprog2[103X, [3Xprog1[103X ) [32X function
  
  [33X[0;0YFor      two     straight     line     programs     [3Xprog1[103X     and     [3Xprog2[103X,
  [2XCompositionOfStraightLinePrograms[102X  returns a straight line program [3Xprog[103X with
  the  properties  that [3Xprog1[103X and [3Xprog[103X have the same number of inputs, and the
  result  of  [3Xprog[103X  when applied to given generators [3Xgens[103X equals the result of
  [3Xprog2[103X when this is applied to the output of [3Xprog1[103X applied to [3Xgens[103X.[133X
  
  [33X[0;0Y(Of  course the number of outputs of [3Xprog1[103X must be the same as the number of
  inputs of [3Xprog2[103X.)[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xprg1:= StraightLineProgram( "a^2b", [ "a","b" ] );;[127X[104X
    [4X[25Xgap>[125X [27Xprg2:= StraightLineProgram( "c^5", [ "c" ] );;[127X[104X
    [4X[25Xgap>[125X [27Xcomp:= CompositionOfStraightLinePrograms( prg2, prg1 );[127X[104X
    [4X[28X<straight line program>[128X[104X
    [4X[25Xgap>[125X [27XStringOfResultOfStraightLineProgram( comp, [ "a", "b" ] );[127X[104X
    [4X[28X"(a^2b)^5"[128X[104X
    [4X[25Xgap>[125X [27Xprg:= StraightLineProgram( [ [2,3], [ [3,1,1,4], [1,2,3,1] ] ], 2 );;[127X[104X
    [4X[25Xgap>[125X [27XStringOfResultOfStraightLineProgram( prg, [ "a", "b" ] );[127X[104X
    [4X[28X"[ b^3a^4, a^2b^3 ]"[128X[104X
    [4X[25Xgap>[125X [27Xcomp:= CompositionOfStraightLinePrograms( prg, prg );[127X[104X
    [4X[28X<straight line program>[128X[104X
    [4X[25Xgap>[125X [27XStringOfResultOfStraightLineProgram( comp, [ "a", "b" ] );[127X[104X
    [4X[28X"[ (a^2b^3)^3(b^3a^4)^4, (b^3a^4)^2(a^2b^3)^3 ]"[128X[104X
  [4X[32X[104X
  
  [1X37.8-8 IntegratedStraightLineProgram[101X
  
  [29X[2XIntegratedStraightLineProgram[102X( [3Xlistofprogs[103X ) [32X function
  
  [33X[0;0YFor  a  nonempty  dense list [3Xlistofprogs[103X of straight line programs that have
  the   same  number  [22Xn[122X,  say,  of  inputs  (see [2XNrInputsOfStraightLineProgram[102X
  ([14X37.8-4[114X))   and   for  which  the  results  (see [2XResultOfStraightLineProgram[102X
  ([14X37.8-5[114X))   are   single   elements   (i.e.,   [13Xnot[113X   lists   of   elements),
  [2XIntegratedStraightLineProgram[102X  returns  a  straight line program [3Xprog[103X with [22Xn[122X
  inputs    such    that    for    each    [22Xn[122X-tuple    [3Xgens[103X    of   generators,
  [10XResultOfStraightLineProgram(  [3Xprog[103X[10X,  [3Xgens[103X[10X  )[110X  is  equal  to  the  list [10XList(
  [3Xlistofprogs[103X[10X, [3Xp[103X[10X -> ResultOfStraightLineProgram( [3Xp[103X[10X, [3Xgens[103X[10X )[110X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xf:= FreeGroup( "x", "y" );;  gens:= GeneratorsOfGroup( f );;[127X[104X
    [4X[25Xgap>[125X [27Xprg1:= StraightLineProgram([ [ [ 1, 2 ], 1 ], [ 1, 2, 2, -1 ] ], 2);;[127X[104X
    [4X[25Xgap>[125X [27Xprg2:= StraightLineProgram([ [ [ 2, 2 ], 3 ], [ 1, 3, 3, 2 ] ], 2);;[127X[104X
    [4X[25Xgap>[125X [27Xprg3:= StraightLineProgram([ [ 2, 2 ], [ 1, 3, 3, 2 ] ], 2);;[127X[104X
    [4X[25Xgap>[125X [27Xprg:= IntegratedStraightLineProgram( [ prg1, prg2, prg3 ] );;[127X[104X
    [4X[25Xgap>[125X [27XResultOfStraightLineProgram( prg, gens );[127X[104X
    [4X[28X[ x^4*y^-1, x^3*y^4, x^3*y^4 ][128X[104X
    [4X[25Xgap>[125X [27Xprg:= IntegratedStraightLineProgram( [ prg2, prg3, prg1 ] );;[127X[104X
    [4X[25Xgap>[125X [27XResultOfStraightLineProgram( prg, gens );[127X[104X
    [4X[28X[ x^3*y^4, x^3*y^4, x^4*y^-1 ][128X[104X
    [4X[25Xgap>[125X [27Xprg:= IntegratedStraightLineProgram( [ prg3, prg1, prg2 ] );;[127X[104X
    [4X[25Xgap>[125X [27XResultOfStraightLineProgram( prg, gens );[127X[104X
    [4X[28X[ x^3*y^4, x^4*y^-1, x^3*y^4 ][128X[104X
  [4X[32X[104X
  
  [1X37.8-9 RestrictOutputsOfSLP[101X
  
  [29X[2XRestrictOutputsOfSLP[102X( [3Xslp[103X, [3Xk[103X ) [32X function
  
  [33X[0;0Y[3Xslp[103X  must  be  a  straight  line  program  returning a tuple of values. This
  function  returns  a new slp that calculates only those outputs specified by
  [3Xk[103X.  The  argument  [3Xk[103X  may  be  an  integer or a list of integers. If [3Xk[103X is an
  integer,  the  resulting  slp calculates only the result with that number in
  the  original  output  tuple.  If [3Xk[103X is a list of integers, the resulting slp
  calculates  those  results  with  indices [3Xk[103X in the original output tuple. In
  both cases the resulting slp does only what is necessary. Obviously, the slp
  must  have  a line with enough expressions (lists) for the supplied [3Xk[103X as its
  last  line.  [3Xslp[103X  is  either  an slp or a pair where the first entry are the
  lines of the slp and the second is the number of inputs.[133X
  
  [1X37.8-10 IntermediateResultOfSLP[101X
  
  [29X[2XIntermediateResultOfSLP[102X( [3Xslp[103X, [3Xk[103X ) [32X function
  
  [33X[0;0YReturns a new slp that calculates only the value of slot [3Xk[103X at the end of [3Xslp[103X
  doing only what is necessary. slp is either an slp or a pair where the first
  entry  are the lines of the slp and the second is the number of inputs. Note
  that  this assumes a general SLP with possible overwriting. If you know that
  your      SLP      does      not     overwrite     slots,     please     use
  [2XIntermediateResultOfSLPWithoutOverwrite[102X  ([14X37.8-11[114X),  which is much faster in
  this case.[133X
  
  [1X37.8-11 IntermediateResultOfSLPWithoutOverwrite[101X
  
  [29X[2XIntermediateResultOfSLPWithoutOverwrite[102X( [3Xslp[103X, [3Xk[103X ) [32X function
  
  [33X[0;0YReturns a new slp that calculates only the value of slot [3Xk[103X, which must be an
  integer.  Note  that  [3Xslp[103X  must  not  overwrite slots but only append!!! Use
  [2XIntermediateResultOfSLP[102X ([14X37.8-10[114X) in the other case! [3Xslp[103X is either an slp or
  a  pair  where the first entry is the lines of the slp and the second is the
  number of inputs.[133X
  
  [1X37.8-12 IntermediateResultsOfSLPWithoutOverwrite[101X
  
  [29X[2XIntermediateResultsOfSLPWithoutOverwrite[102X( [3Xslp[103X, [3Xk[103X ) [32X function
  
  [33X[0;0YReturns  a  new slp that calculates only the value of slots contained in the
  list  k.  Note  that  [3Xslp[103X  must  not  overwrite slots but only append!!! Use
  [2XIntermediateResultOfSLP[102X  ([14X37.8-10[114X) in the other case! [3Xslp[103X is either a slp or
  a  pair  where the first entry is the lines of the slp and the second is the
  number of inputs.[133X
  
  [1X37.8-13 ProductOfStraightLinePrograms[101X
  
  [29X[2XProductOfStraightLinePrograms[102X( [3Xs1[103X, [3Xs2[103X ) [32X function
  
  [33X[0;0Y[3Xs1[103X and [3Xs2[103X must be two slps that return a single element with the same number
  of  inputs.  This function constructs an slp that returns the product of the
  two results the slps [3Xs1[103X and [3Xs2[103X would produce with the same input.[133X
  
  [1X37.8-14 SlotUsagePattern[101X
  
  [29X[2XSlotUsagePattern[102X( [3Xs[103X ) [32X attribute
  
  [33X[0;0YAnalyses  the  straight  line  program [3Xs[103X for more efficient evaluation. This
  means  in particular two things, when this attribute is known: First of all,
  intermediate results which are not actually needed later on are not computed
  at  all,  and  once an intermediate result is used for the last time in this
  SLP,  it  is  discarded. The latter leads to the fact that the evaluation of
  the SLP needs less memory.[133X
  
  
  [1X37.9 [33X[0;0YStraight Line Program Elements[133X[101X
  
  [33X[0;0YWhen  computing  with  very large (in terms of memory) elements, for example
  permutations  of degree a few hundred thousands, it can be helpful (in terms
  of memory usage) to represent them via straight line programs in terms of an
  original generator set. (So every element takes only small extra storage for
  the straight line program.)[133X
  
  [33X[0;0YA  straight line program element has a [13Xseed[113X (a list of group elements) and a
  straight line program on the same number of generators as the length of this
  seed, its value is the value of the evaluated straight line program.[133X
  
  [33X[0;0YAt  the  moment,  the entries of the straight line program have to be simple
  lists (i.e. of the first form).[133X
  
  [33X[0;0YStraight  line  program  elements are in the same categories and families as
  the  elements  of  the  seed,  so  they  should  work together with existing
  algorithms.[133X
  
  [33X[0;0YNote  however,  that  due to the different way of storage some normally very
  cheap  operations  (such  as  testing  for element equality) can become more
  expensive  when  dealing  with  straight  line  program  elements.  This  is
  essentially the tradeoff for using less memory.[133X
  
  [33X[0;0YSee also Section [14X43.13[114X.[133X
  
  [1X37.9-1 IsStraightLineProgElm[101X
  
  [29X[2XIsStraightLineProgElm[102X( [3Xobj[103X ) [32X Representation
  
  [33X[0;0YA  straight  line  program  element  is  a  group  element given (for memory
  reasons)  as  a  straight  line  program. Straight line program elements are
  positional  objects, the first component is a record with a component [10Xseeds[110X,
  the second component the straight line program.[133X
  
  [1X37.9-2 StraightLineProgElm[101X
  
  [29X[2XStraightLineProgElm[102X( [3Xseed[103X, [3Xprog[103X ) [32X function
  
  [33X[0;0YCreates a straight line program element for seed [3Xseed[103X and program [3Xprog[103X.[133X
  
  [1X37.9-3 StraightLineProgGens[101X
  
  [29X[2XStraightLineProgGens[102X( [3Xgens[103X[, [3Xbase[103X] ) [32X function
  
  [33X[0;0Yreturns  a  set  of  straight  line  program  elements  corresponding to the
  generators  in [3Xgens[103X. If [3Xgens[103X is a set of permutations then [3Xbase[103X can be given
  which  must  be a base for the group generated by [3Xgens[103X. (Such a base will be
  used to speed up equality tests.)[133X
  
  [1X37.9-4 EvalStraightLineProgElm[101X
  
  [29X[2XEvalStraightLineProgElm[102X( [3Xslpel[103X ) [32X function
  
  [33X[0;0Yevaluates a straight line program element [3Xslpel[103X from its seeds.[133X
  
  [1X37.9-5 StretchImportantSLPElement[101X
  
  [29X[2XStretchImportantSLPElement[102X( [3Xelm[103X ) [32X operation
  
  [33X[0;0YIf [3Xelm[103X is a straight line program element whose straight line representation
  is very long, this operation changes the representation of [3Xelm[103X to a straight
  line  program  element,  equal to [3Xelm[103X, whose seed contains the evaluation of
  [3Xelm[103X and whose straight line program has length 1.[133X
  
  [33X[0;0YFor other objects nothing happens.[133X
  
  [33X[0;0YThis  operation  permits to designate [21Ximportant[121X elements within an algorithm
  (elements  that  will  be  referred  to often), which will be represented by
  guaranteed short straight line program elements.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xgens:=StraightLineProgGens([(1,2,3,4),(1,2)]);[127X[104X
    [4X[28X[ <[ [ 2, 1 ] ]|(1,2,3,4)>, <[ [ 1, 1 ] ]|(1,2)> ][128X[104X
    [4X[25Xgap>[125X [27Xg:=Group(gens);;[127X[104X
    [4X[25Xgap>[125X [27X(gens[1]^3)^gens[2];[127X[104X
    [4X[28X<[ [ 1, -1, 2, 3, 1, 1 ] ]|(1,2,4,3)>[128X[104X
    [4X[25Xgap>[125X [27XSize(g);[127X[104X
    [4X[28X24[128X[104X
    [4X[25Xgap>[125X [27XRandom(g);[127X[104X
    [4X[28X<[128X[104X
    [4X[28X[ [ 1, -1, 2, -1, 1, 1, 2, -1, 1, -1, 2, 1, 1, 1, 2, 1, 1, -1, 2, 2, [128X[104X
    [4X[28X      1, 1 ], [128X[104X
    [4X[28X  [ 3, -2, 2, -2, 1, -1, 2, -2, 1, 1, 2, -1, 1, -1, 2, -2, 1, 1, 2, [128X[104X
    [4X[28X      -1, 1, -1, 2, -1, 1, 1, 2, 1, 1, -1, 2, 1, 1, 1 ] ]>[128X[104X
  [4X[32X[104X
  
