  
  [1X4. Residue-Class-Wise Affine Monoids[0X
  
  In  this  short  chapter, we describe how to compute with residue-class-wise
  affine  monoids.  [13XResidue-class-wise  affine[0X  monoids,  or  [13Xrcwa[0X monoids for
  short, are monoids whose elements are residue-class-wise affine mappings.
  
  
  [1X4.1 Constructing residue-class-wise affine monoids[0X
  
  As  any  other  monoids  in  [5XGAP[0X,  residue-class-wise  affine monoids can be
  constructed by [10XMonoid[0X or [10XMonoidByGenerators[0X.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> M := Monoid(RcwaMapping([[ 0,1,1],[1,1,1]]),[0X
    [4X>                RcwaMapping([[-1,3,1],[0,2,1]]));[0X
    [4X<rcwa monoid over Z with 2 generators>[0X
    [4Xgap> Size(M);[0X
    [4X11[0X
    [4Xgap> Display(MultiplicationTable(M));[0X
    [4X[ [   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11 ], [0X
    [4X  [   2,   8,   5,  11,   8,   3,  10,   5,   2,   8,   5 ], [0X
    [4X  [   3,  10,  11,   5,   5,   5,   8,   8,   8,   2,   3 ], [0X
    [4X  [   4,   9,   6,   8,   8,   8,   5,   5,   5,   7,   4 ], [0X
    [4X  [   5,   8,   5,   8,   8,   8,   5,   5,   5,   8,   5 ], [0X
    [4X  [   6,   7,   4,   8,   8,   8,   5,   5,   5,   9,   6 ], [0X
    [4X  [   7,   5,   8,   6,   5,   4,   9,   8,   7,   5,   8 ], [0X
    [4X  [   8,   5,   8,   5,   5,   5,   8,   8,   8,   5,   8 ], [0X
    [4X  [   9,   5,   8,   4,   5,   6,   7,   8,   9,   5,   8 ], [0X
    [4X  [  10,   8,   5,   3,   8,  11,   2,   5,  10,   8,   5 ], [0X
    [4X  [  11,   2,   3,   5,   5,   5,   8,   8,   8,  10,  11 ] ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  There  are  methods for the operations [10XView[0X, [10XDisplay[0X, [10XPrint[0X and [10XString[0X which
  are  applicable  to  rcwa  monoids.  All  rcwa  monoids  over  a  ring R are
  submonoids  of Rcwa(R). The monoid Rcwa(R) itself is not finitely generated,
  thus  cannot  be  constructed as described above. It is handled as a special
  case:
  
  [1X4.1-1 Rcwa[0X
  
  [2X> Rcwa( [0X[3XR[0X[2X ) ________________________________________________________[0Xfunction
  [6XReturns:[0X  The  monoid  Rcwa([3XR[0X)  of all residue-class-wise affine mappings of
            the ring [3XR[0X.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> RcwaZ := Rcwa(Integers);[0X
    [4XRcwa(Z)[0X
    [4Xgap> IsSubset(RcwaZ,M);[0X
    [4Xtrue[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  In  our  methods  to  construct  rcwa groups, two kinds of mappings played a
  crucial role, namely the restriction monomorphisms (cp. [2XRestriction[0X ([14X3.1-6[0X))
  and  the  induction  epimorphisms  (cp. [2XInduction[0X  ([14X3.1-7[0X)). The restriction
  monomorphisms  extend  in  a  natural  way  to  the monoids Rcwa(R), and the
  induction  epimorphisms  have corresponding generalizations, also. Therefore
  the  operations  [10XRestriction[0X and [10XInduction[0X can be applied to rcwa monoids as
  well:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> M2 := Restriction(M,2*One(Rcwa(Integers)));[0X
    [4X<rcwa monoid over Z with 2 generators, of size 11>[0X
    [4Xgap> Support(M2);[0X
    [4X0(2)[0X
    [4Xgap> Action(M2,ResidueClass(1,2));[0X
    [4XTrivial rcwa group over Z[0X
    [4Xgap> Induction(M2,2*One(Rcwa(Integers))) = M;[0X
    [4Xtrue[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  
  [1X4.2 Computing with residue-class-wise affine monoids[0X
  
  There  is  a  method  for  [10XSize[0X  which computes the order of an rcwa monoid.
  Further  there  is a method for [10Xin[0X which checks whether a given rcwa mapping
  lies  in  a  given  rcwa monoid (membership test), and there is a method for
  [10XIsSubset[0X which checks for a submonoid relation.
  
  There  are  also methods for [10XSupport[0X, [10XModulus[0X, [10XIsTame[0X, [10XPrimeSet[0X, [10XIsIntegral[0X,
  [10XIsClassWiseOrderPreserving[0X and [10XIsSignPreserving[0X available for rcwa monoids.
  
  The  [13Xsupport[0X of an rcwa monoid is the union of the supports of its elements.
  The  [13Xmodulus[0X  of  an rcwa monoid is the lcm of the moduli of its elements in
  case  such  an  lcm exists and 0 otherwise. An rcwa monoid is called [13Xtame[0X if
  its  modulus is nonzero, and [13Xwild[0X otherwise. The [13Xprime set[0X of an rcwa monoid
  is  the  union  of  the prime sets of its elements. An rcwa monoid is called
  [13Xintegral[0X,  [13Xclass-wise  order-preserving[0X  or  [13Xsign-preserving[0X  if  all of its
  elements are so.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> f1 := RcwaMapping([[-1, 1, 1],[ 0,-1, 1]]);;[0X
    [4Xgap> f2 := RcwaMapping([[ 1,-1, 1],[-1,-2, 1],[-1, 2, 1]]);; [0X
    [4Xgap> f3 := RcwaMapping([[ 1, 0, 1],[-1, 0, 1]]);; [0X
    [4Xgap> N := Monoid(f1,f2,f3);;[0X
    [4Xgap> Size(N);[0X
    [4X366[0X
    [4Xgap> List([Monoid(f1,f2),Monoid(f1,f3),Monoid(f2,f3)],Size);[0X
    [4X[ 96, 6, 66 ][0X
    [4Xgap> f1*f2*f3 in N;[0X
    [4Xtrue[0X
    [4Xgap> IsSubset(N,M);[0X
    [4Xfalse[0X
    [4Xgap> IsSubset(N,Monoid(f1*f2,f3*f2));[0X
    [4Xtrue[0X
    [4Xgap> Support(N);[0X
    [4XIntegers[0X
    [4Xgap> Modulus(N);[0X
    [4X6[0X
    [4Xgap> IsTame(N) and IsIntegral(N);[0X
    [4Xtrue[0X
    [4Xgap> IsClassWiseOrderPreserving(N) or IsSignPreserving(N);[0X
    [4Xfalse[0X
    [4Xgap> Collected(List(AsList(N),Image)); # The images of the elements of N.[0X
    [4X[ [ Integers, 2 ], [ 1(2), 2 ], [ Z \ 1(3), 32 ], [ 0(6), 44 ], [0X
    [4X  [ 0(6) U 1(6), 4 ], [ Z \ 4(6) U 5(6), 32 ], [ 0(6) U 2(6), 4 ], [0X
    [4X  [ 0(6) U 5(6), 4 ], [ 1(6), 44 ], [ 1(6) U [ -1 ], 2 ], [ 1(6) U 3(6), 4 ], [0X
    [4X  [ 1(6) U 5(6), 40 ], [ 2(6), 44 ], [ 2(6) U 3(6), 4 ], [ 3(6), 44 ], [0X
    [4X  [ 3(6) U 5(6), 4 ], [ 5(6), 44 ], [ 5(6) U [ 1 ], 2 ], [ [ -5 ], 1 ], [0X
    [4X  [ [ -4 ], 1 ], [ [ -3 ], 1 ], [ [ -1 ], 1 ], [ [ 0 ], 1 ], [ [ 1 ], 1 ], [0X
    [4X  [ [ 2 ], 1 ], [ [ 3 ], 1 ], [ [ 5 ], 1 ], [ [ 6 ], 1 ] ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Finite forward orbits under the action of an rcwa monoid can be found by the
  operation [10XShortOrbits[0X:
  
  [1X4.2-1 ShortOrbits[0X
  
  [2X> ShortOrbits( [0X[3XM, S, maxlng[0X[2X ) ________________________________________[0Xmethod
  [6XReturns:[0X  A  list of finite forward orbits of the rcwa monoid [3XM[0X of length at
            most [3Xmaxlng[0X which start at points in the set [3XS[0X.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> ShortOrbits(M,[-5..5],20);[0X
    [4X[ [ -5, -4, 1, 2, 7, 8 ], [ -3, -2, 1, 2, 5, 6 ], [ -1, 0, 1, 2, 3, 4 ] ][0X
    [4Xgap> Display(Action(M,last[1]));[0X
    [4XMonoid( [ Transformation( [ 2, 3, 4, 3, 6, 3 ] ), [0X
    [4X  Transformation( [ 4, 5, 4, 3, 4, 1 ] ) ], ... )[0X
    [4Xgap> orbs := ShortOrbits(N,[0..10],50);[0X
    [4X[ [ -5, -4, -3, -1, 0, 1, 2, 3, 5, 6 ], [0X
    [4X  [ -11, -10, -9, -7, -6, -5, -4, -3, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, [0X
    [4X      12 ], [ -17, -16, -15, -13, -12, -11, -10, -9, -7, -6, -5, -4, -3, -1, [0X
    [4X      0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18 ] ][0X
    [4Xgap> quots := List(orbs,orb->Action(N,orb));[0X
    [4X[ <monoid with 3 generators>, <monoid with 3 generators>,[0X
    [4X  <monoid with 3 generators> ][0X
    [4Xgap> List(quots,Size);[0X
    [4X[ 268, 332, 366 ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Balls of given radius around an element of an rcwa monoid can be computed by
  the  operation  [10XBall[0X.  This operation can also be used for computing forward
  orbits or subsets of such under the action of an rcwa monoid:
  
  
  [1X4.2-2  Ball  (for  monoid,  element  and radius or monoid, point, radius and[0X
  [1Xaction)[0X
  
  [2X> Ball( [0X[3XM, f, r[0X[2X ) ____________________________________________________[0Xmethod
  [2X> Ball( [0X[3XM, p, r, action[0X[2X ) ____________________________________________[0Xmethod
  [6XReturns:[0X  The  ball  of  radius [3Xr[0X  around  the  element [3Xf[0X  in  the monoid [3XM[0X,
            respectively  the  ball  of  radius [3Xr[0X around the point [3Xp[0X under the
            action [3Xaction[0X of the monoid [3XM[0X.
  
  All   balls   are  understood  with  respect  to  [10XGeneratorsOfMonoid([3XM[0X)[0X.  As
  membership tests can be expensive, the first-mentioned method does not check
  whether  [3Xf[0X  is  indeed  an  element  of [3XM[0X. The methods require that point- /
  element comparisons are cheap. They are not only applicable to rcwa monoids.
  If the option [3XSpheres[0X is set, the ball is splitted up and returned as a list
  of spheres.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> List([0..12],k->Length(Ball(N,One(N),k)));[0X
    [4X[ 1, 4, 11, 26, 53, 99, 163, 228, 285, 329, 354, 364, 366 ][0X
    [4Xgap> Ball(N,[0..3],2,OnTuples);[0X
    [4X[ [ -3, 3, 3, 3 ], [ -1, -3, 0, 2 ], [ -1, -1, -1, -1 ], [ -1, -1, 1, -1 ], [0X
    [4X  [ -1, 1, 1, 1 ], [ -1, 3, 0, -4 ], [ 0, -1, 2, -3 ], [ 0, 1, 2, 3 ], [0X
    [4X  [ 1, -1, -1, -1 ], [ 1, 3, 0, 2 ], [ 3, -4, -1, 0 ] ][0X
    [4Xgap> l := 2*IdentityRcwaMappingOfZ; r := l+1;[0X
    [4XRcwa mapping of Z: n -> 2n[0X
    [4XRcwa mapping of Z: n -> 2n + 1[0X
    [4Xgap> Ball(Monoid(l,r),1,4,OnPoints:Spheres);[0X
    [4X[ [ 1 ], [ 2, 3 ], [ 4, 5, 6, 7 ], [ 8, 9, 10, 11, 12, 13, 14, 15 ], [0X
    [4X  [ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 ] ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
