  
  [1X6 Examples[0X
  
  This  chapter  discusses  a  number  of "nice" examples of rcwa mappings and
  -groups  in  detail.  All of them show different aspects of the package, and
  the order in which they appear is entirely arbitrary. In particular they are
  not ordered by degree of difficulty or interest.
  
  The rcwa mappings, rcwa groups and other objects defined in this chapter can
  be  found  in  the  file [11Xpkg/rcwa/examples/examples.g[0m. This file can be read
  into  the  current [5XGAP[0m session by issueing [10XRCWAReadExamples( );[0m. Afterwards,
  the  examples  are  stored  in  a record [10XRCWAExamples[0m of records. The global
  variable  assignments  made in a section of this chapter can be performed by
  issueing  [10XUnwrapExample([3Xname[0m[10X)[0m,  where  [3Xname[0m  is  given  at  the  end  of the
  corresponding  section.  Assignments  which  do  not  need  much  typing are
  omitted.  The  names of the variables which are actually assigned are listed
  by the function [10XUnwrapExample[0m.
  
  The  examples  are  typically  far  from  discussing  the respective aspects
  exhaustively. It is quite likely that in many instances by just a few little
  modifications  or  additional  easy  commands  you  can find out interesting
  things yourself -- have fun!
  
  
  [1X6.1 The Higman-Thompson group[0X
  
  The  Higman-Thompson  group  is  a finitely presented infinite simple group,
  cf. [Hig74].
  
  We show that the group
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> G := Group(List([[0,2,1,4],[0,4,1,4],[1,4,2,4],[2,4,3,4]],[0X
    [4X>                    ClassTransposition));[0X
    [4X<rcwa group over Z with 4 generators>[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  is  isomorphic to the Higman-Thompson group. This isomorphy has been pointed
  out by John P. McDermott. We take a slightly different set of generators
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> k := ClassTransposition(0,2,1,2);;[0X
    [4Xgap> l := ClassTransposition(1,2,2,4);;[0X
    [4Xgap> m := ClassTransposition(0,2,1,4);;[0X
    [4Xgap> n := ClassTransposition(1,4,2,4);;[0X
    [4Xgap> H := Group(k,l,m,n);[0X
    [4X<rcwa group over Z with 4 generators>[0X
    [4Xgap> G = H; # k, l, m and n generate G as well[0X
    [4Xtrue[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Now  we  verify  that  our  four  generators  satisfy the relations given on
  page 50  in [Hig74],  when  we  read  [10Xk[0m as kappa, [10Xl[0m as lambda, [10Xm[0m as mu and [10Xn[0m
  as nu:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> HigmanThompsonRels :=[0X
    [4X> [ k^2, l^2, m^2, n^2,                           # (1) in Higman's book[0X
    [4X>   l*k*m*k*l*n*k*n*m*k*l*k*m,                    # (2)        "[0X
    [4X>   k*n*l*k*m*n*k*l*n*m*n*l*n*m,                  # (3)        "[0X
    [4X>   (l*k*m*k*l*n)^3, (m*k*l*k*m*n)^3,             # (4)        "[0X
    [4X>   (l*n*m)^2*k*(m*n*l)^2*k,                      # (5)        "[0X
    [4X>   (l*n*m*n)^5,                                  # (6)        "[0X
    [4X>   (l*k*n*k*l*n)^3*k*n*k*(m*k*n*k*m*n)^3*k*n*k*n,# (7)        "[0X
    [4X>   ((l*k*m*n)^2*(m*k*l*n)^2)^3,                  # (8)        "[0X
    [4X>   (l*n*l*k*m*k*m*n*l*n*m*k*m*k)^4,              # (9)        "[0X
    [4X>   (m*n*m*k*l*k*l*n*m*n*l*k*l*k)^4,              #(10)        "[0X
    [4X>   (l*m*k*l*k*m*l*k*n*k)^2,                      #(11)        "[0X
    [4X>   (m*l*k*m*k*l*m*k*n*k)^2 ];                    #(12)        "[0X
    [4X[ IdentityMapping( Integers ), IdentityMapping( Integers ), [0X
    [4X  IdentityMapping( Integers ), IdentityMapping( Integers ), [0X
    [4X  IdentityMapping( Integers ), IdentityMapping( Integers ), [0X
    [4X  IdentityMapping( Integers ), IdentityMapping( Integers ), [0X
    [4X  IdentityMapping( Integers ), IdentityMapping( Integers ), [0X
    [4X  IdentityMapping( Integers ), IdentityMapping( Integers ), [0X
    [4X  IdentityMapping( Integers ), IdentityMapping( Integers ), [0X
    [4X  IdentityMapping( Integers ), IdentityMapping( Integers ) ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  We  conclude  that  our group is an homomorphic image of the Higman-Thompson
  group.  But  since  the Higman-Thompson group is simple and our group is not
  trivial, this means indeed that the two groups are isomorphic.
  
  In  fact it is straightforward to show that [10XG[0m is the group CT_emptyset(ℤ) in
  Corollary 3.7  in [Koh10],  which  is  generated  by  the  set  of all class
  transpositions  which  interchange residue classes modulo powers of 2. First
  we  check  that  [10XG[0m  contains  all  11 class transpositions which interchange
  residue classes modulo 2 or 4:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> S := Filtered(List(ClassPairs(4),ClassTransposition),[0X
    [4X>                  ct->Mod(ct) in [2,4]);[0X
    [4X[ ClassTransposition(0,2,1,2), ClassTransposition(0,2,1,4), [0X
    [4X  ClassTransposition(0,2,3,4), ClassTransposition(0,4,1,4), [0X
    [4X  ClassTransposition(0,4,2,4), ClassTransposition(0,4,3,4), [0X
    [4X  ClassTransposition(1,2,0,4), ClassTransposition(1,2,2,4), [0X
    [4X  ClassTransposition(1,4,2,4), ClassTransposition(1,4,3,4), [0X
    [4X  ClassTransposition(2,4,3,4) ][0X
    [4Xgap> IsSubset(G,S);[0X
    [4Xtrue[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Then   we  give  a  function  which  takes  a  class  transposition  tau  in
  CT_emptyset(ℤ),  and  which  returns  a  factorization  of  an element gamma
  satisfying  tau^gamma  in S into g_1 := (0(2),1(4)) in S, g_2 := (0(2),3(4))
  in  S,  g_3 := (1(2),0(4)) in S, g_4 := (1(2),2(4)) in S, h_1 := (0(4),1(4))
  in S and h_2 := (1(4),2(4)) in S:
  
  [4X---------------------------  GAP code  ---------------------------[0X
    [4X[0X
    [4XReducingConjugator := function ( tau )[0X
    [4X[0X
    [4X  local  w, F, g1, g2, g3, g4, h1, h2, h, cls, cl, r;[0X
    [4X[0X
    [4X  g1 := ClassTransposition(0,2,1,4); h1 := ClassTransposition(0,4,1,4);[0X
    [4X  g2 := ClassTransposition(0,2,3,4); h2 := ClassTransposition(1,4,2,4);[0X
    [4X  g3 := ClassTransposition(1,2,0,4);[0X
    [4X  g4 := ClassTransposition(1,2,2,4);[0X
    [4X[0X
    [4X  F := FreeGroup("g1","g2","g3","g4","h1","h2");[0X
    [4X[0X
    [4X  w := One(F); if Mod(tau) <= 4 then return w; fi;[0X
    [4X[0X
    [4X  # Before we can reduce the moduli of the interchanged residue classes,[0X
    [4X  # we must make sure that both of them have at least modulus 4.[0X
    [4X  cls := TransposedClasses(tau);[0X
    [4X  if Mod(cls[1]) = 2 then[0X
    [4X    if Residue(cls[1]) = 0 then[0X
    [4X      if Residue(cls[2]) mod 4 = 1 then tau := tau^g2; w := w * F.2;[0X
    [4X                                   else tau := tau^g1; w := w * F.1; fi;[0X
    [4X    else[0X
    [4X      if Residue(cls[2]) mod 4 = 0 then tau := tau^g4; w := w * F.4;[0X
    [4X                                   else tau := tau^g3; w := w * F.3; fi;[0X
    [4X    fi;[0X
    [4X  fi;[0X
    [4X[0X
    [4X  while Mod(tau) > 4 do # Now we can successively reduce the moduli.[0X
    [4X    if not ForAny(AllResidueClassesModulo(2),[0X
    [4X                  cl -> IsEmpty(Intersection(cl,Support(tau))))[0X
    [4X    then[0X
    [4X      cls := TransposedClasses(tau);[0X
    [4X      h := Filtered([h1,h2],[0X
    [4X             hi->Length(Filtered(cls,cl->IsSubset(Support(hi),cl)))=1);[0X
    [4X      h := h[1]; tau := tau^h;[0X
    [4X      if h = h1 then w := w * F.5; else w := w * F.6; fi;[0X
    [4X    fi;[0X
    [4X    cl := TransposedClasses(tau)[2]; # class with larger modulus[0X
    [4X    r  := Residue(cl);[0X
    [4X    if   r mod 4 = 1 then tau := tau^g1; w := w * F.1;[0X
    [4X    elif r mod 4 = 3 then tau := tau^g2; w := w * F.2;[0X
    [4X    elif r mod 4 = 0 then tau := tau^g3; w := w * F.3;[0X
    [4X    elif r mod 4 = 2 then tau := tau^g4; w := w * F.4; fi;[0X
    [4X  od;[0X
    [4X[0X
    [4X  return w;[0X
    [4Xend;[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  After  assigning  [10Xg1[0m,  [10Xg2[0m,  [10Xg3[0m,  [10Xg4[0m,  [10Xh1[0m and [10Xh2[0m appropriately, we obtain for
  example:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> ReducingConjugator(ClassTransposition(3,16,34,256));[0X
    [4Xh2*g1*h1*g1*h1*g1*h1*g1*h2*g2*h2*g4*h2*g4*h2*g3[0X
    [4Xgap> gamma := h2*g1*h1*g1*h1*g1*h1*g1*h2*g2*h2*g4*h2*g4*h2*g3;[0X
    [4X<bijective rcwa mapping of Z with modulus 256>[0X
    [4Xgap> ct := ClassTransposition(3,16,34,256)^gamma;;[0X
    [4Xgap> IsClassTransposition(ct);;[0X
    [4Xgap> ct;[0X
    [4XClassTransposition(1,4,2,4)[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  The  Higman-Thompson  group  can  also  be  embedded  in  a natural way into
  CT(GF(2)[x]):
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> x := Indeterminate(GF(2));; SetName(x,"x");[0X
    [4Xgap> R := PolynomialRing(GF(2),1);;[0X
    [4Xgap> k := ClassTransposition(0,x,1,x);;[0X
    [4Xgap> l := ClassTransposition(1,x,x,x^2);;[0X
    [4Xgap> m := ClassTransposition(0,x,1,x^2);;[0X
    [4Xgap> n := ClassTransposition(1,x^2,x,x^2);;[0X
    [4Xgap> G := Group(k,l,m,n);[0X
    [4X<rcwa group over GF(2)[x] with 4 generators>[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  The  correctness  of  this representation can likewise be verified by simply
  checking the defining relations given above.
  
  Issue   [10XUnwrapExample("HigmanThompson");[0m  in  order  to  assign  the  global
  variables defined in this example.
  
  
  [1X6.2 An extension of the Collatz mapping T to a permutation of ℤ^2[0X
  
  The Collatz mapping T is surjective, but not injective:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> T := RcwaMapping([[1,0,2],[3,1,2]]);;[0X
    [4Xgap> Display(T);[0X
    [4X[0X
    [4XRcwa mapping of Z with modulus 2[0X
    [4X[0X
    [4X              n mod 2               |            Image of n[0X
    [4X------------------------------------+------------------------------------[0X
    [4X  0                                 | n/2[0X
    [4X  1                                 | (3n + 1)/2[0X
    [4X[0X
    [4Xgap> IsInjective(T); IsSurjective(T);[0X
    [4Xfalse[0X
    [4Xtrue[0X
    [4Xgap> PreImages(T,2);[0X
    [4X[ 1, 4 ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Often,  dealing  with  bijective rcwa mappings is easier. Indeed the Collatz
  mapping T  can  be  extended  in  natural  ways  to permutations of ℤ^2. For
  example,  the  following  permutation  acts  on  the  second coordinate just
  like T:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> Sigma_T := RcwaMapping( Integers^2, [[1,0],[0,6]],[0X
    [4X>                            [[[[2,0],[0,1]],[0,0],2],[0X
    [4X>                             [[[4,0],[0,3]],[2,1],2],[0X
    [4X>                             [[[2,0],[0,1]],[0,0],2],[0X
    [4X>                             [[[4,0],[0,3]],[2,1],2],[0X
    [4X>                             [[[4,0],[0,1]],[0,0],2],[0X
    [4X>                             [[[4,0],[0,3]],[2,1],2]] );[0X
    [4X<rcwa mapping of Z^2 with modulus (1,0)Z+(0,6)Z>[0X
    [4Xgap> IsBijective(Sigma_T);[0X
    [4Xtrue[0X
    [4Xgap> Display(Sigma_T);[0X
    [4X[0X
    [4XBijective rcwa mapping of Z^2 with modulus (1,0)Z+(0,6)Z[0X
    [4X[0X
    [4X   [m,n] mod (1,0)Z+(0,6)Z   |              Image of [m,n][0X
    [4X-----------------------------+-------------------------------------------[0X
    [4X [0,0] [0,2]                 | [m,n/2][0X
    [4X [0,1] [0,3] [0,5]           | [2m+1,(3n+1)/2][0X
    [4X [0,4]                       | [2m,n/2][0X
    [4X[0X
    [4Xgap> Display(Sigma_T^-1);[0X
    [4X[0X
    [4XBijective rcwa mapping of Z^2 with modulus (2,0)Z+(0,3)Z[0X
    [4X[0X
    [4X   [m,n] mod (2,0)Z+(0,3)Z   |              Image of [m,n][0X
    [4X-----------------------------+-------------------------------------------[0X
    [4X [0,0] [0,1] [1,0] [1,1]     | [m,2n][0X
    [4X [0,2]                       | [m/2,2n][0X
    [4X [1,2]                       | [(m-1)/2,(2n-1)/3][0X
    [4X[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Now, the 3n+1 conjecture is equivalent to the assertion that the line n=4 is
  a set of representatives for the cycles of [10XSigma_T[0m on the half plane n > 0.
  
  Let's have a look at a part of a cycle of [10XSigma_T[0m:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> Trajectory(Sigma_T,[0,27],75);[0X
    [4X[ [ 0, 27 ], [ 1, 41 ], [ 3, 62 ], [ 3, 31 ], [ 7, 47 ], [ 15, 71 ], [0X
    [4X  [ 31, 107 ], [ 63, 161 ], [ 127, 242 ], [ 127, 121 ], [ 255, 182 ], [0X
    [4X  [ 255, 91 ], [ 511, 137 ], [ 1023, 206 ], [ 1023, 103 ], [0X
    [4X  [ 2047, 155 ], [ 4095, 233 ], [ 8191, 350 ], [ 8191, 175 ], [0X
    [4X  [ 16383, 263 ], [ 32767, 395 ], [ 65535, 593 ], [ 131071, 890 ], [0X
    [4X  [ 131071, 445 ], [ 262143, 668 ], [ 262143, 334 ], [ 524286, 167 ], [0X
    [4X  [ 1048573, 251 ], [ 2097147, 377 ], [ 4194295, 566 ], [ 4194295, 283 ], [0X
    [4X  [ 8388591, 425 ], [ 16777183, 638 ], [ 16777183, 319 ], [0X
    [4X  [ 33554367, 479 ], [ 67108735, 719 ], [ 134217471, 1079 ], [0X
    [4X  [ 268434943, 1619 ], [ 536869887, 2429 ], [ 1073739775, 3644 ], [0X
    [4X  [ 1073739775, 1822 ], [ 2147479550, 911 ], [ 4294959101, 1367 ], [0X
    [4X  [ 8589918203, 2051 ], [ 17179836407, 3077 ], [ 34359672815, 4616 ], [0X
    [4X  [ 34359672815, 2308 ], [ 68719345630, 1154 ], [ 68719345630, 577 ], [0X
    [4X  [ 137438691261, 866 ], [ 137438691261, 433 ], [ 274877382523, 650 ], [0X
    [4X  [ 274877382523, 325 ], [ 549754765047, 488 ], [ 549754765047, 244 ], [0X
    [4X  [ 1099509530094, 122 ], [ 1099509530094, 61 ], [ 2199019060189, 92 ], [0X
    [4X  [ 2199019060189, 46 ], [ 4398038120378, 23 ], [ 8796076240757, 35 ], [0X
    [4X  [ 17592152481515, 53 ], [ 35184304963031, 80 ], [ 35184304963031, 40 ], [0X
    [4X  [ 70368609926062, 20 ], [ 70368609926062, 10 ], [ 140737219852124, 5 ], [0X
    [4X  [ 281474439704249, 8 ], [ 281474439704249, 4 ], [ 562948879408498, 2 ], [0X
    [4X  [ 562948879408498, 1 ], [ 1125897758816997, 2 ], [0X
    [4X  [ 1125897758816997, 1 ], [ 2251795517633995, 2 ], [0X
    [4X  [ 2251795517633995, 1 ] ][0X
    [4Xgap> Trajectory(Sigma_T^-1,[0,27],20);[0X
    [4X[ [ 0, 27 ], [ 0, 54 ], [ 0, 108 ], [ 0, 216 ], [ 0, 432 ], [ 0, 864 ], [0X
    [4X  [ 0, 1728 ], [ 0, 3456 ], [ 0, 6912 ], [ 0, 13824 ], [ 0, 27648 ], [0X
    [4X  [ 0, 55296 ], [ 0, 110592 ], [ 0, 221184 ], [ 0, 442368 ], [0X
    [4X  [ 0, 884736 ], [ 0, 1769472 ], [ 0, 3538944 ], [ 0, 7077888 ], [0X
    [4X  [ 0, 14155776 ] ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  While it seems easy to make conjectures regarding the behaviour of cycles of
  [10XSigma_T[0m, obtaining results on it is apparently hard. We observe however that
  [10XSigma_T[0m  can be written as a product of two permutations of ℤ^2 whose cycles
  can be described easily:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> a := RcwaMapping(Integers^2,[[1,0],[0,2]],[[[[4,0],[0,1]],[0, 0],2],[0X
    [4X>                                               [[[4,0],[0,1]],[2,-1],2]]);[0X
    [4X<rcwa mapping of Z^2 with modulus (1,0)Z+(0,2)Z>[0X
    [4Xgap> b := a^-1*Sigma_T;[0X
    [4X<bijective rcwa mapping of Z^2 with modulus (2,0)Z+(0,3)Z>[0X
    [4Xgap> Display(a);[0X
    [4X[0X
    [4XBijective rcwa mapping of Z^2 with modulus (1,0)Z+(0,2)Z[0X
    [4X[0X
    [4X   [m,n] mod (1,0)Z+(0,2)Z   |              Image of [m,n][0X
    [4X-----------------------------+-------------------------------------------[0X
    [4X [0,0]                       | [2m,n/2][0X
    [4X [0,1]                       | [2m+1,(n-1)/2][0X
    [4X[0X
    [4Xgap> Display(b);[0X
    [4X[0X
    [4XBijective rcwa mapping of Z^2 with modulus (2,0)Z+(0,3)Z[0X
    [4X[0X
    [4X   [m,n] mod (2,0)Z+(0,3)Z   |              Image of [m,n][0X
    [4X-----------------------------+-------------------------------------------[0X
    [4X [0,0] [0,1]                 | [m/2,n][0X
    [4X [0,2]                       | [m,n][0X
    [4X [1,0] [1,1] [1,2]           | [m,3n+2][0X
    [4X[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  It  is  easy  to  see that both [10Xa[0m and [10Xb[0m have infinite order. The cycles of [10Xa[0m
  have roughly hyperbolic shape and run, so to speak, from (0,pm infty) to (pm
  infty,0).  A  given  cycle  contains only finitely many points both of whose
  coordinates  are  nonzero.  The  fixed points of [10Xa[0m are (0,0) and (-1,-1). We
  have a look at an example of a cycle of [10Xa[0m:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> Trajectory(a,[1000,1000],15);[0X
    [4X[ [ 1000, 1000 ], [ 2000, 500 ], [ 4000, 250 ], [ 8000, 125 ], [0X
    [4X  [ 16001, 62 ], [ 32002, 31 ], [ 64005, 15 ], [ 128011, 7 ], [0X
    [4X  [ 256023, 3 ], [ 512047, 1 ], [ 1024095, 0 ], [ 2048190, 0 ], [0X
    [4X  [ 4096380, 0 ], [ 8192760, 0 ], [ 16385520, 0 ] ][0X
    [4Xgap> Trajectory(a^-1,[1000,1000],15);[0X
    [4X[ [ 1000, 1000 ], [ 500, 2000 ], [ 250, 4000 ], [ 125, 8000 ], [0X
    [4X  [ 62, 16001 ], [ 31, 32002 ], [ 15, 64005 ], [ 7, 128011 ], [0X
    [4X  [ 3, 256023 ], [ 1, 512047 ], [ 0, 1024095 ], [ 0, 2048190 ], [0X
    [4X  [ 0, 4096380 ], [ 0, 8192760 ], [ 0, 16385520 ] ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  It is left as an easy exercise to the reader to find out how the cycles of [10Xb[0m
  look like.
  
  Issue  [10XUnwrapExample("ZxZ");[0m in order to assign the global variables defined
  in this example.
  
  
  [1X6.3 Factoring Collatz' permutation of the integers[0X
  
  In  1932, Lothar Collatz mentioned in his notebook the following permutation
  of the integers:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> Collatz := RcwaMapping([[2,0,3],[4,-1,3],[4,1,3]]);;[0X
    [4Xgap> Display(Collatz);[0X
    [4X[0X
    [4XRcwa mapping of Z with modulus 3[0X
    [4X[0X
    [4X              n mod 3               |            Image of n[0X
    [4X------------------------------------+------------------------------------[0X
    [4X  0                                 | 2n/3[0X
    [4X  1                                 | (4n - 1)/3[0X
    [4X  2                                 | (4n + 1)/3[0X
    [4X[0X
    [4Xgap> ShortCycles(Collatz,[-50..50],50); # There are some finite cycles:[0X
    [4X[ [ -111, -74, -99, -66, -44, -59, -79, -105, -70, -93, -62, -83 ], [0X
    [4X  [ -9, -6, -4, -5, -7 ], [ -3, -2 ], [ -1 ], [ 0 ], [ 1 ], [ 2, 3 ], [0X
    [4X  [ 4, 5, 7, 9, 6 ], [ 44, 59, 79, 105, 70, 93, 62, 83, 111, 74, 99, 66 ] ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  The  cycle  structure  of  Collatz'  permutation  has  not  been  completely
  determined yet. In particular it is not known whether the cycle containing 8
  is  finite  or infinite. Nevertheless, the factorization routine included in
  this  package  can  determine a factorization of this permutation into class
  transpositions, i.e. involutions interchanging two disjoint residue classes:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> Collatz in CT(Integers);  # `Collatz' lies in the simple group CT(Z).[0X
    [4Xtrue[0X
    [4Xgap> Length(Factorization(Collatz));[0X
    [4X212[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Setting  the  Info  level of [10XInfoRCWA[0m equal to 2 (simply issue [10XRCWAInfo(2);[0m)
  causes  the  factorization  routine  to  display detailed information on the
  progress  of the factoring process. For reasons of saving space, this is not
  done in this manual.
  
  We  would like to get a factorization into fewer factors. Firstly, we try to
  factor  the  inverse  --  just  like  the various options interpreted by the
  factorization  routine,  this  has  influence  on decisions taken during the
  factoring process:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> Length(Factorization(Collatz^-1));[0X
    [4X129[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  This  is  already  a shorter product, but can still be improved. We remember
  the  [10XmKnot[0m's,  of  which  the  permutation  [10XmKnot(3)[0m  looks  very similar to
  Collatz'  permutation. Therefore it is straightforward to try to factor both
  [10XmKnot(3)[0m and [10XCollatz/mKnot(3)[0m, and to look whether the sum of the numbers of
  factors is less than 129:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> KnotFacts := Factorization(mKnot(3));;[0X
    [4Xgap> QuotFacts := Factorization(Collatz/mKnot(3));;[0X
    [4Xgap> List([KnotFacts,QuotFacts],Length);[0X
    [4X[ 59, 9 ][0X
    [4Xgap> CollatzFacts := Concatenation(QuotFacts,KnotFacts);[0X
    [4X[ ClassTransposition(0,6,4,6), ClassTransposition(0,6,5,6), [0X
    [4X  ClassTransposition(0,6,3,6), ClassTransposition(0,6,1,6), [0X
    [4X  ClassTransposition(0,6,2,6), ClassTransposition(2,3,4,6), [0X
    [4X  ClassTransposition(0,3,4,6), ClassTransposition(2,3,1,6), [0X
    [4X  ClassTransposition(0,3,1,6), ClassTransposition(0,36,35,36), [0X
    [4X  ClassTransposition(0,36,22,36), ClassTransposition(0,36,18,36), [0X
    [4X  ClassTransposition(0,36,17,36), ClassTransposition(0,36,14,36), [0X
    [4X  ClassTransposition(0,36,20,36), ClassTransposition(0,36,4,36), [0X
    [4X  ClassTransposition(2,36,8,36), ClassTransposition(2,36,16,36), [0X
    [4X  ClassTransposition(2,36,13,36), ClassTransposition(2,36,9,36), [0X
    [4X  ClassTransposition(2,36,7,36), ClassTransposition(2,36,6,36), [0X
    [4X  ClassTransposition(2,36,3,36), ClassTransposition(2,36,10,36), [0X
    [4X  ClassTransposition(2,36,15,36), ClassTransposition(2,36,12,36), [0X
    [4X  ClassTransposition(2,36,5,36), ClassTransposition(21,36,28,36), [0X
    [4X  ClassTransposition(21,36,33,36), ClassTransposition(21,36,30,36), [0X
    [4X  ClassTransposition(21,36,23,36), ClassTransposition(21,36,34,36), [0X
    [4X  ClassTransposition(21,36,31,36), ClassTransposition(21,36,27,36), [0X
    [4X  ClassTransposition(21,36,25,36), ClassTransposition(21,36,24,36), [0X
    [4X  ClassTransposition(26,36,32,36), ClassTransposition(26,36,29,36), [0X
    [4X  ClassTransposition(10,18,35,36), ClassTransposition(5,18,35,36), [0X
    [4X  ClassTransposition(10,18,17,36), ClassTransposition(5,18,17,36), [0X
    [4X  ClassTransposition(8,12,14,24), ClassTransposition(6,9,17,18), [0X
    [4X  ClassTransposition(3,9,17,18), ClassTransposition(0,9,17,18), [0X
    [4X  ClassTransposition(6,9,16,18), ClassTransposition(3,9,16,18), [0X
    [4X  ClassTransposition(0,9,16,18), ClassTransposition(6,9,11,18), [0X
    [4X  ClassTransposition(3,9,11,18), ClassTransposition(0,9,11,18), [0X
    [4X  ClassTransposition(6,9,4,18), ClassTransposition(3,9,4,18), [0X
    [4X  ClassTransposition(0,9,4,18), ClassTransposition(0,6,14,24), [0X
    [4X  ClassTransposition(0,6,2,24), ClassTransposition(8,12,17,18), [0X
    [4X  ClassTransposition(7,12,17,18), ClassTransposition(8,12,11,18), [0X
    [4X  ClassTransposition(7,12,11,18), PrimeSwitch(3)^-1, [0X
    [4X  ClassTransposition(7,12,17,18), ClassTransposition(2,6,17,18), [0X
    [4X  ClassTransposition(0,3,17,18), PrimeSwitch(3)^-1, PrimeSwitch(3)^-1, [0X
    [4X  PrimeSwitch(3)^-1 ][0X
    [4Xgap> Product(CollatzFacts) = Collatz; # Check.[0X
    [4Xtrue[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  The   factors   [10XPrimeSwitch(3)[0m   are  products  of  6  class  transpositions
  (cf. [2XPrimeSwitch[0m ([14X2.5-2[0m)).
  
  Issue  [10XUnwrapExample("CollatzlikePerms");[0m  to  assign  the  global  variable
  [10XCollatz[0m defined in this example.
  
  
  [1X6.4 An rcwa mapping which seems to be contracting, but very slow[0X
  
  The  iterates of an integer under the Collatz mapping T seem to approach its
  contraction  centre  -- this is the finite set where all trajectories end up
  after  a  finite number of steps -- rather quickly and do not get very large
  before  doing so (of course this is a purely heuristic statement as the 3n+1
  Conjecture has not been proved so far!):
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> T := RcwaMapping([[1,0,2],[3,1,2]]);;[0X
    [4Xgap> S0 := LikelyContractionCentre(T,100,1000);[0X
    [4X#I  Warning: `LikelyContractionCentre' is highly probabilistic.[0X
    [4XThe returned result can only be regarded as a rough guess.[0X
    [4XSee ?LikelyContractionCentre for more information.[0X
    [4X[ -136, -91, -82, -68, -61, -55, -41, -37, -34, -25, -17, -10, -7, -5, [0X
    [4X  -1, 0, 1, 2 ][0X
    [4Xgap> S0^T = S0; # This holds by definition of the contraction centre.[0X
    [4Xtrue[0X
    [4Xgap> List([1..30],n->Length(Trajectory(T,n,S0)));[0X
    [4X[ 1, 1, 5, 2, 4, 6, 11, 3, 13, 5, 10, 7, 7, 12, 12, 4, 9, 14, 14, 6, 6, [0X
    [4X  11, 11, 8, 16, 8, 70, 13, 13, 13 ][0X
    [4Xgap> Maximum(List([1..1000],n->Length(Trajectory(T,n,S0))));[0X
    [4X113[0X
    [4Xgap> Maximum(List([1..1000],n->Maximum(Trajectory(T,n,S0))));[0X
    [4X125252[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  The  following mapping seems to be contracting as well, but its trajectories
  are much longer:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> f6 := RcwaMapping([[ 1,0,6],[ 5, 1,6],[ 7,-2,6],[0X
    [4X>                       [11,3,6],[11,-2,6],[11,-1,6]]);;[0X
    [4Xgap> Display(f6);[0X
    [4X[0X
    [4XRcwa mapping of Z with modulus 6[0X
    [4X[0X
    [4X              n mod 6               |            Image of n[0X
    [4X------------------------------------+------------------------------------[0X
    [4X  0                                 | n/6[0X
    [4X  1                                 | (5n + 1)/6[0X
    [4X  2                                 | (7n - 2)/6[0X
    [4X  3                                 | (11n + 3)/6[0X
    [4X  4                                 | (11n - 2)/6[0X
    [4X  5                                 | (11n - 1)/6[0X
    [4X[0X
    [4Xgap> S0 := LikelyContractionCentre(f6,1000,100000);;[0X
    [4X#I  Warning: `LikelyContractionCentre' is highly probabilistic.[0X
    [4XThe returned result can only be regarded as a rough guess.[0X
    [4XSee ?LikelyContractionCentre for more information.[0X
    [4Xgap> Trajectory(f6,25,S0);[0X
    [4X[ 25, 21, 39, 72, 12, 2 ][0X
    [4Xgap> List([1..100],n->Length(Trajectory(f6,n,S0)));[0X
    [4X[ 1, 1, 3, 4, 1, 2, 3, 2, 1, 5, 7, 2, 8, 17, 3, 16, 1, 4, 17, 6, 5, 2, [0X
    [4X  5, 5, 6, 1, 4, 2, 15, 1, 1, 3, 2, 5, 13, 3, 2, 3, 4, 1, 8, 4, 4, 2, 7, [0X
    [4X  19, 23517, 3, 9, 3, 1, 18, 14, 2, 20, 23512, 14, 2, 6, 6, 1, 4, 19, [0X
    [4X  12, 23511, 8, 23513, 10, 1, 13, 13, 3, 1, 23517, 7, 20, 7, 9, 9, 6, [0X
    [4X  12, 8, 6, 18, 14, 23516, 31, 12, 23545, 4, 21, 19, 5, 1, 17, 17, 13, [0X
    [4X  19, 6, 23515 ][0X
    [4Xgap> Maximum(Trajectory(f6,47,S0));[0X
    [4X7363391777762473304431877054771075818733690108051469808715809256737742295\[0X
    [4X45698886054[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Computing  the  trajectory  of  3224  takes quite a while -- this trajectory
  ascends  to  about 3 * 10^2197, before it approaches the fixed point 2 after
  19949562 steps.
  
  When  constructing  the mapping [10Xf6[0m, the denominators of the partial mappings
  have  been  chosen  to  be  equal  and the numerators have been chosen to be
  numbers  coprime  to  the common denominator, whose product is just a little
  bit  smaller than the [10XModulus(f6)[0mth power of the denominator. In the example
  we have 5 * 7 * 11^3 = 46585 and 6^6 = 46656.
  
  Although  the  trajectories of [10XT[0m are much shorter than those of [10Xf6[0m, it seems
  likely that this does not make the problem of deciding whether the mapping [10XT[0m
  is  contracting  essentially  easier  -- even for mappings with much shorter
  trajectories  than [10XT[0m  the  problem  seems to be equally hard. A solution can
  usually  only be found in trivial cases, i.e. for example when there is some
  k  such that applying the kth power of the respective mapping to any integer
  decreases its absolute value.
  
  Issue   [10XUnwrapExample("SlowlyContractingMappings");[0m  to  assign  the  global
  variables defined in this example.
  
  
  [1X6.5 Checking a result by P. Andaloro[0X
  
  In [And00], P. Andaloro has shown that proving that trajectories of integers
  n in 1(16) under the Collatz mapping always contain 1 would be sufficient to
  prove  the  3n+1 Conjecture. In the sequel, this result is verified by [5XRCWA[0m.
  Checking  that  the  union  of  the  images of the residue class 1(16) under
  powers  of the Collatz mapping T contains ℤ \ 0(3) is obviously enough. Thus
  we put S := 1(16), and successively unite the set S with its image under T:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> T := RcwaMapping([[1,0,2],[3,1,2]]);[0X
    [4X<rcwa mapping of Z with modulus 2>[0X
    [4Xgap> S := ResidueClass(Integers,16,1);[0X
    [4X1(16)[0X
    [4Xgap> S := Union(S,S^T);[0X
    [4X1(16) U 2(24)[0X
    [4Xgap> S := Union(S,S^T);[0X
    [4X1(12) U 2(24) U 17(48) U 33(48)[0X
    [4Xgap> S := Union(S,S^T);[0X
    [4X<union of 30 residue classes (mod 144)>[0X
    [4Xgap> S := Union(S,S^T);[0X
    [4X<union of 42 residue classes (mod 144)>[0X
    [4Xgap> S := Union(S,S^T);[0X
    [4X<union of 172 residue classes (mod 432)>[0X
    [4Xgap> S := Union(S,S^T);[0X
    [4X<union of 676 residue classes (mod 1296)>[0X
    [4Xgap> S := Union(S,S^T);[0X
    [4X<union of 810 residue classes (mod 1296)>[0X
    [4Xgap> S := Union(S,S^T);[0X
    [4X<union of 2638 residue classes (mod 3888)>[0X
    [4Xgap> S := Union(S,S^T);[0X
    [4X<union of 33 residue classes (mod 48)>[0X
    [4Xgap> S := Union(S,S^T);[0X
    [4X<union of 33 residue classes (mod 48)>[0X
    [4Xgap> Union(S,ResidueClass(Integers,3,0)); # Et voila ...[0X
    [4XIntegers[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Further similar computations are shown in Section [14X6.14[0m.
  
  Issue  [10XUnwrapExample("CollatzMapping");[0m  to  assign  the  global  variable [10XT[0m
  defined in this example.
  
  
  [1X6.6 Two examples by Matthews and Leigh[0X
  
  In  [ML87],  K. R. Matthews and G. M. Leigh have shown that two trajectories
  of  the  following  (surjective,  but  not  injective)  mappings are acyclic
  (mod x) and divergent:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> x := Indeterminate(GF(4),1);; SetName(x,"x");[0X
    [4Xgap> R := PolynomialRing(GF(2),1);[0X
    [4XGF(2)[x][0X
    [4Xgap> ML1 := RcwaMapping(R,x,[[1,0,x],[(x+1)^3,1,x]]*One(R));;[0X
    [4Xgap> ML2 := RcwaMapping(R,x,[[1,0,x],[(x+1)^2,1,x]]*One(R));;[0X
    [4Xgap> Display(ML1);[0X
    [4X[0X
    [4XRcwa mapping of GF(2)[x] with modulus x[0X
    [4X[0X
    [4X        P mod x         |                  Image of P[0X
    [4X------------------------+------------------------------------------------[0X
    [4X 0*Z(2)                 | P/x[0X
    [4X Z(2)^0                 | ((x^3+x^2+x+Z(2)^0)*P + Z(2)^0)/x[0X
    [4X[0X
    [4Xgap> Display(ML2);[0X
    [4X[0X
    [4XRcwa mapping of GF(2)[x] with modulus x[0X
    [4X[0X
    [4X        P mod x         |                  Image of P[0X
    [4X------------------------+------------------------------------------------[0X
    [4X 0*Z(2)                 | P/x[0X
    [4X Z(2)^0                 | ((x^2+Z(2)^0)*P + Z(2)^0)/x[0X
    [4X[0X
    [4Xgap> List([ML1,ML2],IsSurjective);[0X
    [4X[ true, true ][0X
    [4Xgap> List([ML1,ML2],IsInjective);[0X
    [4X[ false, false ][0X
    [4Xgap> traj1 := Trajectory(ML1,One(R),16);[0X
    [4X[ Z(2)^0, x^2+x+Z(2)^0, x^4+x^2+x, x^3+x+Z(2)^0, x^5+x^4+x^2, x^4+x^3+x, [0X
    [4X  x^3+x^2+Z(2)^0, x^5+x^2+Z(2)^0, x^7+x^6+x^5+x^3+Z(2)^0, [0X
    [4X  x^9+x^7+x^6+x^5+x^3+x+Z(2)^0, x^11+x^10+x^8+x^7+x^6+x^5+x^2, [0X
    [4X  x^10+x^9+x^7+x^6+x^5+x^4+x, x^9+x^8+x^6+x^5+x^4+x^3+Z(2)^0, [0X
    [4X  x^11+x^8+x^7+x^6+x^4+x+Z(2)^0, x^13+x^12+x^11+x^8+x^7+x^6+x^4, [0X
    [4X  x^12+x^11+x^10+x^7+x^6+x^5+x^3 ][0X
    [4Xgap> traj2 := Trajectory(ML2,(x^3+x+1)*One(R),16);[0X
    [4X[ x^3+x+Z(2)^0, x^4+x+Z(2)^0, x^5+x^3+x^2+x+Z(2)^0, x^6+x^3+Z(2)^0, [0X
    [4X  x^7+x^5+x^4+x^2+x, x^6+x^4+x^3+x+Z(2)^0, x^7+x^4+x^3+x+Z(2)^0, [0X
    [4X  x^8+x^6+x^5+x^4+x^3+x+Z(2)^0, x^9+x^6+x^3+x+Z(2)^0, [0X
    [4X  x^10+x^8+x^7+x^5+x^4+x+Z(2)^0, x^11+x^8+x^7+x^5+x^4+x^3+x^2+x+Z(2)^0, [0X
    [4X  x^12+x^10+x^9+x^8+x^7+x^5+Z(2)^0, x^13+x^10+x^7+x^4+x, [0X
    [4X  x^12+x^9+x^6+x^3+Z(2)^0, x^13+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x, [0X
    [4X  x^12+x^10+x^9+x^7+x^6+x^4+x^3+x+Z(2)^0 ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  The  pattern  which  Matthews  and  Leigh used to show the divergence of the
  above  trajectories can be recognized easily by looking at the corresponding
  Markov chains with the two states 0 mod x and 1 mod x:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> traj1modx := Trajectory(ML1,One(R),400,x);;[0X
    [4Xgap> traj2modx := Trajectory(ML2,(x^3+x+1)*One(R),600,x);;[0X
    [4Xgap> List(traj1modx{[1..150]},val->Position([Zero(R),One(R)],val)-1);[0X
    [4X[ 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, [0X
    [4X  1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, [0X
    [4X  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, [0X
    [4X  1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, [0X
    [4X  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, [0X
    [4X  1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, [0X
    [4X  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ][0X
    [4Xgap> List(traj2modx{[1..150]},val->Position([Zero(R),One(R)],val)-1);[0X
    [4X[ 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, [0X
    [4X  1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, [0X
    [4X  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, [0X
    [4X  1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, [0X
    [4X  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, [0X
    [4X  1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, [0X
    [4X  0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  What  is important here are the lengths of the intervals between two changes
  from one state to the other:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> ChangePoints := l->Filtered([1..Length(l)-1],pos->l[pos]<>l[pos+1]);;[0X
    [4Xgap> Diffs := l->List([1..Length(l)-1],pos->l[pos+1]-l[pos]);;[0X
    [4Xgap> Diffs(ChangePoints(traj1modx)); # The pattern in the first ...[0X
    [4X[ 1, 1, 2, 4, 2, 2, 4, 8, 4, 4, 8, 16, 8, 8, 16, 32, 16, 16, 32, 64, 32, [0X
    [4X  32, 64 ][0X
    [4Xgap> Diffs(ChangePoints(traj2modx)); # ... and in the second example.[0X
    [4X[ 1, 7, 1, 1, 1, 13, 1, 1, 1, 1, 1, 1, 1, 25, 1, 1, 1, 1, 1, 1, 1, 1, 1, [0X
    [4X  1, 1, 1, 1, 1, 1, 49, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, [0X
    [4X  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 97, 1, 1, 1, 1, 1, 1, 1, [0X
    [4X  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, [0X
    [4X  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, [0X
    [4X  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 193, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, [0X
    [4X  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, [0X
    [4X  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, [0X
    [4X  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, [0X
    [4X  1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ][0X
    [4Xgap> Diffs(ChangePoints(last)); # Make this a bit more obvious.[0X
    [4X[ 1, 3, 1, 7, 1, 15, 1, 31, 1, 63, 1 ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  This  looks  clearly acyclic, thus the trajectories diverge. Needless to say
  however  that  this  computational evidence does not replace the proof along
  these  lines given in the article cited above, but just sheds a light on the
  idea behind it.
  
  Issue [10XUnwrapExample("MatthewsLeigh");[0m to assign the global variables defined
  in this example.
  
  
  [1X6.7 Orders of commutators[0X
  
  We enter some wild rcwa permutation:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> u := RcwaMapping([[3,0,5],[9,1,5],[3,-1,5],[9,-2,5],[9,4,5]]);;[0X
    [4Xgap> IsTame(u);;[0X
    [4Xgap> Display(u);[0X
    [4X[0X
    [4XWild bijective rcwa mapping of Z with modulus 5[0X
    [4X[0X
    [4X              n mod 5               |            Image of n[0X
    [4X------------------------------------+------------------------------------[0X
    [4X  0                                 | 3n/5[0X
    [4X  1                                 | (9n + 1)/5[0X
    [4X  2                                 | (3n - 1)/5[0X
    [4X  3                                 | (9n - 2)/5[0X
    [4X  4                                 | (9n + 4)/5[0X
    [4X[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  We  would  like  to compute the order of [u,n -> n + k] and [u^2,n -> n + k]
  for different values of k:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> nu := ClassShift(0,1);; # n -> n + 1[0X
    [4Xgap> l := Filtered([0..100],k->IsTame(Comm(u,nu^k)));[0X
    [4X[ 0, 2, 3, 5, 6, 9, 10, 12, 13, 15, 17, 18, 20, 21, 24, 25, 27, 28, 30, [0X
    [4X  32, 33, 35, 36, 39, 40, 42, 43, 45, 47, 48, 50, 51, 54, 55, 57, 58, [0X
    [4X  60, 62, 63, 65, 66, 69, 70, 72, 73, 75, 77, 78, 80, 81, 84, 85, 87, [0X
    [4X  88, 90, 92, 93, 95, 96, 99, 100 ][0X
    [4Xgap> List(l,k->Order(Comm(u,nu^k)));[0X
    [4X[ 1, 6, 5, 3, 5, 5, 3, infinity, 7, infinity, 7, 5, 3, infinity, [0X
    [4X  infinity, 3, 5, 7, infinity, 7, infinity, 3, 5, 5, 3, 5, infinity, [0X
    [4X  infinity, infinity, 5, 3, 5, 5, 3, infinity, 7, infinity, 7, 5, 3, [0X
    [4X  infinity, infinity, 3, 5, 7, infinity, 7, infinity, 3, 5, 5, 3, 5, [0X
    [4X  infinity, infinity, infinity, 5, 3, 5, 5, 3 ][0X
    [4Xgap> u2 := u^2;[0X
    [4X<wild bijective rcwa mapping of Z with modulus 25>[0X
    [4Xgap> Filtered([1..16],k->IsTame(Comm(u2,nu^k))); # k < 15 -> commutator wild![0X
    [4X[ 15 ][0X
    [4Xgap> Order(Comm(u2,nu^15));[0X
    [4Xinfinity[0X
    [4Xgap> u2nu17 := Comm(u2,nu^17);[0X
    [4X<bijective rcwa mapping of Z with modulus 81>[0X
    [4Xgap> cycs := ShortCycles(u2nu17,[-100..100],100);;[0X
    [4Xgap> List(cycs,Length);[0X
    [4X[ 72, 72, 73, 72, 73, 72, 72, 73, 72, 72, 72, 73, 72, 72, 73, 72, 72, [0X
    [4X  73, 72, 72, 73, 72, 72 ][0X
    [4Xgap> Lcm(last);[0X
    [4X5256[0X
    [4Xgap> u2nu17^5256; # This element has indeed order 2^3*3^2*73 = 5256.[0X
    [4XIdentityMapping( Integers )[0X
    [4Xgap> u2nu18 := Comm(u2,nu^18);[0X
    [4X<bijective rcwa mapping of Z with modulus 81>[0X
    [4Xgap> cycs := ShortCycles(u2nu18,[-100..100],100);;[0X
    [4Xgap> List(cycs,Length);[0X
    [4X[ 22, 22, 22, 21, 22, 22, 22, 21, 21, 22, 22, 21, 22, 21, 22, 22, 21, [0X
    [4X  22, 22, 21, 22, 22, 21 ][0X
    [4Xgap> Lcm(last);[0X
    [4X462[0X
    [4Xgap> u2nu18^462; # This is an element of order 2*3*7*11 = 462.[0X
    [4XIdentityMapping( Integers )[0X
    [4Xgap> List([Comm(u2,nu^20),Comm(u2,nu^25),Comm(u2,nu^30)],Order);[0X
    [4X[ 29, 9, 15 ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  We  observe that our commutators have various different orders, and that the
  prime factors of these orders are not all "very small".
  
  Issue  [10XUnwrapExample("CollatzlikePerms");[0m  to  assign  the global variable [10Xu[0m
  defined in this example.
  
  
  [1X6.8 An infinite subgroup of CT(GF(2)[x]) with many torsion elements[0X
  
  In this section, we have a look at the following subgroup of CT(GF(2)[x]):
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> x := Indeterminate(GF(2));; SetName(x,"x");[0X
    [4Xgap> R := PolynomialRing(GF(2),1);[0X
    [4XGF(2)[x][0X
    [4Xgap> a := ClassTransposition(0,x,1,x);;[0X
    [4Xgap> b := ClassTransposition(0,x^2+1,1,x^2+1);;[0X
    [4Xgap> c := ClassTransposition(1,x,0,x^2+x);;[0X
    [4Xgap> G := Group(a,b,c);[0X
    [4X<rcwa group over GF(2)[x] with 3 generators>[0X
    [4Xgap> Display(G);[0X
    [4X[0X
    [4XRcwa group over GF(2)[x], generated by[0X
    [4X[0X
    [4X[[0X
    [4XBijective rcwa mapping of GF(2)[x]: P -> P + Z(2)^0[0X
    [4X[0X
    [4XBijective rcwa mapping of GF(2)[x] with modulus x^2+Z(2)^0, of order 2[0X
    [4X[0X
    [4X    P mod x^2+Z(2)^0    |                  Image of P[0X
    [4X------------------------+------------------------------------------------[0X
    [4X 0*Z(2)   Z(2)^0        | P + Z(2)^0[0X
    [4X x        x+Z(2)^0      | P[0X
    [4X[0X
    [4X[0X
    [4XBijective rcwa mapping of GF(2)[x] with modulus x^2+x, of order 2[0X
    [4X[0X
    [4X      P mod x^2+x       |                  Image of P[0X
    [4X------------------------+------------------------------------------------[0X
    [4X 0*Z(2)                 | (P + x+Z(2)^0)/(x+Z(2)^0)[0X
    [4X Z(2)^0   x+Z(2)^0      | (x+Z(2)^0)*P + x+Z(2)^0[0X
    [4X x                      | P[0X
    [4X[0X
    [4X][0X
    [4X[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  We can easily find 2 normal subgroups of [10XG[0m:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> N1 := Subgroup(G,[a*b,a*c]);[0X
    [4X<rcwa group over GF(2)[x] with 2 generators>[0X
    [4Xgap> IsNormal(G,N1);[0X
    [4Xtrue[0X
    [4Xgap> Index(G,N1);[0X
    [4X2[0X
    [4Xgap> G/N1;[0X
    [4XGroup([ (1,2), (1,2), (1,2) ])[0X
    [4Xgap> N2 := Subgroup(G,[a*b*c,a*c]);;[0X
    [4Xgap> IsNormal(G,N2);[0X
    [4Xtrue[0X
    [4Xgap> IsSubgroup(N1,N2);[0X
    [4Xfalse[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Products  of  even  numbers  of generators of [10XG[0m may have infinite order. For
  example, we have
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> Order(a*b);[0X
    [4X2[0X
    [4Xgap> Order(a*c);[0X
    [4Xinfinity[0X
    [4Xgap> Order(b*c);[0X
    [4Xinfinity[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  We  would  like  to  have  a  look  at  orders of products of odd numbers of
  generators.   In  order  to  restrict  our  considerations  to  "essentially
  different"  products (as far as we can easily do this), we use the following
  auxiliary function:
  
  [4X---------------------------  GAP code  ---------------------------[0X
    [4X[0X
    [4XNormedWords := function ( F, lng )[0X
    [4X[0X
    [4X  local  words, gens, tuples, w;[0X
    [4X[0X
    [4X  gens   := GeneratorsOfGroup(F);[0X
    [4X  tuples := EnumeratorOfTuples([1..3],lng);[0X
    [4X  words  := [];[0X
    [4X[0X
    [4X  for w in tuples do[0X
    [4X    if    (w[1] = 1 or not 1 in w)[0X
    [4X      and PositionSublist(w,[1,1]) = fail[0X
    [4X      and PositionSublist(w,[2,2]) = fail[0X
    [4X      and PositionSublist(w,[3,3]) = fail[0X
    [4X      and PositionSublist(w,[2,1]) = fail[0X
    [4X      and w[1] < w[lng][0X
    [4X      and w{[1,lng]} <> [1,2][0X
    [4X      and (w{[1..3]} = [1,2,3] or PositionSublist(w,[1,2,3]) = fail)[0X
    [4X    then Add(words,w); fi;[0X
    [4X  od;[0X
    [4X[0X
    [4X  words := List(words,word->Product(List(word,i->gens[i])));[0X
    [4X  return words;[0X
    [4Xend;[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Now  let's  compute  the  possible  orders  of  products  of  3,  5,  7 or 9
  generators:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> F := FreeGroup("a","b","c");;[0X
    [4Xgap> phi := EpimorphismByGenerators(F,G);[0X
    [4X[ a, b, c ] -> [ ClassTransposition(0*Z(2),x,Z(2)^0,x), [0X
    [4X  ClassTransposition(0*Z(2),x^2+Z(2)^0,Z(2)^0,x^2+Z(2)^0), [0X
    [4X  ClassTransposition(Z(2)^0,x,0*Z(2),x^2+x) ][0X
    [4Xgap> B3 := NormedWords(F,3);[0X
    [4X[ a*b*c ][0X
    [4Xgap> B3 := List(B3,g->g^phi);[0X
    [4X[ <bijective rcwa mapping of GF(2)[x] with modulus x^3+x> ][0X
    [4Xgap> List(B3,Order);[0X
    [4X[ 20 ][0X
    [4Xgap> B5 := NormedWords(F,5);[0X
    [4X[ a*b*c*a*c, a*b*c*b*c ][0X
    [4Xgap> B5 := List(B5,g->g^phi);[0X
    [4X[ <bijective rcwa mapping of GF(2)[x] with modulus x^3+x>, [0X
    [4X  <bijective rcwa mapping of GF(2)[x] with modulus x^4+x^3+x^2+x> ][0X
    [4Xgap> List(B5,Order);[0X
    [4X[ 12, 12 ][0X
    [4Xgap> B7 := NormedWords(F,7);[0X
    [4X[ a*b*c*a*c*a*c, a*b*c*a*c*b*c, a*b*c*b*c*a*c, a*b*c*b*c*b*c ][0X
    [4Xgap> B7 := List(B7,g->g^phi);[0X
    [4X[ <bijective rcwa mapping of GF(2)[x] with modulus x^4+x^3+x^2+x>, [0X
    [4X  <bijective rcwa mapping of GF(2)[x] with modulus x^5+x>, [0X
    [4X  <bijective rcwa mapping of GF(2)[x] with modulus x^4+x^3+x^2+x>, [0X
    [4X  <bijective rcwa mapping of GF(2)[x] with modulus x^5+x> ][0X
    [4Xgap> List(B7,Order);[0X
    [4X[ 12, 12, 12, 30 ][0X
    [4Xgap> B9 := NormedWords(F,9);[0X
    [4X[ a*b*c*a*b*c*a*b*c, a*b*c*a*c*a*c*a*c, a*b*c*a*c*a*c*b*c, a*b*c*a*c*b*c*a*c, [0X
    [4X  a*b*c*a*c*b*c*b*c, a*b*c*b*c*a*c*a*c, a*b*c*b*c*a*c*b*c, a*b*c*b*c*b*c*a*c, [0X
    [4X  a*b*c*b*c*b*c*b*c ][0X
    [4Xgap> B9 := List(B9,g->g^phi);;[0X
    [4Xgap> List(B9,Order);[0X
    [4X[ 20, 4, 30, 12, 42, 30, 4, 42, 12 ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Issue  [10XUnwrapExample("OddNumberOfGens_FiniteOrder");[0m  in order to assign the
  global variables defined in this example.
  
  
  [1X6.9 An abelian rcwa group over a polynomial ring[0X
  
  We enter a 2-generated abelian wild rcwa group over GF(4)[x]:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> x := Indeterminate(GF(4),1);; SetName(x,"x");[0X
    [4Xgap> R := PolynomialRing(GF(4),1);[0X
    [4XGF(2^2)[x][0X
    [4Xgap> e := One(GF(4));;[0X
    [4Xgap> p := x^2 + x + e;;    q := x^2 + e;;[0X
    [4Xgap> r := x^2 + x + Z(4);; s := x^2 + x + Z(4)^2;;[0X
    [4Xgap> cg := List( AllResidues(R,x^2), pol -> [ p, p * pol mod q, q ] );;[0X
    [4Xgap> ch := List( AllResidues(R,x^2), pol -> [ r, r * pol mod s, s ] );;[0X
    [4Xgap> g := RcwaMapping( R, q, cg );[0X
    [4X<rcwa mapping of GF(2^2)[x] with modulus x^2+Z(2)^0>[0X
    [4Xgap> h := RcwaMapping( R, s, ch );[0X
    [4X<rcwa mapping of GF(2^2)[x] with modulus x^2+x+Z(2^2)^2>[0X
    [4Xgap> List([g,h],IsTame);[0X
    [4X[ false, false ][0X
    [4Xgap> G := Group(g,h);[0X
    [4X<rcwa group over GF(2^2)[x] with 2 generators>[0X
    [4Xgap> IsAbelian(G);[0X
    [4Xtrue[0X
    [4Xgap> IsTame(G);[0X
    [4Xfalse[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  It  is  easy  to  see  that all orbits on GF(4)[x] under the action of [10XG[0m are
  finite.
  
  Now we compute the action of the group [10XG[0m on one of its orbits, and make some
  statistics of the orbits of [10XG[0m containing polynomials of degree less than 4:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> orb := Orbit(G,x^5);[0X
    [4X[ x^5, x^5+x^4+x^2+Z(2)^0, x^5+x^3+x^2+Z(2^2)*x+Z(2)^0, x^5+x^3, [0X
    [4X  x^5+x^4+x^3+x^2+Z(2^2)^2*x+Z(2^2)^2, x^5+x, x^5+x^4+x^3, [0X
    [4X  x^5+x^2+Z(2^2)^2*x, x^5+x^4+x^2+x, x^5+x^3+x^2+Z(2^2)^2*x+Z(2)^0, [0X
    [4X  x^5+x^4+Z(2^2)*x+Z(2^2), x^5+x^3+x, x^5+x^4+x^3+x^2+Z(2^2)*x+Z(2^2), [0X
    [4X  x^5+x^4+x^3+x+Z(2)^0, x^5+x^2+Z(2^2)*x, x^5+x^4+Z(2^2)^2*x+Z(2^2)^2 ][0X
    [4Xgap> H := Action(G,orb);[0X
    [4XGroup([ (1,2,4,7,6,9,12,14)(3,5,8,11,10,13,15,16), [0X
    [4X  (1,3,6,10)(2,5,9,13)(4,8,12,15)(7,11,14,16) ])[0X
    [4Xgap> IsAbelian(H); # check ...[0X
    [4Xtrue[0X
    [4Xgap> IsCyclic(H);  # H, and therefore also G, is not cyclic[0X
    [4Xfalse[0X
    [4Xgap> Exponent(H);[0X
    [4X8[0X
    [4Xgap> Collected(List(ShortOrbits(G,AllResidues(R,x^4),100),Length));[0X
    [4X[ [ 1, 4 ], [ 2, 6 ], [ 4, 12 ], [ 8, 24 ] ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Changing  the generators a little changes the structure of the group and its
  action on the underlying ring a lot:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> cg[1][2] := cg[1][2] + (x^2 + e) * p * q;;[0X
    [4Xgap> ch[7][2] := ch[7][2] + x * r * s;;[0X
    [4Xgap> g := RcwaMapping( R, q, cg );; h := RcwaMapping( R, s, ch );;[0X
    [4Xgap> G := Group(g,h);[0X
    [4X<rcwa group over GF(2^2)[x] with 2 generators>[0X
    [4Xgap> IsAbelian(G);[0X
    [4Xfalse[0X
    [4Xgap> Support(G);[0X
    [4XGF(2^2)[x] \ [ Z(2)^0, Z(2^2), Z(2^2)^2 ][0X
    [4Xgap> orb := Orbit(G,Zero(R));;[0X
    [4Xgap> Length(orb);[0X
    [4X87[0X
    [4Xgap> StructureDescription(Action(G,orb));[0X
    [4X"A87"[0X
    [4Xgap> Collected(List(orb,DegreeOfLaurentPolynomial));[0X
    [4X[ [ 1, 2 ], [ 2, 4 ], [ 3, 16 ], [ 4, 64 ], [ infinity, 1 ] ][0X
    [4Xgap> S := AllResidues(R,x^6);;[0X
    [4Xgap> orbs := ShortOrbits(G,S,-1:finite);;[0X
    [4Xgap> List(orbs,Length);[0X
    [4X[ 87, 1, 1, 1, 2, 2, 2, 2, 2, 4, 4, 4, 20, 4, 12, 4, 20, 4, 4, 12, 8, 8, [0X
    [4X  48, 48, 16, 8, 8, 56, 8, 88, 8, 8, 8, 400, 16, 48, 16, 16, 16, 80, 16, [0X
    [4X  16, 16, 96, 32, 192, 32, 16, 16, 416, 16, 48, 16, 16, 880, 16, 16, 16, [0X
    [4X  16, 16, 16, 16, 16, 16, 848, 16, 16, 32, 16, 16, 16, 16, 16, 16, 16 ][0X
    [4Xgap> Position(last,880);[0X
    [4X55[0X
    [4Xgap> Set(orbs[55],DegreeOfLaurentPolynomial); # all elm's have same degree[0X
    [4X[ 5 ][0X
    [4Xgap> H := Action(G,orbs[55]);;[0X
    [4Xgap> IsPrimitive(H,MovedPoints(H));[0X
    [4Xfalse[0X
    [4Xgap> List(Blocks(H,MovedPoints(H)),Length);[0X
    [4X[ 110, 110, 110, 110, 110, 110, 110, 110 ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Issue  [10XUnwrapExample("AbelianGroupOverPolynomialRing");[0m to assign the global
  variables defined in this example.
  
  
  [1X6.10 Checking for solvability[0X
  
  Presently  there is no general method available for testing wild rcwa groups
  for  solvability.  However,  sometimes  the  question for solvability can be
  answered  anyway.  In  the  example  below, the idea is to find a subgroup [3XU[0m
  which  acts  on  a  finite  set [3XS[0m  of  integers,  and  which  induces on [3XS[0m a
  non-solvable finite permutation group:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> a := RcwaMapping([[3,0,2],[3, 1,4],[3,0,2],[3,-1,4]]);;[0X
    [4Xgap> b := RcwaMapping([[3,0,2],[3,13,4],[3,0,2],[3,-1,4]]);;[0X
    [4Xgap> G := Group(a,b);;[0X
    [4Xgap> ShortOrbits(Group(Comm(a,b)),[-10..10],100);[0X
    [4X[ [ -10 ], [ -9 ], [ -30, -21, -14, -13, -11, -8 ], [ -7 ], [ -6 ], [0X
    [4X  [ -12, -5, -4, -3, -2, 1 ], [ -1 ], [ 0 ], [ 2 ], [ 3 ], [0X
    [4X  [ 4, 5, 6, 7, 10, 15 ], [ 8 ], [ 9 ] ][0X
    [4Xgap> S := [ 4, 5, 6, 7, 10, 15 ];;[0X
    [4Xgap> Cycle(Comm(a,b),4);[0X
    [4X[ 4, 7, 10, 15, 5, 6 ][0X
    [4Xgap> elm := RepresentativeAction(G,S,Permuted(S,(1,4)),OnTuples);[0X
    [4X<bijective rcwa mapping of Z with modulus 81>[0X
    [4Xgap> List(S,n->n^elm);[0X
    [4X[ 7, 5, 6, 4, 10, 15 ][0X
    [4Xgap> U := Group(Comm(a,b),elm);[0X
    [4X<rcwa group over Z with 2 generators>[0X
    [4Xgap> Action(U,S);[0X
    [4XGroup([ (1,4,5,6,2,3), (1,4) ])[0X
    [4Xgap> IsNaturalSymmetricGroup(last);[0X
    [4Xtrue[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Thus  the  subgroup  [3XU[0m  induces  on [3XS[0m a natural symmetric group of degree 6.
  Therefore the group [3XG[0m is not solvable. We conclude this example by factoring
  the group element [3Xelm[0m into generators:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> F := FreeGroup("a","b");[0X
    [4X<free group on the generators [ a, b ]>[0X
    [4Xgap> RepresentativeActionPreImage(G,S,Permuted(S,(1,4)),OnTuples,F);[0X
    [4Xa^-2*b^-2*a*b*a^-1*b*a*b^-2*a[0X
    [4Xgap> a^-2*b^-2*a*b*a^-1*b*a*b^-2*a = elm;[0X
    [4Xtrue[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Issue   [10XUnwrapExample("CheckingForSolvability");[0m   to   assign   the  global
  variables [10Xa[0m, [10Xb[0m and [10XG[0m defined in this example.
  
  
  [1X6.11 Some examples over (semi)localizations of the integers[0X
  
  We  start  with  something one can observe when trying to "transfer" an rcwa
  mapping from the ring of integers to one of its localizations:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> a := RcwaMapping([[3,0,2],[3,1,4],[3,0,2],[3,-1,4]]);;[0X
    [4Xgap> IsBijective(a);[0X
    [4Xtrue[0X
    [4Xgap> a2 := LocalizedRcwaMapping(a,2);[0X
    [4X<rcwa mapping of Z_( 2 ) with modulus 4>[0X
    [4Xgap> IsSurjective(a2); # As expected[0X
    [4Xtrue[0X
    [4Xgap> IsInjective(a2); # Why not??[0X
    [4Xfalse[0X
    [4Xgap> 0^a2;[0X
    [4X0[0X
    [4Xgap> (1/3)^a2; # That's the reason![0X
    [4X0[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  The  above  can also be explained easily by pointing out that the modulus of
  the  inverse  of  [10Xa[0m  is 3,  and that 3 is a unit of ℤ_(2). Moving to ℤ_(2,3)
  solves this problem:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> a23 := SemilocalizedRcwaMapping(a,[2,3]);[0X
    [4X<rcwa mapping of Z_( 2, 3 ) with modulus 4>[0X
    [4Xgap> IsBijective(a23);[0X
    [4Xtrue[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  We get additional finite cycles, e.g.:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> List(ShortOrbits(Group(a23),[0..50]/5,50),orb->Cycle(a23,orb[1]));[0X
    [4X[ [ 0 ], [ 1/5, 2/5, 3/5 ], [0X
    [4X  [ 4/5, 6/5, 9/5, 8/5, 12/5, 18/5, 27/5, 19/5, 13/5, 11/5, 7/5 ], [0X
    [4X  [ 1 ], [ 2, 3 ], [ 14/5, 21/5, 17/5 ], [0X
    [4X  [ 16/5, 24/5, 36/5, 54/5, 81/5, 62/5, 93/5, 71/5, 52/5, 78/5, 117/5, [0X
    [4X      89/5, 68/5, 102/5, 153/5, 116/5, 174/5, 261/5, 197/5, 149/5, [0X
    [4X      113/5, 86/5, 129/5, 98/5, 147/5, 109/5, 83/5, 61/5, 47/5, 34/5, [0X
    [4X      51/5, 37/5, 29/5, 23/5 ], [ 4, 6, 9, 7, 5 ] ][0X
    [4Xgap> List(last,Length);[0X
    [4X[ 1, 3, 11, 1, 2, 3, 34, 5 ][0X
    [4Xgap> List(ShortOrbits(Group(a23),[0..50]/7,50),orb->Cycle(a23,orb[1]));[0X
    [4X[ [ 0 ], [ -1/7, 1/7 ], [ 2/7, 3/7, 4/7, 6/7, 9/7, 5/7 ], [ 1 ], [0X
    [4X  [ 2, 3 ], [ 4, 6, 9, 7, 5 ] ][0X
    [4Xgap> List(last,Length);[0X
    [4X[ 1, 2, 6, 1, 2, 5 ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  However  the  structure  of a group with prime set P remains invariant under
  the "transfer" from ℤ to ℤ_(P).
  
  "Transferring"  a  non-invertible  rcwa mapping from the ring of integers to
  some of its (semi)localizations can also turn it into an invertible one:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> v := RcwaMapping([[6,0,1],[1,-7,2],[6,0,1],[1,-1,1],[0X
    [4X>                      [6,0,1],[1, 1,2],[6,0,1],[1,-1,1]]);;[0X
    [4Xgap> Display(v);[0X
    [4X[0X
    [4XRcwa mapping of Z with modulus 8[0X
    [4X[0X
    [4X              n mod 8               |            Image of n[0X
    [4X------------------------------------+------------------------------------[0X
    [4X  0 2 4 6                           | 6n[0X
    [4X  1                                 | (n - 7)/2[0X
    [4X  3 7                               | n - 1[0X
    [4X  5                                 | (n + 1)/2[0X
    [4X[0X
    [4Xgap> IsInjective(v);[0X
    [4Xtrue[0X
    [4Xgap> IsSurjective(v);[0X
    [4Xfalse[0X
    [4Xgap> Image(v);[0X
    [4XZ \ 4(12) U 8(12)[0X
    [4Xgap> Difference(Integers,last);[0X
    [4X4(12) U 8(12)[0X
    [4Xgap> v2 := LocalizedRcwaMapping(v,2);[0X
    [4X<rcwa mapping of Z_( 2 ) with modulus 8>[0X
    [4Xgap> IsBijective(v2);[0X
    [4Xtrue[0X
    [4Xgap> Display(v2^-1);[0X
    [4X[0X
    [4XBijective rcwa mapping of Z_( 2 ) with modulus 4[0X
    [4X[0X
    [4X              n mod 4               |            Image of n[0X
    [4X------------------------------------+------------------------------------[0X
    [4X  0                                 | 1/3 n / 2[0X
    [4X  1                                 | 2 n + 7[0X
    [4X  2                                 | n + 1[0X
    [4X  3                                 | 2 n - 1[0X
    [4X[0X
    [4Xgap> S := ResidueClass(Z_pi(2),2,0);; l := [S];;[0X
    [4Xgap> for i in [1..10] do Add(l,l[Length(l)]^v2); od;[0X
    [4Xgap> l; # Visibly v2 is wild ...[0X
    [4X[ 0(2), 0(4), 0(8), 0(16), 0(32), 0(64), 0(128), 0(256), 0(512),[0X
    [4X  0(1024), 0(2048) ][0X
    [4Xgap> w2 := RcwaMapping(Z_pi(2),[[1,0,2],[2,-1,1],[1,1,1],[2,-1,1]]);;[0X
    [4Xgap> v2w2 := Comm(v2,w2);; v2w2^-1;;[0X
    [4Xgap> Display(v2w2);[0X
    [4X[0X
    [4XBijective rcwa mapping of Z_( 2 ) with modulus 8[0X
    [4X[0X
    [4X              n mod 8               |            Image of n[0X
    [4X------------------------------------+------------------------------------[0X
    [4X  0 3 4 7                           | n[0X
    [4X  1                                 | n + 4[0X
    [4X  2 6                               | 3 n[0X
    [4X  5                                 | n - 4[0X
    [4X[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Again, viewed as an rcwa mapping of the integers the commutator given at the
  end of the example would not be surjective.
  
  Issue [10XUnwrapExample("Semilocals");[0m to assign the global variables defined in
  this example.
  
  
  [1X6.12 Twisting 257-cycles into an rcwa mapping with modulus 32[0X
  
  We define an rcwa mapping [3Xx[0m of order 257 with modulus 32. The easiest way to
  construct  such  a  mapping  is  to prescribe a transition graph and then to
  assign suitable affine mappings to its vertices.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> x_257 := RcwaMapping([0X
    [4X>      [[ 16,  2,  1], [ 16, 18,  1], [  1, 16,  1], [ 16, 18,  1],[0X
    [4X>       [  1, 16,  1], [ 16, 18,  1], [  1, 16,  1], [ 16, 18,  1],[0X
    [4X>       [  1, 16,  1], [ 16, 18,  1], [  1, 16,  1], [ 16, 18,  1],[0X
    [4X>       [  1, 16,  1], [ 16, 18,  1], [  1, 16,  1], [ 16, 18,  1],[0X
    [4X>       [  1,  0, 16], [ 16, 18,  1], [  1,-14,  1], [ 16, 18,  1],[0X
    [4X>       [  1,-14,  1], [ 16, 18,  1], [  1,-14,  1], [ 16, 18,  1],[0X
    [4X>       [  1,-14,  1], [ 16, 18,  1], [  1,-14,  1], [ 16, 18,  1],[0X
    [4X>       [  1,-14,  1], [ 16, 18,  1], [  1,-14,  1], [  1,-31,  1]]);;[0X
    [4Xgap> Order(x_257);; Display(x_257);[0X
    [4X[0X
    [4XBijective rcwa mapping of Z with modulus 32, of order 257[0X
    [4X[0X
    [4X              n mod 32              |             Image of n[0X
    [4X------------------------------------+------------------------------------[0X
    [4X   0                                | 16n + 2[0X
    [4X   1  3  5  7  9 11 13 15 17 19 21  |[0X
    [4X  23 25 27 29                       | 16n + 18[0X
    [4X   2  4  6  8 10 12 14              | n + 16[0X
    [4X  16                                | n/16[0X
    [4X  18 20 22 24 26 28 30              | n - 14[0X
    [4X  31                                | n - 31[0X
    [4X[0X
    [4Xgap> Length(Cycle(x_257,0));[0X
    [4X257[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Issue   [10XUnwrapExample("LongCyclesOfPrimeLength");[0m   to   assign  the  global
  variable [10Xx_257[0m defined in this example.
  
  
  [1X6.13 The behaviour of the moduli of powers[0X
  
  We  give  some examples of how the series of the moduli of powers of a given
  rcwa mapping of the integers can look like.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> a := RcwaMapping([[3,0,2],[3, 1,4],[3,0,2],[3,-1,4]]);;[0X
    [4Xgap> List([0..4],i->Modulus(a^i));[0X
    [4X[ 1, 4, 16, 64, 256 ][0X
    [4Xgap> e1 := RcwaMapping([[1,4,1],[2,0,1],[1,0,2],[2,0,1]]);;[0X
    [4Xgap> e2 := RcwaMapping([[1,4,1],[2,0,1],[1,0,2],[1,0,1],[0X
    [4X>                       [1,4,1],[2,0,1],[1,0,1],[1,0,1]]);;[0X
    [4Xgap> List([e1,e2],Order);[0X
    [4X[ infinity, infinity ][0X
    [4Xgap> List([1..20],i->Modulus(e1^i));[0X
    [4X[ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 ][0X
    [4Xgap> List([1..20],i->Modulus(e2^i));[0X
    [4X[ 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4 ][0X
    [4Xgap> Display(e2);[0X
    [4X[0X
    [4XBijective rcwa mapping of Z with modulus 8, of order infinity[0X
    [4X[0X
    [4X              n mod 8               |            Image of n[0X
    [4X------------------------------------+------------------------------------[0X
    [4X  0 4                               | n + 4[0X
    [4X  1 5                               | 2n[0X
    [4X  2                                 | n/2[0X
    [4X  3 6 7                             | n[0X
    [4X[0X
    [4Xgap> e2^2 = Restriction(RcwaMapping([[1,2,1]]),RcwaMapping([[4,0,1]]));[0X
    [4Xtrue[0X
    [4Xgap> g:=RcwaMapping([[2,2,1],[1, 4,1],[1,0,2],[2,2,1],[1,-4,1],[1,-2,1]]);;[0X
    [4Xgap> h:=RcwaMapping([[2,2,1],[1,-2,1],[1,0,2],[2,2,1],[1,-1,1],[1, 1,1]]);;[0X
    [4Xgap> List([0..7],i->Modulus(g^i));[0X
    [4X[ 1, 6, 12, 12, 12, 12, 6, 1 ][0X
    [4Xgap> List([1..18],i->Modulus((g^3*h)^i));[0X
    [4X[ 12, 6, 12, 12, 12, 6, 12, 6, 12, 12, 12, 6, 12, 6, 12, 12, 12, 6 ][0X
    [4Xgap> u := RcwaMapping([[3,0,5],[9,1,5],[3,-1,5],[9,-2,5],[9,4,5]]);;[0X
    [4Xgap> List([0..3],i->Modulus(u^i));[0X
    [4X[ 1, 5, 25, 125 ][0X
    [4Xgap> v6 := RcwaMapping([[-1,2,1],[1,-1,1],[1,-1,1]]);;[0X
    [4Xgap> List([0..6],i->Modulus(v6^i));[0X
    [4X[ 1, 3, 3, 3, 3, 3, 1 ][0X
    [4Xgap> w8 := RcwaMapping([[-1,3,1],[1,-1,1],[1,-1,1],[1,-1,1]]);;[0X
    [4Xgap> List([0..8],i->Modulus(w8^i));[0X
    [4X[ 1, 4, 4, 4, 4, 4, 4, 4, 1 ][0X
    [4Xgap> z := RcwaMapping([[2,1,1],[1, 1,1],[2,-1,1],[2, -2,1],[0X
    [4X>                      [1,6,2],[1, 1,1],[1,-6,2],[2,  5,1],[0X
    [4X>                      [1,6,2],[1, 1,1],[1, 1,1],[2, -5,1],[0X
    [4X>                      [1,0,1],[1,-4,1],[1, 0,1],[2,-10,1]]);;[0X
    [4Xgap> IsBijective(z);[0X
    [4Xtrue[0X
    [4Xgap> List([0..25],i->Modulus(z^i));[0X
    [4X[ 1, 16, 32, 64, 64, 128, 128, 128, 128, 128, 128, 256, 256, 256, 256, [0X
    [4X  256, 256, 512, 512, 512, 512, 512, 512, 1024, 1024, 1024 ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Issue   [10XUnwrapExample("ModuliOfPowers");[0m  to  assign  the  global  variables
  defined in this example.
  
  
  [1X6.14 Images and preimages under the Collatz mapping[0X
  
  We  have  a look at the images of the residue class 1(2) under powers of the
  Collatz mapping.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> T := RcwaMapping([[1,0,2],[3,1,2]]);;[0X
    [4Xgap> S0 := ResidueClass(Integers,2,1);;[0X
    [4Xgap> S1 := S0^T;[0X
    [4X2(3)[0X
    [4Xgap> S2 := S1^T;[0X
    [4X1(3) U 8(9)[0X
    [4Xgap> S3 := S2^T;[0X
    [4X2(3) U 4(9)[0X
    [4Xgap> S4 := S3^T;[0X
    [4XZ \ 0(3) U 5(9)[0X
    [4Xgap> S5 := S4^T;[0X
    [4XZ \ 0(3) U 7(9)[0X
    [4Xgap> S6 := S5^T;[0X
    [4XZ \ 0(3)[0X
    [4Xgap> S7 := S6^T;[0X
    [4XZ \ 0(3)[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Thus  the  image  gets stable after applying the mapping T for the 6th time.
  Hence  T^6  maps  the  residue class 1(2) surjectively onto the union of the
  residue classes 1(3) and 2(3), which T stabilizes setwise. Now we would like
  to  determine  the preimages of 1(3) and 2(3) in 1(2) under T^6. The residue
  class 1(2) has to be the disjoint union of these sets.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> U := Intersection(PreImage(T^6,ResidueClass(Integers,3,1)),S0);[0X
    [4X<union of 11 residue classes (mod 64)>[0X
    [4Xgap> V := Intersection(PreImage(T^6,ResidueClass(Integers,3,2)),S0);[0X
    [4X<union of 21 residue classes (mod 64)>[0X
    [4Xgap> AsUnionOfFewClasses(U);[0X
    [4X[ 1(64), 5(64), 7(64), 9(64), 21(64), 23(64), 29(64), 31(64), 49(64), [0X
    [4X  51(64), 59(64) ][0X
    [4Xgap> AsUnionOfFewClasses(V);[0X
    [4X[ 3(32), 11(32), 13(32), 15(32), 25(32), 17(64), 19(64), 27(64), 33(64), [0X
    [4X  37(64), 39(64), 41(64), 53(64), 55(64), 61(64), 63(64) ][0X
    [4Xgap> Union(U,V) = S0 and Intersection(U,V) = [];  # consistency check[0X
    [4Xtrue[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  The images of the residue class 0(3) under powers of T look as follows:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> S0 := ResidueClass(Integers,3,0);[0X
    [4X0(3)[0X
    [4Xgap> S1 := S0^T;[0X
    [4X0(3) U 5(9)[0X
    [4Xgap> S2 := S1^T;[0X
    [4X0(3) U 5(9) U 7(9) U 8(27)[0X
    [4Xgap> S3 := S2^T;[0X
    [4X<union of 20 residue classes (mod 27)>[0X
    [4Xgap> S4 := S3^T;[0X
    [4X<union of 73 residue classes (mod 81)>[0X
    [4Xgap> S5 := S4^T;[0X
    [4XZ \ 10(81) U 37(81)[0X
    [4Xgap> S6 := S5^T;[0X
    [4XIntegers[0X
    [4Xgap> S7 := S6^T;[0X
    [4XIntegers[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Thus  every  integer  is  the image of a multiple of 3 under T^6. This means
  that it would be sufficient to prove the 3n+1 Conjecture for multiples of 3.
  We can obtain the corresponding result for multiples of 5 as follows:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> S := [ResidueClass(Integers,5,0)];[0X
    [4X[ 0(5) ][0X
    [4Xgap> for i in [1..12] do Add(S,S[i]^T); od;[0X
    [4Xgap> for s in S do View(s); Print("\n"); od;[0X
    [4X0(5)[0X
    [4X0(5) U 8(15)[0X
    [4X0(5) U 4(15) U 8(15)[0X
    [4X0(5) U 2(15) U 4(15) U 8(15) U 29(45)[0X
    [4X<union of 73 residue classes (mod 135)>[0X
    [4X<union of 244 residue classes (mod 405)>[0X
    [4X<union of 784 residue classes (mod 1215)>[0X
    [4X<union of 824 residue classes (mod 1215)>[0X
    [4X<union of 2593 residue classes (mod 3645)>[0X
    [4X<union of 2647 residue classes (mod 3645)>[0X
    [4X<union of 2665 residue classes (mod 3645)>[0X
    [4X<union of 2671 residue classes (mod 3645)>[0X
    [4X1(3) U 2(3) U 0(15)[0X
    [4Xgap> Union(S[13],ResidueClass(Integers,3,0));[0X
    [4XIntegers[0X
    [4Xgap>  List(S,Si->Float(Density(Si)));[0X
    [4X[ 0.2, 0.266667, 0.333333, 0.422222, 0.540741, 0.602469, 0.645267, [0X
    [4X  0.678189, 0.711385, 0.7262, 0.731139, 0.732785, 0.733333 ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Issue  [10XUnwrapExample("CollatzMapping");[0m  to  assign  the  global  variable [10XT[0m
  defined in this example.
  
  
  [1X6.15 A group which acts 4-transitively on the positive integers[0X
  
  In this section, we would like to show that the group G generated by the two
  wild mappings
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> a := RcwaMapping([[3,0,2],[3,1,4],[3,0,2],[3,-1,4]]);;[0X
    [4Xgap> u := RcwaMapping([[3,0,5],[9,1,5],[3,-1,5],[9,-2,5],[9,4,5]]);;[0X
    [4Xgap> SetName(a,"a"); SetName(u,"u"); G := Group(a,u);;[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  which  we  have already investigated in earlier examples acts 4-transitively
  on  the  set of positive integers. Obviously, it acts on the set of positive
  integers. First we show that this action is transitive. We start by checking
  in  which residue classes sufficiently large positive integers are mapped to
  smaller ones by a suitable group element:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> List([a,a^-1,u,u^-1],DecreasingOn);[0X
    [4X[ 1(2), 0(3), 0(5) U 2(5), 2(3) ][0X
    [4Xgap> Union(last);[0X
    [4XZ \ 4(30) U 16(30) U 28(30)[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  We  see  that  we  cannot always choose such a group element from the set of
  generators and their inverses -- otherwise the union would be [10XIntegers[0m.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> List([a,a^-1,u,u^-1,a^2,a^-2,u^2,u^-2],DecreasingOn);[0X
    [4X[ 1(2), 0(3), 0(5) U 2(5), 2(3), 1(8) U 7(8), 0(3) U 2(9) U 7(9), [0X
    [4X  0(25) U 12(25) U 17(25) U 20(25), 2(3) U 1(9) U 3(9) ][0X
    [4Xgap> Union(last); # Still not enough ...[0X
    [4XZ \ 4(90) U 58(90) U 76(90)[0X
    [4Xgap> List([a,a^-1,u,u^-1,a^2,a^-2,u^2,u^-2,a*u,u*a,(a*u)^-1,(u*a)^-1],[0X
    [4X>         DecreasingOn);[0X
    [4X[ 1(2), 0(3), 0(5) U 2(5), 2(3), 1(8) U 7(8), 0(3) U 2(9) U 7(9), [0X
    [4X  0(25) U 12(25) U 17(25) U 20(25), 2(3) U 1(9) U 3(9), [0X
    [4X  3(5) U 0(10) U 7(20) U 9(20), 0(5) U 2(5), 2(3), 3(9) U 4(9) U 8(9) ][0X
    [4Xgap> Union(last); # ... but that's it![0X
    [4XIntegers[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Finally,  we have to deal with "small" integers. We use the notation for the
  coefficients  of  rcwa  mappings introduced at the beginning of this manual.
  Let  c_r(m)  >  a_r(m).  Then we easily see that (a_r(m)n+b_r(m))/c_r(m) > n
  implies  n < b_r(m)/(c_r(m)-a_r(m)). Thus we can restrict our considerations
  to  integers  n  <  b_  max,  where  b_ max is the largest second entry of a
  coefficient triple of one of the group elements in our list:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> List([a,a^-1,u,u^-1,a^2,a^-2,u^2,u^-2,a*u,u*a,(a*u)^-1,(u*a)^-1],[0X
    [4X>         f->Maximum(List(Coefficients(f),c->c[2])));[0X
    [4X[ 1, 1, 4, 2, 7, 7, 56, 28, 25, 17, 17, 11 ][0X
    [4Xgap> Maximum(last);[0X
    [4X56[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Thus  this  upper  bound  is 56. The rest is easy -- all we have to do is to
  check  that the orbit containing 1 contains also all other positive integers
  less than or equal to 56:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> S := [1];;[0X
    [4Xgap> while not IsSubset(S,[1..56]) do[0X
    [4X>      S := Union(S,S^a,S^u,S^(a^-1),S^(u^-1));[0X
    [4X>    od;[0X
    [4Xgap> IsSubset(S,[1..56]);[0X
    [4Xtrue[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Checking 2-transitivity is computationally harder, and in the sequel we will
  omit  some  steps which are in practice needed to find out "what to do". The
  approach  taken  here  is  to  show  that  the  stabilizer  of 1  in G  acts
  transitively  on  the set of positive integers greater than 1. We do this by
  similar  means as used above for showing the transitivity of the action of G
  on  the positive integers. We start by determining all products of at most 5
  generators and their inverses, which stabilize 1 (taking at most 4-generator
  products would not suffice!):
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> gens := [a,u,a^-1,u^-1];;[0X
    [4Xgap> tups := Concatenation(List([1..5],k->Tuples([1..4],k)));;[0X
    [4Xgap> Length(tups);[0X
    [4X1364[0X
    [4Xgap> tups := Filtered(tups,tup->ForAll([[1,3],[3,1],[2,4],[4,2]],[0X
    [4X>                                      l->PositionSublist(tup,l)=fail));;[0X
    [4Xgap> Length(tups);[0X
    [4X484[0X
    [4Xgap> stab := [];;[0X
    [4Xgap> for tup in tups do[0X
    [4X>      n := 1;[0X
    [4X>      for i in tup do n := n^gens[i]; od;[0X
    [4X>      if n = 1 then Add(stab,tup); fi;[0X
    [4X>    od;[0X
    [4Xgap> Length(stab);[0X
    [4X118[0X
    [4Xgap> stabelm := List(stab,tup->Product(List(tup,i->gens[i])));;[0X
    [4Xgap> ForAll(stabelm,elm->1^elm=1); # Check.[0X
    [4Xtrue[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  The resulting products have various different not quite small moduli:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> List(stabelm,Modulus);[0X
    [4X[ 4, 3, 16, 25, 9, 81, 64, 100, 108, 100, 25, 75, 27, 243, 324, 243, [0X
    [4X  256, 400, 144, 400, 100, 432, 324, 400, 80, 400, 625, 25, 75, 135, [0X
    [4X  150, 75, 225, 81, 729, 486, 729, 144, 144, 81, 729, 1296, 729, 6561, [0X
    [4X  1024, 1600, 192, 1600, 400, 576, 432, 1600, 320, 1600, 2500, 100, 100, [0X
    [4X  180, 192, 192, 108, 972, 1728, 972, 8748, 1600, 400, 320, 80, 1600, [0X
    [4X  2500, 300, 2500, 625, 625, 75, 675, 75, 75, 135, 405, 600, 120, 600, [0X
    [4X  1875, 75, 225, 405, 225, 225, 675, 243, 2187, 729, 2187, 216, 216, [0X
    [4X  243, 2187, 1944, 2187, 19683, 576, 144, 576, 432, 81, 81, 729, 2187, [0X
    [4X  5184, 324, 8748, 243, 2187, 19683, 26244, 19683 ][0X
    [4Xgap> Lcm(last);[0X
    [4X12597120000[0X
    [4Xgap> Collected(Factors(last));[0X
    [4X[ [ 2, 10 ], [ 3, 9 ], [ 5, 4 ] ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Similar  as  before,  we determine for any of the above mappings the residue
  classes  whose  elements larger than the largest b_r(m) - coefficient of the
  respective mapping are mapped to smaller integers:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> decs := List(stabelm,DecreasingOn);;[0X
    [4Xgap> List(decs,Modulus);[0X
    [4X[ 2, 3, 8, 25, 9, 9, 16, 100, 12, 50, 25, 75, 27, 81, 54, 81, 64, 400, [0X
    [4X  48, 200, 100, 72, 108, 400, 80, 200, 625, 25, 75, 45, 75, 75, 225, 81, [0X
    [4X  243, 81, 243, 144, 144, 81, 243, 216, 243, 243, 128, 1600, 64, 400, [0X
    [4X  400, 48, 144, 1600, 320, 400, 2500, 100, 100, 60, 96, 192, 108, 324, [0X
    [4X  144, 324, 972, 400, 400, 80, 80, 400, 2500, 100, 1250, 625, 625, 25, [0X
    [4X  75, 75, 75, 45, 135, 600, 120, 150, 1875, 75, 225, 135, 225, 225, 675, [0X
    [4X  243, 729, 243, 729, 108, 216, 243, 729, 162, 729, 2187, 144, 144, 144, [0X
    [4X  144, 81, 81, 243, 729, 1296, 324, 972, 243, 729, 2187, 1458, 2187 ][0X
    [4Xgap> Lcm(last);[0X
    [4X174960000[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Since  the  least  common  multiple of the moduli of these unions of residue
  classes  is as large as 174960000, directly forming their union and checking
  whether  it  is equal to the set of integers would take relatively much time
  and  memory.  However, starting with the set of integers and subtracting the
  above sets one-by-one in a suitably chosen order is cheap:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> SortParallel(decs,stabelm,[0X
    [4X>      function(S1,S2)[0X
    [4X>        return First([1..100],k->Factorial(k) mod Modulus(S1)=0)[0X
    [4X>             < First([1..100],k->Factorial(k) mod Modulus(S2)=0);[0X
    [4X>      end);[0X
    [4Xgap> S := Integers;;[0X
    [4Xgap> for i in [1..Length(decs)] do[0X
    [4X>      S_old := S; S := Difference(S,decs[i]);[0X
    [4X>      if S <> S_old then ViewObj(S); Print("\n"); fi;[0X
    [4X>      if S = [] then maxind := i; break; fi;[0X
    [4X>    od;[0X
    [4X0(2)[0X
    [4X2(6) U 4(6)[0X
    [4X<union of 8 residue classes (mod 30)>[0X
    [4X<union of 19 residue classes (mod 90)>[0X
    [4X<union of 114 residue classes (mod 720)>[0X
    [4X<union of 99 residue classes (mod 720)>[0X
    [4X<union of 57 residue classes (mod 720)>[0X
    [4X<union of 54 residue classes (mod 720)>[0X
    [4X<union of 41 residue classes (mod 720)>[0X
    [4X<union of 35 residue classes (mod 720)>[0X
    [4X<union of 8 residue classes (mod 720)>[0X
    [4X4(720) U 94(720) U 148(720) U 238(720)[0X
    [4X<union of 24 residue classes (mod 5760)>[0X
    [4X<union of 72 residue classes (mod 51840)>[0X
    [4X<union of 48 residue classes (mod 51840)>[0X
    [4X<union of 192 residue classes (mod 259200)>[0X
    [4X<union of 168 residue classes (mod 259200)>[0X
    [4X<union of 120 residue classes (mod 259200)>[0X
    [4X<union of 96 residue classes (mod 259200)>[0X
    [4X<union of 72 residue classes (mod 259200)>[0X
    [4X<union of 60 residue classes (mod 259200)>[0X
    [4X<union of 48 residue classes (mod 259200)>[0X
    [4X<union of 24 residue classes (mod 259200)>[0X
    [4X<union of 12 residue classes (mod 259200)>[0X
    [4X<union of 24 residue classes (mod 777600)>[0X
    [4X<union of 12 residue classes (mod 777600)>[0X
    [4X111604(194400) U 14404(777600) U 208804(777600)[0X
    [4X[  ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Similar  as  above, it remains to check that the "small" integers all lie in
  the  orbit  containing 2.  Obviously,  it  is  sufficient  to check that any
  integer  greater  than 2  is mapped to a smaller one by some suitably chosen
  element of the stabilizer under consideration:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> Maximum(List(stabelm{[1..maxind]},[0X
    [4X>                 f->Maximum(List(Coefficients(f),c->c[2]))));[0X
    [4X6581[0X
    [4Xgap> Filtered([3..6581],n->Minimum(List(stabelm,elm->n^elm))>=n);[0X
    [4X[ 4 ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  We have to treat 4 separately:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> 1^(u*a*u^2*a^-1*u);[0X
    [4X1[0X
    [4Xgap> 4^(u*a*u^2*a^-1*u);[0X
    [4X3[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Now  we know that any positive integer greater than 1 lies in the same orbit
  under the action of the stabilizer of 1 in G as 2, thus that this stabilizer
  acts  transitively  on  ℕ \ {1}. But this means that we have established the
  2-transitivity of the action of G on ℕ.
  
  In  the  following,  we essentially repeat the above steps to show that this
  action is indeed 3-transitive:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> tups := Concatenation(List([1..6],k->Tuples([1..4],k)));;[0X
    [4Xgap> tups := Filtered(tups,tup->ForAll([[1,3],[3,1],[2,4],[4,2]],[0X
    [4X>                                      l->PositionSublist(tup,l)=fail));;[0X
    [4Xgap> stab := [];;[0X
    [4Xgap> for tup in tups do[0X
    [4X>      l := [1,2];[0X
    [4X>      for i in tup do l := List(l,n->n^gens[i]); od;[0X
    [4X>      if l = [1,2] then Add(stab,tup); fi;[0X
    [4X>    od;[0X
    [4Xgap> Length(stab);[0X
    [4X212[0X
    [4Xgap> stabelm := List(stab,tup->Product(List(tup,i->gens[i])));;[0X
    [4Xgap> decs := List(stabelm,DecreasingOn);;[0X
    [4Xgap> SortParallel(decs,stabelm,function(S1,S2)[0X
    [4X>      return First([1..100],k->Factorial(k) mod Mod(S1)=0)[0X
    [4X>           < First([1..100],k->Factorial(k) mod Mod(S2)=0); end);[0X
    [4Xgap> S := Integers;;[0X
    [4Xgap> for i in [1..Length(decs)] do[0X
    [4X>      S_old := S; S := Difference(S,decs[i]);[0X
    [4X>      if S <> S_old then ViewObj(S); Print("\n"); fi;[0X
    [4X>      if S = [] then break; fi;[0X
    [4X>    od;[0X
    [4XZ \ 1(8) U 7(8)[0X
    [4X<union of 151 residue classes (mod 240)>[0X
    [4X<union of 208 residue classes (mod 720)>[0X
    [4X<union of 51 residue classes (mod 720)>[0X
    [4X<union of 45 residue classes (mod 720)>[0X
    [4X<union of 39 residue classes (mod 720)>[0X
    [4X<union of 33 residue classes (mod 720)>[0X
    [4X<union of 23 residue classes (mod 720)>[0X
    [4X<union of 19 residue classes (mod 720)>[0X
    [4X<union of 17 residue classes (mod 720)>[0X
    [4X<union of 16 residue classes (mod 720)>[0X
    [4X<union of 14 residue classes (mod 720)>[0X
    [4X<union of 8 residue classes (mod 720)>[0X
    [4X<union of 7 residue classes (mod 720)>[0X
    [4X238(360) U 4(720) U 148(720) U 454(720)[0X
    [4X<union of 38 residue classes (mod 5760)>[0X
    [4X<union of 37 residue classes (mod 5760)>[0X
    [4X<union of 25 residue classes (mod 5760)>[0X
    [4X<union of 21 residue classes (mod 5760)>[0X
    [4X<union of 17 residue classes (mod 5760)>[0X
    [4X<union of 16 residue classes (mod 5760)>[0X
    [4X<union of 138 residue classes (mod 51840)>[0X
    [4X<union of 48 residue classes (mod 51840)>[0X
    [4X<union of 32 residue classes (mod 51840)>[0X
    [4X<union of 20 residue classes (mod 51840)>[0X
    [4X<union of 16 residue classes (mod 51840)>[0X
    [4X<union of 68 residue classes (mod 259200)>[0X
    [4X<union of 42 residue classes (mod 259200)>[0X
    [4X<union of 32 residue classes (mod 259200)>[0X
    [4X<union of 26 residue classes (mod 259200)>[0X
    [4X<union of 25 residue classes (mod 259200)>[0X
    [4X<union of 11 residue classes (mod 259200)>[0X
    [4X<union of 10 residue classes (mod 259200)>[0X
    [4X<union of 7 residue classes (mod 259200)>[0X
    [4X13414(129600) U 2164(259200) U 66964(259200) U 228964(259200)[0X
    [4X2164(259200) U 66964(259200) U 228964(259200)[0X
    [4X[  ][0X
    [4Xgap> Maximum(List(stabelm,f->Maximum(List(Coefficients(f),c->c[2]))));[0X
    [4X515816[0X
    [4Xgap> smallnum := [4..515816];;[0X
    [4Xgap> for i in [1..Length(stabelm)] do[0X
    [4X>      smallnum := Filtered(smallnum,n->n^stabelm[i]>=n);[0X
    [4X>    od;[0X
    [4Xgap> smallnum;[0X
    [4X[  ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  The same for 4-transitivity:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> tups := Concatenation(List([1..8],k->Tuples([1..4],k)));;[0X
    [4Xgap> tups := Filtered(tups,tup->ForAll([[1,3],[3,1],[2,4],[4,2]],[0X
    [4X>                                      l->PositionSublist(tup,l)=fail));;[0X
    [4Xgap> stab := [];;[0X
    [4Xgap> for tup in tups do[0X
    [4X>      l := [1,2,3];[0X
    [4X>      for i in tup do l := List(l,n->n^gens[i]); od;[0X
    [4X>      if l = [1,2,3] then Add(stab,tup); fi;[0X
    [4X>    od;[0X
    [4Xgap> Length(stab);[0X
    [4X528[0X
    [4Xgap> stabelm := [];;[0X
    [4Xgap> for i in [1..Length(stab)] do[0X
    [4X>      elm := One(G);[0X
    [4X>      for j in stab[i] do[0X
    [4X>        if Modulus(elm) > 10000 then elm := fail; break; fi;[0X
    [4X>        elm := elm * gens[j];[0X
    [4X>      od;[0X
    [4X>      if elm <> fail then Add(stabelm,elm); fi;[0X
    [4X>    od;[0X
    [4Xgap> Length(stabelm);[0X
    [4X334[0X
    [4Xgap> decs := List(stabelm,DecreasingOn);;[0X
    [4Xgap> SortParallel(decs,stabelm,[0X
    [4X>      function(S1,S2)[0X
    [4X>        return First([1..100],k->Factorial(k) mod Modulus(S1) = 0)[0X
    [4X>             < First([1..100],k->Factorial(k) mod Modulus(S2) = 0);[0X
    [4X>      end);[0X
    [4Xgap> S := Integers;;[0X
    [4Xgap> for i in [1..Length(decs)] do[0X
    [4X>      S_old := S; S := Difference(S,decs[i]);[0X
    [4X>      if S <> S_old then ViewObj(S); Print("\n"); fi;[0X
    [4X>      if S = [] then maxind := i; break; fi;[0X
    [4X>    od;[0X
    [4XZ \ 1(8) U 7(8)[0X
    [4X<union of 46 residue classes (mod 72)>[0X
    [4X<union of 20 residue classes (mod 72)>[0X
    [4X4(18)[0X
    [4X<union of 28 residue classes (mod 576)>[0X
    [4X<union of 22 residue classes (mod 576)>[0X
    [4X<union of 21 residue classes (mod 576)>[0X
    [4X40(72) U 4(144) U 94(144) U 346(576) U 418(576)[0X
    [4X<union of 16 residue classes (mod 576)>[0X
    [4X<union of 15 residue classes (mod 576)>[0X
    [4X4(144) U 94(144) U 346(576) U 418(576)[0X
    [4X<union of 30 residue classes (mod 5184)>[0X
    [4X<union of 26 residue classes (mod 5184)>[0X
    [4X<union of 6 residue classes (mod 1296)>[0X
    [4X<union of 504 residue classes (mod 129600)>[0X
    [4X<union of 324 residue classes (mod 129600)>[0X
    [4X<union of 282 residue classes (mod 129600)>[0X
    [4X<union of 239 residue classes (mod 129600)>[0X
    [4X<union of 218 residue classes (mod 129600)>[0X
    [4X<union of 194 residue classes (mod 129600)>[0X
    [4X<union of 154 residue classes (mod 129600)>[0X
    [4X<union of 97 residue classes (mod 129600)>[0X
    [4X<union of 85 residue classes (mod 129600)>[0X
    [4X<union of 77 residue classes (mod 129600)>[0X
    [4X<union of 67 residue classes (mod 129600)>[0X
    [4X<union of 125 residue classes (mod 259200)>[0X
    [4X<union of 108 residue classes (mod 259200)>[0X
    [4X<union of 107 residue classes (mod 259200)>[0X
    [4X<union of 101 residue classes (mod 259200)>[0X
    [4X<union of 100 residue classes (mod 259200)>[0X
    [4X<union of 84 residue classes (mod 259200)>[0X
    [4X<union of 80 residue classes (mod 259200)>[0X
    [4X<union of 76 residue classes (mod 259200)>[0X
    [4X<union of 70 residue classes (mod 259200)>[0X
    [4X<union of 66 residue classes (mod 259200)>[0X
    [4X<union of 54 residue classes (mod 259200)>[0X
    [4X<union of 53 residue classes (mod 259200)>[0X
    [4X<union of 47 residue classes (mod 259200)>[0X
    [4X<union of 43 residue classes (mod 259200)>[0X
    [4X<union of 31 residue classes (mod 259200)>[0X
    [4X<union of 24 residue classes (mod 259200)>[0X
    [4X<union of 23 residue classes (mod 259200)>[0X
    [4X<union of 13 residue classes (mod 259200)>[0X
    [4X57406(129600) U 115006(129600) U 192676(259200) U 250276(259200)[0X
    [4X57406(129600) U 192676(259200) U 250276(259200) U 374206(388800)[0X
    [4X57406(129600) U 192676(259200) U 250276(259200)[0X
    [4X250276(259200) U 57406(388800) U 316606(388800) U 451876(777600)[0X
    [4X316606(388800) U 451876(777600) U 509476(777600) U 768676(777600)[0X
    [4X<union of 18 residue classes (mod 3110400)>[0X
    [4X451876(777600) U 509476(777600) U 705406(777600) U 768676(777600)[0X
    [4X U 2649406(3110400)[0X
    [4X451876(777600) U 705406(777600) U 768676(777600) U 2649406(3110400)[0X
    [4X451876(777600) U 705406(777600) U 2649406(3110400)[0X
    [4X705406(777600) U 2007076(3110400) U 2649406(3110400) U 2784676(3110400)[0X
    [4X<union of 14 residue classes (mod 9331200)>[0X
    [4X2260606(2332800) U 5759806(9331200) U 5895076(9331200) U 8227876(9331200)[0X
    [4X4593406(6998400) U 15091006(27993600) U 17559076(27993600)[0X
    [4X U 24557476(27993600)[0X
    [4X<union of 14 residue classes (mod 83980800)>[0X
    [4X18590206(20995200) U 24557476(83980800) U 45552676(83980800)[0X
    [4X U 71078206(83980800)[0X
    [4X[  ][0X
    [4Xgap> Maximum(List(stabelm{[1..maxind]},[0X
    [4X>                 f->Maximum(List(Coefficients(f),c->c[2]))));[0X
    [4X58975[0X
    [4Xgap> smallnum := [5..58975];;[0X
    [4Xgap> for i in [1..maxind] do[0X
    [4X>      smallnum := Filtered(smallnum,n->n^stabelm[i]>=n);[0X
    [4X>    od;[0X
    [4Xgap> smallnum;[0X
    [4X[  ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  There is even some evidence that the degree of transitivity of the action of
  G on the positive integers is higher than 4:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> phi := EpimorphismFromFreeGroup(G);[0X
    [4X[ a, u ] -> [ a, u ][0X
    [4Xgap> F := Source(phi);[0X
    [4X<free group on the generators [ a, u ]>[0X
    [4Xgap> List([5..20],[0X
    [4X>         n->RepresentativeActionPreImage(G,[1,2,3,4,5],[0X
    [4X>                                           [1,2,3,4,n],OnTuples,F));[0X
    [4X[ <identity ...>, a^-3*u^4*a*u^-2*a^2, [0X
    [4X  a^-2*u*a^-1*u*a^-1*u*a^-1*u*a^-1*u^-1*a, a^4*u^-2*a^-4, a^-1*u^-4*a, [0X
    [4X  u^2*a^-1*u^2*a^-1*u^-2, u^-2*a^-2*u^4, a^-1*u^2*a, a^-1*u^-6*a, [0X
    [4X  a^2*u^4*a^2*u^2, u^-4*a*u^-2*a^-3, a^-1*u^-2*a^-3*u^4*a^2, [0X
    [4X  a^3*u^2*a*u^2, a*u^-4*a*u^-4*a^-2, u^-2*a*u^2*a*u^-2, u^-4*a^2*u^2 ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Issue  [10XUnwrapExample("CollatzlikePerms");[0m  to  assign the global variables [10Xa[0m
  and [10Xu[0m defined in this example.
  
  
  [1X6.16 A group which acts 3-transitively, but not 4-transitively on ℤ[0X
  
  In  this  section,  we would like to show that the wild group G generated by
  the  two tame mappings n -> n + 1 and tau_1(2),0(4) acts 3-transitively, but
  not 4-transitively on the set of integers.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> G := Group(ClassShift(0,1),ClassTransposition(1,2,0,4));[0X
    [4X<rcwa group over Z with 2 generators>[0X
    [4Xgap> IsTame(G);[0X
    [4Xfalse[0X
    [4Xgap> (G.1^-2*G.2)^3*(G.1^2*G.2)^3; # G <> the free product C_infty * C_2.[0X
    [4XIdentityMapping( Integers )[0X
    [4Xgap> Display(G);[0X
    [4X[0X
    [4XWild rcwa group over Z, generated by[0X
    [4X[0X
    [4X[[0X
    [4XTame bijective rcwa mapping of Z: n -> n + 1[0X
    [4X[0X
    [4XBijective rcwa mapping of Z with modulus 4, of order 2[0X
    [4X[0X
    [4X              n mod 4               |            Image of n[0X
    [4X------------------------------------+------------------------------------[0X
    [4X  0                                 | (n + 2)/2[0X
    [4X  1 3                               | 2n - 2[0X
    [4X  2                                 | n[0X
    [4X[0X
    [4X][0X
    [4X[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  This  group acts transitively on ℤ, since already the cyclic group generated
  by  the  first  of  the two generators does so. Next we have to show that it
  acts  2-transitively.  We  essentially  proceed  as  in  the  example in the
  previous  section, by checking that the stabilizer of 0 acts transitively on
  ℤ \ {0}.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> gens := [ClassShift(0,1)^-1,ClassTransposition(1,2,0,4),ClassShift(0,1)];;[0X
    [4Xgap> tups := Concatenation(List([1..6],k->Tuples([-1,0,1],k)));;[0X
    [4Xgap> tups := Filtered(tups,tup->ForAll([[0,0],[-1,1],[1,-1]],[0X
    [4X>                                      l->PositionSublist(tup,l)=fail));;[0X
    [4Xgap> Length(tups);[0X
    [4X189[0X
    [4Xgap> stab := [];;[0X
    [4Xgap> for tup in tups do[0X
    [4X>      n := 0;[0X
    [4X>      for i in tup do n := n^gens[i+2]; od;[0X
    [4X>      if n = 0 then Add(stab,tup); fi;[0X
    [4X>    od;[0X
    [4Xgap> stabelm := List(stab,tup->Product(List(tup,i->gens[i+2])));;[0X
    [4Xgap> Collected(List(stabelm,Modulus));[0X
    [4X[ [ 4, 6 ], [ 8, 4 ], [ 16, 3 ] ][0X
    [4Xgap> decs := List(stabelm,DecreasingOn);[0X
    [4X[ 0(4), 3(4), 0(4), 3(4), 2(4), 0(4), 4(8), 2(4), 2(4), 0(4), 1(4), [0X
    [4X  0(8), 3(8) ][0X
    [4Xgap> Union(decs);[0X
    [4XIntegers[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Similar  as  in  the previous section, it remains to check that the integers
  with  "small"  absolute  value  all  lie in the orbit containing 1 under the
  action of the stabilizer of 0:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> Maximum(List(stabelm,f->Maximum(List(Coefficients(f),c->AbsInt(c[2])))));[0X
    [4X21[0X
    [4Xgap> S := [1];;[0X
    [4Xgap> for elm in stabelm do S := Union(S,S^elm,S^(elm^-1)); od;[0X
    [4Xgap> IsSubset(S,Difference([-21..21],[0])); # Not yet ..[0X
    [4Xfalse[0X
    [4Xgap> for elm in stabelm do S := Union(S,S^elm,S^(elm^-1)); od;[0X
    [4Xgap> IsSubset(S,Difference([-21..21],[0])); # ... but now![0X
    [4Xtrue[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Now  we  have  to  check  for 3-transitivity. Since we cannot find for every
  residue class an element of the pointwise stabilizer of {0,1} which properly
  divides  its  elements, we also have to take additions and subtractions into
  consideration.  Since the moduli of all of our stabilizer elements are quite
  small, simply looking at sets of representatives is cheap:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> tups := Concatenation(List([1..10],k->Tuples([-1,0,1],k)));;[0X
    [4Xgap> tups := Filtered(tups,tup->ForAll([[0,0],[-1,1],[1,-1]],[0X
    [4X>                                      l->PositionSublist(tup,l)=fail));;[0X
    [4Xgap> Length(tups);[0X
    [4X3069[0X
    [4Xgap> stab := [];;[0X
    [4Xgap> for tup in tups do[0X
    [4X>      l := [0,1];[0X
    [4X>      for i in tup do l := List(l,n->n^gens[i+2]); od;[0X
    [4X>      if l = [0,1] then Add(stab,tup); fi;[0X
    [4X>    od;[0X
    [4Xgap> Length(stab);[0X
    [4X10[0X
    [4Xgap> stabelm := List(stab,tup->Product(List(tup,i->gens[i+2])));;[0X
    [4Xgap> Maximum(List(stabelm,Modulus));[0X
    [4X8[0X
    [4Xgap> Maximum(List(stabelm,[0X
    [4X>                 f->Maximum(List(Coefficients(f),c->AbsInt(c[2])))));[0X
    [4X8[0X
    [4Xgap> decsp := List(stabelm,elm->Filtered([9..16],n->n^elm<n));[0X
    [4X[ [ 9, 13 ], [ 10, 12, 14, 16 ], [ 12, 16 ], [ 9, 13 ], [ 12, 16 ], [0X
    [4X  [ 9, 11, 13, 15 ], [ 9, 11, 13, 15 ], [ 12, 16 ], [ 12, 16 ], [0X
    [4X  [ 9, 11, 13, 15 ] ][0X
    [4Xgap> Union(decsp);[0X
    [4X[ 9, 10, 11, 12, 13, 14, 15, 16 ][0X
    [4Xgap> decsm := List(stabelm,elm->Filtered([-16..-9],n->n^elm>n));[0X
    [4X[ [ -15, -13, -11, -9 ], [ -16, -12 ], [ -16, -12 ], [ -15, -11 ], [0X
    [4X  [ -16, -14, -12, -10 ], [ -15, -11 ], [ -15, -11 ], [0X
    [4X  [ -16, -14, -12, -10 ], [ -16, -14, -12, -10 ], [ -15, -11 ] ][0X
    [4Xgap> Union(decsm);[0X
    [4X[ -16, -15, -14, -13, -12, -11, -10, -9 ][0X
    [4Xgap> S := [2];;[0X
    [4Xgap> for elm in stabelm do S := Union(S,S^elm,S^(elm^-1)); od;[0X
    [4Xgap> IsSubset(S,Difference([-8..8],[0,1]));[0X
    [4Xtrue[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  At  this  point we have established 3-transitivity. It remains to check that
  the  group  G does not act 4-transitively. We do this by checking that it is
  not  transitive on 4-tuples (mod 4). Since n mod 8 determines the image of n
  under a generator of G (mod 4), it suffices to compute (mod 8):
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> orb := [[0,1,2,3]];;[0X
    [4Xgap> extend := function ()[0X
    [4X>      local gen;[0X
    [4X>      for gen in gens do[0X
    [4X>        orb := Union(orb,List(orb,l->List(l,n->n^gen) mod 8));[0X
    [4X>      od;[0X
    [4X>    end;;[0X
    [4Xgap> repeat[0X
    [4X>      old := ShallowCopy(orb);[0X
    [4X>      extend(); Print(Length(orb),"\n");[0X
    [4X>    until orb = old;[0X
    [4X7[0X
    [4X27[0X
    [4X97[0X
    [4X279[0X
    [4X573[0X
    [4X916[0X
    [4X1185[0X
    [4X1313[0X
    [4X1341[0X
    [4X1344[0X
    [4X1344[0X
    [4Xgap> Length(Set(List(orb,l->l mod 4)));[0X
    [4X120[0X
    [4Xgap> last < 4^4;[0X
    [4Xtrue[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  This   shows   that  G  acts  not  4-transitively  on ℤ.  The  corresponding
  calculation for 3-tuples looks as follows:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> orb := [[0,1,2]];;[0X
    [4Xgap> repeat[0X
    [4X>      old := ShallowCopy(orb);[0X
    [4X>      extend(); Print(Length(orb),"\n");[0X
    [4X>    until orb = old;[0X
    [4X7[0X
    [4X27[0X
    [4X84[0X
    [4X207[0X
    [4X363[0X
    [4X459[0X
    [4X503[0X
    [4X512[0X
    [4X512[0X
    [4Xgap> Length(Set(List(orb,l->l mod 4)));[0X
    [4X64[0X
    [4Xgap> last = 4^3;[0X
    [4Xtrue[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Needless  to  say  that the latter kind of argumentation is not suitable for
  proving, but only for disproving k-transitivity.
  
  
  [1X6.17 Finite quotients of Grigorchuk groups[0X
  
  In  this  section,  we  show  how  to  construct finite quotients of the two
  infinite  periodic groups introduced by Rostislav Grigorchuk in [Gri80] with
  the  help of [5XRCWA[0m. The first of these, nowadays known as "Grigorchuk group",
  is   investigated   in   an   example  given  on  the  [5XGAP[0m  website  --  see
  [7Xhttp://www.gap-system.org/Doc/Examples/grigorchuk.html[0m.   The  [5XRCWA[0m  package
  permits  a  simpler and more elegant construction of the finite quotients of
  this  group:  The  function  [10XTopElement[0m  given on the mentioned webpage gets
  unnecessary, and the function [10XSequenceElement[0m can be simplified as follows:
  
  [4X------------------------------------------------------------------[0X
    [4X[0X
    [4XSequenceElement := function ( r, level )[0X
    [4X[0X
    [4X  return Permutation(Product(Filtered([1..level-1],k->k mod 3 <> r),[0X
    [4X                             k->ClassTransposition(    2^(k-1)-1,2^(k+1),[0X
    [4X                                                   2^k+2^(k-1)-1,2^(k+1))),[0X
    [4X                     [0..2^level-1]);[0X
    [4Xend;[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  The actual constructors for the generators are modified as follows:
  
  [4X------------------------------------------------------------------[0X
    [4X[0X
    [4Xa := level -> Permutation(ClassTransposition(0,2,1,2),[0..2^level-1]);[0X
    [4Xb := level -> SequenceElement(0,level);[0X
    [4Xc := level -> SequenceElement(2,level);[0X
    [4Xd := level -> SequenceElement(1,level);[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  All  computations  given  on  the  webpage  can now be done just as with the
  "original"  construction  of  the  quotients of the Grigorchuk group. In the
  sequel,  we  construct  finite  quotients  of  the  second  group introduced
  in [Gri80]:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> FourCycle := RcwaMapping((4,5,6,7),[4..7]);[0X
    [4X<bijective rcwa mapping of Z with modulus 4, of order 4>[0X
    [4Xgap> GrigorchukGroup2Generator := function ( level )[0X
    [4X>      if level = 1 then return FourCycle; else[0X
    [4X>        return   Restriction(FourCycle, RcwaMapping([[4,1,1]]))[0X
    [4X>               * Restriction(FourCycle, RcwaMapping([[4,3,1]]))[0X
    [4X>               * Restriction(GrigorchukGroup2Generator(level-1),[0X
    [4X>                             RcwaMapping([[4,0,1]]));[0X
    [4X>      fi;[0X
    [4X>    end;;[0X
    [4Xgap> GrigorchukGroup2 := level -> Group(FourCycle,[0X
    [4X>                                       GrigorchukGroup2Generator(level));;[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  We  can do similar things as shown in the example on the [5XGAP[0m webpage for the
  "first" Grigorchuk group:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> G := List([1..4],lev->GrigorchukGroup2(lev)); # The first 4 quotients.[0X
    [4X[ <rcwa group over Z with 2 generators>, [0X
    [4X  <rcwa group over Z with 2 generators>, [0X
    [4X  <rcwa group over Z with 2 generators>, [0X
    [4X  <rcwa group over Z with 2 generators> ][0X
    [4Xgap> H := List([1..4],lev->Action(G[lev],[0..4^lev-1])); # Isom. perm.-gps.[0X
    [4X[ Group([ (1,2,3,4), (1,2,3,4) ]), [0X
    [4X  Group([ (1,2,3,4)(5,6,7,8)(9,10,11,12)(13,14,15,16), [0X
    [4X      (1,5,9,13)(2,6,10,14)(4,8,12,16) ]), [0X
    [4X  <permutation group with 2 generators>, [0X
    [4X  <permutation group with 2 generators> ][0X
    [4Xgap> List(H,Size);[0X
    [4X[ 4, 1024, 4294967296, 1329227995784915872903807060280344576 ][0X
    [4Xgap> List(last,n->Collected(Factors(n)));[0X
    [4X[ [ [ 2, 2 ] ], [ [ 2, 10 ] ], [ [ 2, 32 ] ], [ [ 2, 120 ] ] ][0X
    [4Xgap> List(H,NilpotencyClassOfGroup);      [0X
    [4X[ 1, 6, 14, 40 ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Issue  [10XUnwrapExample("GrigorchukQuotients");[0m  to assign the global variables
  defined in this example.
  
  
  [1X6.18 Forward orbits of a monoid with 2 generators[0X
  
  The  3n+1  Conjecture asserts that the forward orbit of any positive integer
  under  the  Collatz  mapping T contains 1. In contrast, it seems likely that
  "most" trajectories of the two mappings
  
                                         /
                                        | n/2          if n even,
            T_5+/-:  Z -> Z,   n  |->  <
                                        | (5n +/- 1)/2 if n odd
                                         \
  
  diverge.  However we can show by means of computation that the forward orbit
  of  any positive integer under the action of the monoid generated by the two
  mappings  T_5^-  and T_5^+  indeed  contains 1.  First  of all, we enter the
  generators:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> T5m := RcwaMapping([[1,0,2],[5,-1,2]]);;[0X
    [4Xgap> T5p := RcwaMapping([[1,0,2],[5, 1,2]]);;[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  We  look  for  a  number k such that for any residue class r(2^k) there is a
  product f  of k mappings T_5^pm whose restriction to r(2^k) is given by n ->
  (an+b)/c where c>a:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> k := 1;;[0X
    [4Xgap> repeat[0X
    [4X>      maps := List(Tuples([T5m,T5p],k),Product);[0X
    [4X>      decr := List(maps,DecreasingOn);[0X
    [4X>      decreasable := Union(decr);[0X
    [4X>      Print(k,": "); View(decreasable); Print("\n");[0X
    [4X>      k := k + 1;[0X
    [4X>    until decreasable = Integers;[0X
    [4X1: 0(2)[0X
    [4X2: 0(4)[0X
    [4X3: Z \ 1(8) U 7(8)[0X
    [4X4: 0(4) U 3(16) U 6(16) U 10(16) U 13(16)[0X
    [4X5: Z \ 7(32) U 25(32)[0X
    [4X6: <union of 48 residue classes (mod 64)>[0X
    [4X7: Integers[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Thus k=7 serves our purposes. To be sure that for any positive integer n our
  monoid  contains  a  mapping  f such that n^f<n, we still need to check this
  condition  for "small" n. Since in case c>a we have (an+b)/c >= n if only if
  n  <=  b/(c-a),  we only need to check those n which are not larger than the
  largest   coefficient   b_r(m)   occuring  in  any  of  the  products  under
  consideration:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> maxb := Maximum(List(maps,f->Maximum(List(Coefficients(f),t->t[2]))));[0X
    [4X25999[0X
    [4Xgap> small := Filtered([1..maxb],n->ForAll(maps,f->n^f>=n));[0X
    [4X[ 1, 7, 9, 11 ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  This means that except of 1, only for n in {7,9,11} there is no product of 7
  mappings  T_5^pm  which  maps n to a smaller integer. We check that also the
  forward  orbits  of these three integers contain 1 by successively computing
  preimages of 1:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> S := [1];; k := 0;;[0X
    [4Xgap> repeat[0X
    [4X>      S := Union(S,PreImage(T5m,S),PreImage(T5p,S));[0X
    [4X>      k := k+1;[0X
    [4X>    until IsSubset(S,small);[0X
    [4Xgap> k;[0X
    [4X17[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Issue   [10XUnwrapExample("CollatzMapping");[0m  to  assign  the  global  variables
  defined in this example.
  
  
  [1X6.19 The free group of rank 2 and the modular group PSL(2,ℤ)[0X
  
  The  free  group  of rank 2 embeds into RCWA(ℤ) -- in fact it embeds even in
  the  subgroup  which  is  generated by all class transpositions. An explicit
  embedding  can  be  constructed  by  transferring  the  construction  of the
  so-called  "Schottky groups" (cf. [dlH00], page 27) from PSL(2,ℂ) to RCWA(ℤ)
  (we use the notation from the cited book):
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> D := AllResidueClassesModulo(4);[0X
    [4X[ 0(4), 1(4), 2(4), 3(4) ][0X
    [4Xgap> gamma1 := RepresentativeAction(RCWA(Integers),[0X
    [4X>                                   Difference(Integers,D[1]),D[2]);;[0X
    [4Xgap> gamma2 := RepresentativeAction(RCWA(Integers),[0X
    [4X>                                   Difference(Integers,D[3]),D[4]);;[0X
    [4Xgap> F2 := Group(gamma1,gamma2);[0X
    [4X<rcwa group over Z with 2 generators>[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  We can do some checks:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> X1 := Union(D{[1,2]});; X2 := Union(D{[3,4]});;[0X
    [4Xgap>     IsSubset(X1,X2^gamma1) and IsSubset(X1,X2^(gamma1^-1))[0X
    [4X>    and IsSubset(X2,X1^gamma2) and IsSubset(X2,X1^(gamma2^-1));[0X
    [4Xtrue[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  The generators are products of 3 class transpositions, each:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> Factorization(gamma1);[0X
    [4X[ ClassTransposition(0,2,1,2), ClassTransposition(3,4,5,8),[0X
    [4X  ClassTransposition(0,2,1,8) ][0X
    [4Xgap> Factorization(gamma2);[0X
    [4X[ ClassTransposition(0,2,1,2), ClassTransposition(1,4,7,8),[0X
    [4X  ClassTransposition(0,2,3,8) ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  The above construction is used by [2XIsomorphismRcwaGroup[0m ([14X3.1-4[0m) to embed free
  groups of any rank >= 2.
  
  We  give another only slightly different representation of the free group of
  rank 2.  We  verify  that  it  really  is  one  by  applying  the  so-called
  [13XTable-Tennis  Lemma[0m (see e.g. [dlH00], Section II.B.) to the infinite cyclic
  groups generated by the two generators and to the same two sets [10XX1[0m and [10XX2[0m as
  above:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> r1 := ClassTransposition(0,2,1,2)*ClassTransposition(0,2,1,4);;[0X
    [4Xgap> r2 := ClassTransposition(0,2,1,2)*ClassTransposition(0,2,3,4);;[0X
    [4Xgap> F2 := Group(r1^2,r2^2);;[0X
    [4Xgap> List(GeneratorsOfGroup(F2),IsTame);[0X
    [4X[ false, false ][0X
    [4Xgap>     IsSubset(X1,X2^F2.1) and IsSubset(X1,X2^(F2.1^-1))[0X
    [4X>    and IsSubset(X2,X1^F2.2) and IsSubset(X2,X1^(F2.2^-1));[0X
    [4Xtrue[0X
    [4Xgap> [Sources(r1),Sinks(r1),Loops(r1)]; # compare with X1[0X
    [4X[ [ 0(4) ], [ 1(4) ], [ 0(4), 1(4) ] ][0X
    [4Xgap> [Sources(r2),Sinks(r2),Loops(r2)]; # compare with X2[0X
    [4X[ [ 2(4) ], [ 3(4) ], [ 2(4), 3(4) ] ][0X
    [4Xgap>    IsSubset(X1,Union(Sinks(r1))) and IsSubset(X1,Union(Sinks(r1^-1)))[0X
    [4X>   and IsSubset(X2,Union(Sinks(r2))) and IsSubset(X2,Union(Sinks(r2^-1)));[0X
    [4Xtrue[0X
    [4Xgap> IsSubset(Union(Sinks(r1)),X2^F2.1) and[0X
    [4X>    IsSubset(Union(Sinks(r1^-1)),X2^(F2.1^-1));[0X
    [4Xtrue[0X
    [4Xgap> IsSubset(Union(Sinks(r2)),X1^F2.2) and[0X
    [4X>    IsSubset(Union(Sinks(r2^-1)),X1^(F2.2^-1));[0X
    [4Xtrue[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Drawing  the  transition  graphs  of  [10Xr1[0m  and  [10Xr2[0m  for modulus 4 may help to
  understand what is actually done in this calculation. It is easy to see that
  the group generated by [10Xr1[0m and [10Xr2[0m is [13Xnot[0m free:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> Order(r1/r2);[0X
    [4X3[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  The  modular group PSL(2,ℤ) embeds into CT(ℤ) as well. We give an embedding,
  and check that it really is one by applying the Table Tennis Lemma as above:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> PSL2Z := [0X
    [4X>      Group(ClassTransposition(0,3,1,3) * ClassTransposition(0,3,2,3),[0X
    [4X>            ClassTransposition(1,3,0,6) * ClassTransposition(2,3,3,6));;[0X
    [4Xgap> List(GeneratorsOfGroup(PSL2Z),Order);[0X
    [4X[ 3, 2 ][0X
    [4Xgap> X1 := Difference(Integers,ResidueClass(0,3));[0X
    [4XZ \ 0(3)[0X
    [4Xgap> X2 := ResidueClass(0,3);[0X
    [4X0(3)[0X
    [4Xgap> IsSubset(X1,X2^PSL2Z.1) and IsSubset(X1,X2^(PSL2Z.1^2));[0X
    [4Xtrue[0X
    [4Xgap> IsSubset(X2,X1^PSL2Z.2);[0X
    [4Xtrue[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  A  slightly  different  representation  of PSL(2,ℤ) can be obtained by using
  [5XRCWA[0m's  general  method for [10XIsomorphismRcwaGroup[0m for free products of finite
  groups:
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> G := Image(IsomorphismRcwaGroup(FreeProduct(CyclicGroup(3),[0X
    [4X>                                                CyclicGroup(2))));[0X
    [4X<wild rcwa group over Z with 2 generators>[0X
    [4Xgap> List(GeneratorsOfGroup(G),Factorization);[0X
    [4X[ [ ClassTransposition(0,4,2,4), ClassTransposition(1,2,0,4) ],[0X
    [4X  [ ClassTransposition(0,2,1,2) ] ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  Issue  [10XUnwrapExample("F2_PSL2Z");[0m  to assign the global variables defined in
  this example.
  
