  
  [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  will  be  called  monoid
  polynomials, and are stored as lists of pairs [10X[coefficient, word][0X.
  
  
  [1X4.1 Construction of monoid polynomials[0X
  
  [1X4.1-1 MonoidPolyFromCoeffsWords[0X
  
  [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  possible ways to input a monoid polynomial. The first is by
  listing  the  coefficients  and then the words; the second is by listing the
  terms  as  a  list  of pairs [10X[coefficient, word][0X. Note that 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
    [4XGroup( [f1, f2] )[0X
    [4Xgap> gens := GeneratorsOfGroup( freeq8 );;[0X
    [4Xgap> famfree := ElementsFamily( FamilyObj( freeq8 ) );[0X
    [4XNewFamily( "FreeGroupElementsFamily", [ 125, 144, 989 ], [0X
    [4X[ 76, 77, 78, 79, 111, 114, 117, 121, 125, 144, 989 ] )[0X
    [4Xgap> famfree!.monoidPolyFam := MonoidPolyFam;[0X
    [4XNewFamily( "MonoidPolyFam", [ 2416 ], [ 111, 114, 117, 2416 ] )[0X
    [4Xgap> cg := [6,7];[0X
    [4X[ 6, 7 ][0X
    [4Xgap> cr := [3,4,-5,-2];[0X
    [4X[ 3, 4, -5, -2 ][0X
    [4Xgap> pg := MonoidPolyFromCoeffsWords( cg, gens );[0X
    [4X<monpoly> [0X
    [4Xgap> Print( pg );[0X
    [4X7*f2 + 6*f1 [0X
    [4Xgap> pr := MonoidPolyFromCoeffsWords( cr, rels );[0X
    [4X<monpoly> [0X
    [4Xgap> Print( pr );[0X
    [4X4*f2^4 - 5*f1*f2*f1*f2^-1 - 2*f1^2*f2^2 + 3*f1^4[0X
    [4Xgap> zeromp := ZeroMonoidPoly( freeq8 );[0X
    [4X<monpoly> [0X
    [4Xgap> Print( zeromp);[0X
    [4Xzero monpoly [0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  
  [1X4.2 Components of a polynomial[0X
  
  [1X4.2-1 Terms[0X
  
  [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[0X returns the terms of a polynomial as a list of pairs of
  the  form  [10X[word, coefficient][0X. The function [10XCoeffs[0X returns the coefficients
  of  a  polynomial  as  a list, and the function [10XWords[0X returns the words of a
  polynomial  as  a  list.  The  function  [10XLeadTerm[0X  returns  the  term of the
  polynomial  whose  word  component  is  the  largest  with  respect  to  the
  length-lexicographical  ordering.  The  function [10XLeadCoeffMonoidPoly[0X 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[0X
  
  [2X> Monic( [0X[3Xpoly[0X[2X ) ___________________________________________________[0Xoperation
  
  A  monoid  polynomial  is  called  [13Xmonic[0X  if  the coefficient of its leading
  polynomial  is  one.  The  function [10XMonic[0X 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> Print( 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[0X
  
  [2X> AddTermMonoidPoly( [0X[3Xpoly, coeff, word[0X[2X ) __________________________[0Xoperation
  
  The  function  [10XAddTermMonoidPoly[0X  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
    [4X<monpoly> [0X
    [4Xgap> Print( 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[0X returns [10Xtrue[0X if the monoid polynomials have the
  same  terms,  and [10Xfalse[0X 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;[0X
    [4Xtrue [0X
    [4Xgap> pg = pr;[0X
    [4Xfalse [0X
    [4Xgap> prcw := pr*cw;[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
    [4X3*f2^4 - 15/4*f1*f2*f1*f2^-1 - 3/2*f1^2*f2^2 + 9/4*f1^4[0X
    [4Xgap> pr = prcw;[0X
    [4Xfalse [0X
    [4Xgap> prcw = cwpr;[0X
    [4Xtrue [0X
    [4Xgap> Print( 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> Print( 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> Print( pg * w );[0X
    [4X6*f1*f2^-1*f1*f2 + 7*f1*f2 [0X
    [4Xgap> Print( 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[0X
  
  [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[0X returns [10Xtrue[0X 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[0X is returned.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> pol > 3*pol;[0X
    [4Xfalse [0X
    [4Xgap> pol > redpol;[0X
    [4Xtrue[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  
  [1X4.4 Reduction of a Monoid Polynomial[0X
  
  [1X4.4-1 ReduceMonoidPoly[0X
  
  [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.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> M := genfgmon;[0X
    [4X[ q8_Ml, q8_M2, q8_M3, q8_M4 ] [0X
    [4Xgap> r2;[0X
    [4X[ q8_Ml*q8_M3, <identity ...>], [ q8_M2*q8_Ml, q8_Ml*q8_M4 ], [0X
    [4X  [ q8_M2^2, q8_Ml^2], [ q8_M2*q8_M3, q8_Ml*q8_M2 ], [0X
    [4X  [ q8_M2*q8_M4, <identity ...> ], [ q8_M3*q8_Ml, <identity ...> ], [0X
    [4X  [ q8_M3*q8_M2, q8_Ml*q8_M4], [ q8_M3^2, q8_Ml^2 ], [0X
    [4X  [ q8_M3*q8_M4, q8_Ml*q8_M2], [ q8_M4*q8_Ml, q8_Ml*q8_M2 ], [0X
    [4X  [ q8_M4*q8_M2, <identity ...> ], [ q8_M4*q8_M3, q8_Ml*q8_M4 ], [0X
    [4X  [ q8_M4^2, q8_Ml^2 ], [ q8_Ml^3, q8_M3], [ q8_Ml^2*q8_M2, q8_M4 ], [0X
    [4X  [ q8_Ml^2*q8_M4, q8_M2 ] ] [0X
    [4Xgap> pol := MonoidPolyFromCoeffsWords([3,2,-5], [M[1]*M[3] ,M[2]-4,M[1]]);[0X
    [4X<monpoly> [0X
    [4Xgap> Print( pol );[0X
    [4X2*q8_M2^4 + 3*q8_Ml*q8_M3 - 5*q8_Ml [0X
    [4Xgap> redpol := ReduceMonoidPoly( pol, KBrules );[0X
    [4X<monpoly> [0X
    [4Xgap> Print( redpol );[0X
    [4X- 5*q8_Ml + 5*<identity ...>[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
