  
  [1X4 Monoid Polynomials[0X
  
  This  chapter  describes  functions  to  compute  with  elements  of  a free
  noncommutative  algebra.  The  elements  of the algebra are sums of rational
  multiples  of  words  in a free monoid. These are called [13Xmonoid polynomials[0m,
  and are stored as lists of pairs [10X[coefficient, word][0m.
  
  
  [1X4.1 Construction of monoid polynomials[0X
  
  [1X4.1-1 MonoidPolyFromCoeffsWords[0m
  
  [2X> MonoidPolyFromCoeffsWords( [0X[3Xcoeffs, words[0X[2X ) ______________________[0Xoperation
  [2X> MonoidPoly( [0X[3Xterms[0X[2X ) _____________________________________________[0Xoperation
  [2X> ZeroMonoidPoly( [0X[3XF[0X[2X ) _____________________________________________[0Xoperation
  
  There are two ways to input a monoid polynomial: by listing the coefficients
  and then the words; or by listing the terms as a list of pairs [10X[coefficient,
  word][0m.  If  a word occurs more than once in the input list, the coefficients
  will  be  added  so  that the terms of the monoid polynomial recorded do not
  contain any duplicates. The zero monoid polynomial is the polynomial with no
  terms.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> rels := RelatorsOfFpGroup( q8 );[0X
    [4X[ f1^4, f2^4, f1*f2*f1*f2^-1, f1^2*f2^2 ] [0X
    [4Xgap> freeq8 := FreeGroupOfFpGroup( q8 );; [0X
    [4Xgap> gens := GeneratorsOfGroup( freeq8 );;[0X
    [4Xgap> famfree := ElementsFamily( FamilyObj( freeq8 ) );;[0X
    [4Xgap> famfree!.monoidPolyFam := MonoidPolyFam;;[0X
    [4Xgap> cg := [6,7];; [0X
    [4Xgap> pg := MonoidPolyFromCoeffsWords( cg, gens );; [0X
    [4Xgap> Display( pg ); [0X
    [4X7*f2 + 6*f1[0X
    [4Xgap> cr := [3,4,-5,-2];;[0X
    [4Xgap> pr := MonoidPolyFromCoeffsWords( cr, rels );; [0X
    [4Xgap> Display( pr );[0X
    [4X4*f2^4 - 5*f1*f2*f1*f2^-1 - 2*f1^2*f2^2 + 3*f1^4[0X
    [4Xgap> Display( ZeroMonoidPoly( freeq8 ) );[0X
    [4Xzero monpoly[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  
  [1X4.2 Components of a polynomial[0X
  
  [1X4.2-1 Terms[0m
  
  [2X> Terms( [0X[3Xpoly[0X[2X ) ___________________________________________________[0Xattribute
  [2X> Coeffs( [0X[3Xpoly[0X[2X ) __________________________________________________[0Xattribute
  [2X> Words( [0X[3Xpoly[0X[2X ) ___________________________________________________[0Xattribute
  [2X> LeadTerm( [0X[3Xpoly[0X[2X ) ________________________________________________[0Xattribute
  [2X> LeadCoeffMonoidPoly( [0X[3Xpoly[0X[2X ) _____________________________________[0Xattribute
  
  The  function  [10XTerms[0m returns the terms of a polynomial as a list of pairs of
  the  form  [10X[word, coefficient][0m. The function [10XCoeffs[0m returns the coefficients
  of  a  polynomial  as  a list, and the function [10XWords[0m returns the words of a
  polynomial  as  a  list.  The  function  [10XLeadTerm[0m  returns  the  term of the
  polynomial  whose  word  component  is  the  largest  with  respect  to  the
  length-lexicographical  ordering.  The  function [10XLeadCoeffMonoidPoly[0m returns
  the coefficient of the leading term of a polynomial.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> Coeffs( pr );[0X
    [4X[ 4, -5, -2, 3 ][0X
    [4Xgap> Terms( pr );[0X
    [4X[ [ 4, f2^4 ], [ -5, f1*f2*f1*f2^-1 ], [ -2, f1^2*f2^2 ], [ 3, f1^4 ] ][0X
    [4Xgap> Words( pr );[0X
    [4X[ f2^4, f1*f2*f1*f2^-1, f1^2*f2^2, f1^4 ][0X
    [4Xgap> LeadTerm( pr );[0X
    [4X[ 4, f2^4][0X
    [4Xgap> LeadCoeffMonoidPoly( pr );[0X
    [4X4[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  [1X4.2-2 Monic[0m
  
  [2X> Monic( [0X[3Xpoly[0X[2X ) ___________________________________________________[0Xoperation
  
  A  monoid  polynomial  is  called  [13Xmonic[0m  if  the coefficient of its leading
  polynomial  is  one.  The  function [10XMonic[0m converts a polynomial into a monic
  polynomial by dividing all the coefficients by the leading coefficient.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> mpr := Monic( pr );;[0X
    [4Xgap> Display( mpr );[0X
    [4Xf2^4 - 5/4*f1*f2*f1*f2^-1 - 1/2*f1^2*f2^2 + 3/4*f1^4[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  [1X4.2-3 AddTermMonoidPoly[0m
  
  [2X> AddTermMonoidPoly( [0X[3Xpoly, coeff, word[0X[2X ) __________________________[0Xoperation
  
  The  function  [10XAddTermMonoidPoly[0m  adds a new term, given by its coeffiecient
  and word, to an existing polynomial.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> w := gens[1]^gens[2];[0X
    [4Xf2^-1*f1*f2[0X
    [4Xgap> cw := 3/4;;[0X
    [4Xgap> wpg:= AddTermMonoidPoly( pg, cw, w);;[0X
    [4Xgap> Display( wpg );[0X
    [4X3/4*f2^-1*f1*f2 + 7*f2 + 6*f1[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  
  [1X4.3 Monoid Polynomial Operations[0X
  
  Tests for equality and arithmetic operations are performed in the usual way.
  
  The  operation [10Xpoly1 = poly2[0m returns [10Xtrue[0m if the monoid polynomials have the
  same  terms,  and [10Xfalse[0m otherwise. Multiplication of a monoid polynomial (on
  the  left  or  right)  by  a coefficient; the addition or subtraction of two
  monoid  polynomials; multiplication (on the right) of a monoid polynomial by
  a word; and multiplication of two monoid polynomials; are all implemented.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> [ pg = pg, pg = pr ];[0X
    [4X[ true, false ][0X
    [4Xgap> prcw := pr*cw;;[0X
    [4Xgap> Display( prcw );[0X
    [4X3*f2^4 - 15/4*f1*f2*f1*f2^-1 - 3/2*f1^2*f2^2 + 9/4*f1^4[0X
    [4Xgap> cwpr := cw*pr;; [0X
    [4Xgap> Display( cwpr ); [0X
    [4X3*f2^4 - 15/4*f1*f2*f1*f2^-1 - 3/2*f1^2*f2^2 + 9/4*f1^4[0X
    [4Xgap> [ pr = prcw, prcw = cwpr ];[0X
    [4X[ false, true ] [0X
    [4Xgap> Display( pg + pr );[0X
    [4X4*f2^4 - 5*f1*f2*f1*f2^-1 - 2*f1^2*f2^2 + 3*f1^4 + 7*f2 + 6*f1 [0X
    [4Xgap> Display( pg - pr );[0X
    [4X- 4*f2^4 + 5*f1*f2*f1*f2^-1 + 2*f1^2*f2^2 - 3*f1^4 + 7*f2 + 6*f1[0X
    [4Xgap> Display( pg * w );[0X
    [4X6*f1*f2^-1*f1*f2 + 7*f1*f2 [0X
    [4Xgap> Display( pg * pr );[0X
    [4X28*f2^5 - 35*f2*f1*f2*f1*f2^-1 - 14*f2*f1^2*f2^2 + 21*f2*f1^4 [0X
    [4X+ 24*f1*f2^4 - 30*f1^2*f2*f1*f2^-1 - 12*f1^3*f2^2 + 18*f1^5 [0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  [1X4.3-1 Length[0m
  
  [2X> Length( [0X[3Xpoly[0X[2X ) __________________________________________________[0Xattribute
  
  This function returns the number of distinct terms in the monoid polynomial.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> Length( pr );[0X
    [4X4[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  The  boolean function [10Xpoly1 > poly2[0m returns [10Xtrue[0m if the first polynomial has
  more  terms  than the second. If the polynomials are the same length it will
  compare   their  leading  terms.  If  the  leading  word  of  the  first  is
  lengthlexicographically  greater  than the leading word of the second, or if
  the  words  are  equal  but the coefficient of the first is greater than the
  coefficient  of  the  second then true is returned. If the leading terms are
  equal then the next terms are compared in the same way. If all terms are the
  same then [10Xfalse[0m is returned.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> [ pr > 3*pr, pr > pg ];[0X
    [4X[ false, true ] [0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  
  [1X4.4 Reduction of a Monoid Polynomial[0X
  
  [1X4.4-1 ReduceMonoidPoly[0m
  
  [2X> ReduceMonoidPoly( [0X[3Xpoly, rules[0X[2X ) _________________________________[0Xoperation
  
  Recall  that the words of a monoid polynomial are elements of a free monoid.
  Given  a  rewrite  system (set of rules) on the free monoid the words can be
  reduced.  This  allows  us to simulate calculation in monoid rings where the
  monid  is  given by a complete presentation. This function reduces the words
  of the polynomial (elements of the free monoid) with respect to the complete
  rewrite system. The words of the reduced polynomial are normal forms for the
  elements of the monoid presented by that rewite system. The list of rules [10Xr2[0m
  is displayed in section 2.3.3.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> M := genfgmon;;[0X
    [4Xgap> mp1 := MonoidPolyFromCoeffsWords( [9,-7,5], [M[1]*M[3], M[2]^3, M[4]*M[3]*M[2]] );; [0X
    [4Xgap> Display( mp1 ); [0X
    [4X5*q8_M4*q8_M3*q8_M2 - 7*q8_M2^3 + 9*q8_M1*q8_M3[0X
    [4Xgap> rmp1 := ReduceMonoidPoly( mp1, r2 );;[0X
    [4Xgap> Display( rmp1 ); [0X
    [4X - 7*q8_M4 + 5*q8_M1 + 9*<identity ...>[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
