GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
1[1X2 [33X[0;0YResidue-Class-Wise Affine Mappings[133X[101X23[33X[0;0YThis chapter contains the basic definitions, and it describes how to enter4residue-class-wise affine mappings and how to compute with them.[133X56[33X[0;0YHow to compute with residue-class-wise affine groups is described in detail7in the next chapter. The reader is encouraged to look there already after8having read the first few pages of this chapter, and to look up definitions9as he needs to.[133X101112[1X2.1 [33X[0;0YBasic definitions[133X[101X1314[33X[0;0YResidue-class-wise affine groups, or [13Xrcwa[113X groups for short, are permutation15groups whose elements are bijective residue-class-wise affine mappings.[133X1617[33X[0;0YA mapping [22Xf: ℤ → ℤ[122X is called [13Xresidue-class-wise affine[113X, or for short an [13Xrcwa[113X18mapping, if there is a positive integer [22Xm[122X such that the restrictions of [22Xf[122X to19the residue classes [22Xr(m) ∈ ℤ/mℤ[122X are all affine, i.e. given by[133X2021a_r(m) * n + b_r(m)22f|_r(m): r(m) -> Z, n |-> -------------------23c_r(m)2425[33X[0;0Yfor certain coefficients [22Xa_r(m), b_r(m), c_r(m) ∈ ℤ[122X depending on [22Xr(m)[122X. The26smallest possible [22Xm[122X is called the [13Xmodulus[113X of [22Xf[122X. It is understood that all27fractions are reduced, i.e. that [22Xgcd( a_r(m), b_r(m), c_r(m) ) = 1[122X, and that28[22Xc_r(m) > 0[122X. The lcm of the coefficients [22Xa_r(m)[122X is called the [13Xmultiplier[113X29of [22Xf[122X, and the lcm of the coefficients [22Xc_r(m)[122X is called the [13Xdivisor[113X of [22Xf[122X.[133X3031[33X[0;0YIt is easy to see that the residue-class-wise affine mappings of ℤ form a32monoid under composition, and that the residue-class-wise affine33permutations of ℤ form a countable subgroup of Sym(ℤ). We denote the former34by Rcwa(ℤ), and the latter by RCWA(ℤ).[133X3536[33X[0;0YAn rcwa mapping is called [13Xtame[113X if the set of moduli of its powers is37bounded, or equivalently if it permutes a partition of ℤ into finitely many38residue classes on all of which it is affine. An rcwa group is called [13Xtame[113X39if there is a common such partition for all of its elements, or equivalently40if the set of moduli of its elements is bounded. Rcwa mappings and -groups41which are not tame are called [13Xwild[113X. Tame rcwa mappings and -groups are42something which one could call the [21Xtrivial cases[121X or [21Xbasic building blocks[121X,43while wild rcwa groups are the objects of primary interest.[133X4445[33X[0;0YThe definitions of residue-class-wise affine mappings and -groups can be46generalized in the obvious way to suitable rings other than ℤ. In fact, this47package provides also some support for residue-class-wise affine groups over48[22Xℤ^2[122X, over semilocalizations of ℤ and over univariate polynomial rings over49finite fields. The ring [22Xℤ^2[122X has been chosen as an example of a suitable ring50which is not a principal ideal domain, the semilocalizations of ℤ have been51chosen as examples of rings with only finitely many prime elements, and the52univariate polynomial rings over finite fields have been chosen as examples53of rings with nonzero characteristic.[133X545556[1X2.2 [33X[0;0YEntering residue-class-wise affine mappings[133X[101X5758[33X[0;0YEntering an rcwa mapping of ℤ requires giving the modulus [22Xm[122X and the59coefficients [22Xa_r(m)[122X, [22Xb_r(m)[122X and [22Xc_r(m)[122X for [22Xr(m)[122X running over the residue60classes (mod [22Xm[122X).[133X6162[33X[0;0YThis can be done easiest by [10XRcwaMapping( [3Xcoeffs[103X[10X )[110X, where [3Xcoeffs[103X is a list of63[22Xm[122X coefficient triples [10Xcoeffs[[110X[22Xr+1[122X[10X] = [[110X[22Xa_r(m)[122X, [22Xb_r(m)[122X, [22Xc_r(m)[122X[10X][110X, with [22Xr[122X running64from 0 to [22Xm-1[122X.[133X6566[33X[0;0YIf some coefficient [22Xc_r(m)[122X is zero or if images of some integers under the67mapping to be defined would not be integers, an error message is printed and68a break loop is entered. For example, the coefficient triple [10X[1,4,3][110X is not69allowed at the first position. The reason for this is that not all integers70congruent to [22X1 ⋅ 0 + 4 = 4[122X mod [22Xm[122X are divisible by 3.[133X7172[33X[0;0YFor the general constructor for rcwa mappings, see [2XRcwaMapping[102X ([14X2.2-5[114X).[133X7374[4X[32X Example [32X[104X75[4X[28X[128X[104X76[4X[25Xgap>[125X [27XT := RcwaMapping([[1,0,2],[3,1,2]]); # The Collatz mapping.[127X[104X77[4X[28X<rcwa mapping of Z with modulus 2>[128X[104X78[4X[25Xgap>[125X [27X[ IsSurjective(T), IsInjective(T) ];[127X[104X79[4X[28X[ true, false ][128X[104X80[4X[25Xgap>[125X [27XDisplay(T);[127X[104X81[4X[28X[128X[104X82[4X[28XSurjective rcwa mapping of Z with modulus 2[128X[104X83[4X[28X[128X[104X84[4X[28X /[128X[104X85[4X[28X | n/2 if n in 0(2)[128X[104X86[4X[28X n |-> < (3n+1)/2 if n in 1(2)[128X[104X87[4X[28X |[128X[104X88[4X[28X \[128X[104X89[4X[28X[128X[104X90[4X[25Xgap>[125X [27Xa := RcwaMapping([[2,0,3],[4,-1,3],[4,1,3]]);[127X[104X91[4X[28X<rcwa mapping of Z with modulus 3>[128X[104X92[4X[25Xgap>[125X [27XIsBijective(a);[127X[104X93[4X[28Xtrue[128X[104X94[4X[25Xgap>[125X [27XDisplay(a); # This is Collatz' permutation:[127X[104X95[4X[28X[128X[104X96[4X[28XRcwa permutation of Z with modulus 3[128X[104X97[4X[28X[128X[104X98[4X[28X /[128X[104X99[4X[28X | 2n/3 if n in 0(3)[128X[104X100[4X[28X n |-> < (4n-1)/3 if n in 1(3)[128X[104X101[4X[28X | (4n+1)/3 if n in 2(3)[128X[104X102[4X[28X \[128X[104X103[4X[28X[128X[104X104[4X[25Xgap>[125X [27XSupport(a);[127X[104X105[4X[28XZ \ [ -1, 0, 1 ][128X[104X106[4X[25Xgap>[125X [27XCycle(a,44);[127X[104X107[4X[28X[ 44, 59, 79, 105, 70, 93, 62, 83, 111, 74, 99, 66 ][128X[104X108[4X[28X[128X[104X109[4X[32X[104X110111[33X[0;0YThere is computational evidence for the conjecture that any112residue-class-wise affine permutation of ℤ can be factored into members of113the following three series of permutations of particularly simple structure114(cf. [2XFactorizationIntoCSCRCT[102X ([14X2.5-1[114X)):[133X115116[1X2.2-1 ClassShift[101X117118[29X[2XClassShift[102X( [3Xr[103X, [3Xm[103X ) [32X function119[29X[2XClassShift[102X( [3Xcl[103X ) [32X function120[6XReturns:[106X [33X[0;10Ythe class shift [22Xν_r(m)[122X.[133X121122[33X[0;0YThe [13Xclass shift[113X [22Xν_r(m)[122X is the rcwa mapping of ℤ which maps [22Xn ∈ r(m)[122X to [22Xn + m[122X123and which fixes [22Xℤ ∖ r(m)[122X pointwise.[133X124125[33X[0;0YIn the one-argument form, the argument [3Xcl[103X stands for the residue class [22Xr(m)[122X.126Enclosing the argument list in list brackets is permitted.[133X127128[4X[32X Example [32X[104X129[4X[28X[128X[104X130[4X[25Xgap>[125X [27XDisplay(ClassShift(5,12));[127X[104X131[4X[28X[128X[104X132[4X[28XTame rcwa permutation of Z with modulus 12, of order infinity[128X[104X133[4X[28X[128X[104X134[4X[28X /[128X[104X135[4X[28X | n+12 if n in 5(12)[128X[104X136[4X[28X n |-> < n if n in Z \ 5(12)[128X[104X137[4X[28X |[128X[104X138[4X[28X \[128X[104X139[4X[28X[128X[104X140[4X[32X[104X141142[1X2.2-2 ClassReflection[101X143144[29X[2XClassReflection[102X( [3Xr[103X, [3Xm[103X ) [32X function145[29X[2XClassReflection[102X( [3Xcl[103X ) [32X function146[6XReturns:[106X [33X[0;10Ythe class reflection [22Xς_r(m)[122X.[133X147148[33X[0;0YThe [13Xclass reflection[113X [22Xς_r(m)[122X is the rcwa mapping of ℤ which maps [22Xn ∈ r(m)[122X to149[22X-n + 2r[122X and which fixes [22Xℤ ∖ r(m)[122X pointwise, where it is understood that [22X0 ≤150r < m[122X.[133X151152[33X[0;0YIn the one-argument form, the argument [3Xcl[103X stands for the residue class [22Xr(m)[122X.153Enclosing the argument list in list brackets is permitted.[133X154155[4X[32X Example [32X[104X156[4X[28X[128X[104X157[4X[25Xgap>[125X [27XDisplay(ClassReflection(5,9));[127X[104X158[4X[28X[128X[104X159[4X[28XRcwa permutation of Z with modulus 9, of order 2[128X[104X160[4X[28X[128X[104X161[4X[28X /[128X[104X162[4X[28X | -n+10 if n in 5(9)[128X[104X163[4X[28X n |-> < n if n in Z \ 5(9)[128X[104X164[4X[28X |[128X[104X165[4X[28X \[128X[104X166[4X[28X[128X[104X167[4X[32X[104X168169[1X2.2-3 ClassTransposition[101X170171[29X[2XClassTransposition[102X( [3Xr1[103X, [3Xm1[103X, [3Xr2[103X, [3Xm2[103X ) [32X function172[29X[2XClassTransposition[102X( [3Xcl1[103X, [3Xcl2[103X ) [32X function173[6XReturns:[106X [33X[0;10Ythe class transposition [22Xτ_r_1(m_1),r_2(m_2)[122X.[133X174175[33X[0;0YGiven two disjoint residue classes [22Xr_1(m_1)[122X and [22Xr_2(m_2)[122X of the integers,176the [13Xclass transposition[113X [22Xτ_r_1(m_1),r_2(m_2)[122X [22X∈[122X RCWA(ℤ) is defined as the177involution which interchanges [22Xr_1+km_1[122X and [22Xr_2+km_2[122X for any integer [22Xk[122X and178which fixes all other points. It is understood that [22Xm_1[122X and [22Xm_2[122X are179positive, that [22X0 ≤ r_1 < m_1[122X and that [22X0 ≤ r_2 < m_2[122X. For a [13Xgeneralized class180transposition[113X, the latter assumptions are not made.[133X181182[33X[0;0YThe class transposition [22Xτ_r_1(m_1),r_2(m_2)[122X interchanges the residue classes183[22Xr_1(m_1)[122X and [22Xr_2(m_2)[122X and fixes the complement of their union pointwise.[133X184185[33X[0;0YIn the four-argument form, the arguments [3Xr1[103X, [3Xm1[103X, [3Xr2[103X and [3Xm2[103X stand for [22Xr_1[122X,186[22Xm_1[122X, [22Xr_2[122X and [22Xm_2[122X, respectively. In the two-argument form, the arguments [3Xcl1[103X187and [3Xcl2[103X stand for the residue classes [22Xr_1(m_1)[122X and [22Xr_2(m_2)[122X, respectively.188Enclosing the argument list in list brackets is permitted. The residue189classes [22Xr_1(m_1)[122X and [22Xr_2(m_2)[122X are stored as an attribute [10XTransposedClasses[110X.[133X190191[33X[0;0YA list of all class transpositions interchanging residue classes with moduli192less than or equal to a given bound [3Xm[103X can be obtained by193[10XList(ClassPairs([[3XP[103X[10X],[3Xm[103X[10X),ClassTransposition)[110X, where the function [10XClassPairs[110X194returns a list of all 4-tuples [22X(r_1,m_1,r_2,m_2)[122X of integers corresponding195to the unordered pairs of disjoint residue classes [22Xr_1(m_1)[122X and [22Xr_2(m_2)[122X196with [22Xm_1[122X and [22Xm_2[122X less than or equal to the specified bound. If a list of197primes is given as optional argument [3XP[103X, then the returned list contains only198those 4-tuples where all prime factors of [22Xm_1[122X and [22Xm_2[122X lie in [3XP[103X. If the199option [10Xdivisors[110X is set, the returned list contains only the 4-tuples where200[22Xm_1[122X and [22Xm_2[122X divide [3Xm[103X.[133X201202[33X[0;0YThe function [10XNrClassPairs([3Xm[103X[10X)[110X returns the length of the list [10XClassPairs([3Xm[103X[10X)[110X,203where the result is computed much faster and without actually generating the204list of tuples. Given a class transposition [3Xct[103X, the corresponding 4-tuple205can be obtained by [10XExtRepOfObj([3Xct[103X[10X)[110X[133X206207[33X[0;0YA class transposition can be written as a product of any given number [22Xk[122X of208class transpositions. Such a decomposition can be obtained by209[10XSplittedClassTransposition([3Xct[103X[10X,[3Xk[103X[10X)[110X.[133X210211[4X[32X Example [32X[104X212[4X[28X[128X[104X213[4X[25Xgap>[125X [27XDisplay(ClassTransposition(1,2,8,10):CycleNotation:=false);[127X[104X214[4X[28X[128X[104X215[4X[28XRcwa permutation of Z with modulus 10, of order 2[128X[104X216[4X[28X[128X[104X217[4X[28X /[128X[104X218[4X[28X | 5n+3 if n in 1(2)[128X[104X219[4X[28X n |-> < (n-3)/5 if n in 8(10)[128X[104X220[4X[28X | n if n in 0(2) \ 8(10)[128X[104X221[4X[28X \[128X[104X222[4X[28X[128X[104X223[4X[25Xgap>[125X [27XList(ClassPairs(4),ClassTransposition);[127X[104X224[4X[28X[ ( 0(2), 1(2) ), ( 0(2), 1(4) ), ( 0(2), 3(4) ), ( 0(3), 1(3) ), [128X[104X225[4X[28X ( 0(3), 2(3) ), ( 0(4), 1(4) ), ( 0(4), 2(4) ), ( 0(4), 3(4) ), [128X[104X226[4X[28X ( 1(2), 0(4) ), ( 1(2), 2(4) ), ( 1(3), 2(3) ), ( 1(4), 2(4) ), [128X[104X227[4X[28X ( 1(4), 3(4) ), ( 2(4), 3(4) ) ][128X[104X228[4X[25Xgap>[125X [27XNrClassPairs(100);[127X[104X229[4X[28X3528138[128X[104X230[4X[25Xgap>[125X [27XSplittedClassTransposition(ClassTransposition(0,2,1,4),3);[127X[104X231[4X[28X[ ( 0(6), 1(12) ), ( 2(6), 5(12) ), ( 4(6), 9(12) ) ][128X[104X232[4X[32X[104X233234[33X[0;0YThe set of all class transpositions of the ring of integers generates the235simple group CT(ℤ) mentioned in Chapter [14X1[114X. This group has a representation236as a [5XGAP[105X object -- see [2XCT[102X ([14X3.1-9[114X). The set of all generalized class237transpositions of ℤ generates a simple group as well, cf. [Koh10].[133X238239[33X[0;0YClass shifts, class reflections and class transpositions of rings [22XR[122X other240than ℤ are defined in an entirely analogous way -- all one needs to do is to241replace ℤ by [22XR[122X and to read [22X<[122X and [22X≤[122X in the sense of the ordering used by [5XGAP[105X.242They can also be entered basically as described above -- just prepend the243desired ring [22XR[122X to the argument list. Often also a sensible [21Xdefault ring[121X ([22X→[122X244[10XDefaultRing[110X in the [5XGAP[105X Reference Manual) is chosen if that optional first245argument is omitted.[133X246247[33X[0;0YOn rings which have more than two units, there is another basic series of248rcwa permutations which generalizes class reflections:[133X249250[1X2.2-4 ClassRotation[101X251252[29X[2XClassRotation[102X( [3Xr[103X, [3Xm[103X, [3Xu[103X ) [32X function253[29X[2XClassRotation[102X( [3Xcl[103X, [3Xu[103X ) [32X function254[6XReturns:[106X [33X[0;10Ythe class rotation [22Xρ_r(m),u[122X.[133X255256[33X[0;0YGiven a residue class [22Xr(m)[122X and a unit [22Xu[122X of a suitable ring [22XR[122X, the [13Xclass257rotation[113X [22Xρ_r(m),u[122X is the rcwa mapping which maps [22Xn ∈ r(m)[122X to [22Xun + (1-u)r[122X and258which fixes [22XR ∖ r(m)[122X pointwise. Class rotations generalize class259reflections, as we have [22Xρ_r(m),-1 = ς_r(m)[122X.[133X260261[33X[0;0YIn the two-argument form, the argument [3Xcl[103X stands for the residue class [22Xr(m)[122X.262Enclosing the argument list in list brackets is permitted. The argument [3Xu[103X is263stored as an attribute [10XRotationFactor[110X.[133X264265[4X[32X Example [32X[104X266[4X[28X[128X[104X267[4X[25Xgap>[125X [27XDisplay(ClassRotation(ResidueClass(Z_pi(2),2,1),1/3));[127X[104X268[4X[28X[128X[104X269[4X[28XTame rcwa permutation of Z_( 2 ) with modulus 2, of order infinity[128X[104X270[4X[28X[128X[104X271[4X[28X /[128X[104X272[4X[28X | 1/3 n + 2/3 if n in 1(2)[128X[104X273[4X[28X n |-> < n if n in 0(2)[128X[104X274[4X[28X |[128X[104X275[4X[28X \[128X[104X276[4X[28X[128X[104X277[4X[25Xgap>[125X [27Xx := Indeterminate(GF(8),1);; SetName(x,"x");[127X[104X278[4X[25Xgap>[125X [27XR := PolynomialRing(GF(8),1);;[127X[104X279[4X[25Xgap>[125X [27Xcr := ClassRotation(1,x,Z(8)*One(R)); Support(cr);[127X[104X280[4X[28XClassRotation( 1(x), Z(2^3) )[128X[104X281[4X[28X1(x) \ [ 1 ][128X[104X282[4X[25Xgap>[125X [27XDisplay(cr);[127X[104X283[4X[28X[128X[104X284[4X[28XRcwa permutation of GF(2^3)[x] with modulus x, of order 7[128X[104X285[4X[28X[128X[104X286[4X[28X /[128X[104X287[4X[28X | Z(2^3)*P + Z(2^3)^3 if P in 1(x)[128X[104X288[4X[28X P |-> < P otherwise[128X[104X289[4X[28X |[128X[104X290[4X[28X \[128X[104X291[4X[28X[128X[104X292[4X[32X[104X293294[33X[0;0Y[10XIsClassShift[110X, [10XIsClassReflection[110X, [10XIsClassRotation[110X, [10XIsClassTransposition[110X and295[10XIsGeneralizedClassTransposition[110X are properties which indicate whether a296given rcwa mapping belongs to the corresponding series.[133X297298[33X[0;0YIn the sequel we describe the general-purpose constructor for rcwa mappings.299The constructor may look a bit technical on a first glance, but knowing all300possible ways of entering an rcwa mapping is by no means necessary for301understanding this manual or for using this package.[133X302303304[1X2.2-5 [33X[0;0YRcwaMapping (the general constructor)[133X[101X305306[29X[2XRcwaMapping[102X( [3XR[103X, [3Xm[103X, [3Xcoeffs[103X ) [32X method307[29X[2XRcwaMapping[102X( [3XR[103X, [3Xcoeffs[103X ) [32X method308[29X[2XRcwaMapping[102X( [3Xcoeffs[103X ) [32X method309[29X[2XRcwaMapping[102X( [3Xperm[103X, [3Xrange[103X ) [32X method310[29X[2XRcwaMapping[102X( [3Xm[103X, [3Xvalues[103X ) [32X method311[29X[2XRcwaMapping[102X( [3Xpi[103X, [3Xcoeffs[103X ) [32X method312[29X[2XRcwaMapping[102X( [3Xq[103X, [3Xm[103X, [3Xcoeffs[103X ) [32X method313[29X[2XRcwaMapping[102X( [3XP1[103X, [3XP2[103X ) [32X method314[29X[2XRcwaMapping[102X( [3Xcycles[103X ) [32X method315[29X[2XRcwaMapping[102X( [3Xexpression[103X ) [32X method316[6XReturns:[106X [33X[0;10Yan rcwa mapping.[133X317318[33X[0;0YIn all cases the argument [3XR[103X is the underlying ring, [3Xm[103X is the modulus and319[3Xcoeffs[103X is the coefficient list. A [13Xcoefficient list[113X for an rcwa mapping with320modulus [22Xm[122X consists of [22X|R/mR|[122X coefficient triples [10X[[110X[22Xa_r(m)[122X, [22Xb_r(m)[122X, [22Xc_r(m)[122X[10X][110X.321Their ordering is determined by the ordering of the representatives of the322residue classes (mod [22Xm[122X) in the sorted list returned by [10XAllResidues([3XR[103X[10X, [3Xm[103X[10X)[110X. In323case [22XR = ℤ[122X this means that the coefficient triple for the residue class [22X0(m)[122X324comes first and is followed by the one for [22X1(m)[122X, the one for [22X2(m)[122X and so on.[133X325326[33X[0;0YIf one or several of the arguments [3XR[103X, [3Xm[103X and [3Xcoeffs[103X are omitted or replaced327by other arguments, the former are either derived from the latter or default328values are chosen. The meaning of the other arguments is defined in the329detailed description of the particular methods given in the sequel. The330above methods return the rcwa mapping[133X331332[8X(a)[108X333[33X[0;6Yof [3XR[103X with modulus [3Xm[103X and coefficients [3Xcoeffs[103X,[133X334335[8X(b)[108X336[33X[0;6Yof [3XR[103X = ℤ or [3XR[103X = [22Xℤ_(π)[122X with modulus [10XLength([3Xcoeffs[103X[10X)[110X and coefficients337[3Xcoeffs[103X,[133X338339[8X(c)[108X340[33X[0;6Yof [3XR[103X = ℤ with modulus [10XLength([3Xcoeffs[103X[10X)[110X and coefficients [3Xcoeffs[103X,[133X341342[8X(d)[108X343[33X[0;6Yof [3XR[103X = ℤ, permuting any set [10X[3Xrange[103X[10X+k*Length([3Xrange[103X[10X)[110X like [3Xperm[103X permutes344[3Xrange[103X,[133X345346[8X(e)[108X347[33X[0;6Yof [3XR[103X = ℤ with modulus [3Xm[103X and values given by a list [3Xval[103X of 2 pairs348[10X[[110Xpreimage[10X, [110Ximage[10X][110X per residue class (mod [3Xm[103X),[133X349350[8X(f)[108X351[33X[0;6Yof [3XR[103X = [22Xℤ_(π)[122X with modulus [10XLength([3Xcoeffs[103X[10X)[110X and coefficients [3Xcoeffs[103X (the352set of primes [22Xπ[122X which denotes the underlying ring is passed as353argument [3Xpi[103X),[133X354355[8X(g)[108X356[33X[0;6Yof [3XR[103X = GF([3Xq[103X)[[3Xx[103X] with modulus [3Xm[103X and coefficients [3Xcoeffs[103X,[133X357358[8X(h)[108X359[33X[0;6Yan rcwa permutation which induces a bijection between the partitions360[3XP1[103X and [3XP2[103X of [3XR[103X into residue classes and which is affine on the361elements of [3XP1[103X,[133X362363[8X(i)[108X364[33X[0;6Yan rcwa permutation with [21Xresidue class cycles[121X given by a list [3Xcycles[103X365of lists of pairwise disjoint residue classes, each of which it366permutes cyclically, or[133X367368[8X(j)[108X369[33X[0;6Ythe rcwa permutation of ℤ given by the arithmetical expression370[3Xexpression[103X -- a string consisting of class transpositions (e.g.371[10X"(0(2),1(4))"[110X) or cycles permuting residue classes (e.g.372[10X"(0(2),1(8),3(4),5(8))"[110X), class shifts (e.g. [10X"cs(4(6))"[110X, class373reflections (e.g. [10X"cr(3(4))"[110X), arithmetical operators ([10X"*"[110X, [10X"/"[110X and374[10X"^"[110X) and brackets ([10X"("[110X, [10X")"[110X),[133X375376[33X[0;0Yrespectively. The methods for the operation [10XRcwaMapping[110X perform a number of377argument checks, which can be skipped by using [10XRcwaMappingNC[110X instead.[133X378379[4X[32X Example [32X[104X380[4X[28X[128X[104X381[4X[25Xgap>[125X [27XR := PolynomialRing(GF(2),1);; x := X(GF(2),1);; SetName(x,"x");[127X[104X382[4X[25Xgap>[125X [27XRcwaMapping(R,x+1,[[1,0,x+One(R)],[x+One(R),0,1]]*One(R)); # (a)[127X[104X383[4X[28X<rcwa mapping of GF(2)[x] with modulus x+1>[128X[104X384[4X[25Xgap>[125X [27XRcwaMapping(Z_pi(2),[[1/3,0,1]]); # (b)[127X[104X385[4X[28XRcwa mapping of Z_( 2 ): n -> 1/3 n[128X[104X386[4X[25Xgap>[125X [27Xa := RcwaMapping([[2,0,3],[4,-1,3],[4,1,3]]); # (c)[127X[104X387[4X[28X<rcwa mapping of Z with modulus 3>[128X[104X388[4X[25Xgap>[125X [27XRcwaMapping((1,2,3),[1..4]); # (d)[127X[104X389[4X[28X( 1(4), 2(4), 3(4) )[128X[104X390[4X[25Xgap>[125X [27XT = RcwaMapping(2,[[1,2],[2,1],[3,5],[4,2]]); # (e)[127X[104X391[4X[28Xtrue[128X[104X392[4X[25Xgap>[125X [27XRcwaMapping([2],[[1/3,0,1]]); # (f)[127X[104X393[4X[28XRcwa mapping of Z_( 2 ): n -> 1/3 n[128X[104X394[4X[25Xgap>[125X [27XRcwaMapping(2,x+1,[[1,0,x+One(R)],[x+One(R),0,1]]*One(R)); # (g)[127X[104X395[4X[28X<rcwa mapping of GF(2)[x] with modulus x+1>[128X[104X396[4X[25Xgap>[125X [27Xa = RcwaMapping(List([[0,3],[1,3],[2,3]],ResidueClass),[127X[104X397[4X[25X>[125X [27X List([[0,2],[1,4],[3,4]],ResidueClass)); # (h)[127X[104X398[4X[28Xtrue[128X[104X399[4X[25Xgap>[125X [27XRcwaMapping([List([[0,2],[1,4],[3,8],[7,16]],ResidueClass)]); # (i)[127X[104X400[4X[28X( 0(2), 1(4), 3(8), 7(16) )[128X[104X401[4X[25Xgap>[125X [27XCycle(last,ResidueClass(0,2));[127X[104X402[4X[28X[ 0(2), 1(4), 3(8), 7(16) ][128X[104X403[4X[25Xgap>[125X [27Xg := RcwaMapping("((0(4),1(6))*cr(0(6)))^2/cs(2(8))"); # (j)[127X[104X404[4X[28X<rcwa permutation of Z with modulus 72>[128X[104X405[4X[25Xgap>[125X [27Xg = (ClassTransposition(0,4,1,6) * ClassReflection(0,6))^2/[127X[104X406[4X[25X>[125X [27X ClassShift(2,8);[127X[104X407[4X[28Xtrue[128X[104X408[4X[28X[128X[104X409[4X[32X[104X410411[33X[0;0YRcwa mappings of ℤ can be [21Xtranslated[121X to rcwa mappings of some412semilocalization [22Xℤ_(π)[122X of ℤ:[133X413414[1X2.2-6 LocalizedRcwaMapping[101X415416[29X[2XLocalizedRcwaMapping[102X( [3Xf[103X, [3Xp[103X ) [32X function417[29X[2XSemilocalizedRcwaMapping[102X( [3Xf[103X, [3Xpi[103X ) [32X function418[6XReturns:[106X [33X[0;10Ythe rcwa mapping of [22Xℤ_(p)[122X respectively [22Xℤ_(π)[122X with the same419coefficients as the rcwa mapping [3Xf[103X of ℤ.[133X420421[33X[0;0YThe argument [3Xp[103X or [3Xpi[103X must be a prime or a set of primes, respectively. The422argument [3Xf[103X must be an rcwa mapping of ℤ whose modulus is a power of [3Xp[103X, or423whose modulus has only prime divisors which lie in [3Xpi[103X, respectively.[133X424425[4X[32X Example [32X[104X426[4X[28X[128X[104X427[4X[25Xgap>[125X [27XT := RcwaMapping([[1,0,2],[3,1,2]]);; # The Collatz mapping.[127X[104X428[4X[25Xgap>[125X [27XCycle(LocalizedRcwaMapping(T,2),131/13);[127X[104X429[4X[28X[ 131/13, 203/13, 311/13, 473/13, 716/13, 358/13, 179/13, 275/13, [128X[104X430[4X[28X 419/13, 635/13, 959/13, 1445/13, 2174/13, 1087/13, 1637/13, 2462/13, [128X[104X431[4X[28X 1231/13, 1853/13, 2786/13, 1393/13, 2096/13, 1048/13, 524/13, 262/13 ][128X[104X432[4X[28X[128X[104X433[4X[32X[104X434435[33X[0;0YRcwa mappings can be [10XView[110Xed, [10XDisplay[110Xed, [10XPrint[110Xed and written to a [10XString[110X. The436output of the [10XView[110X method is kept reasonably short. In most cases it does437not describe an rcwa mapping completely. In these cases the output is438enclosed in brackets. There are options [10XCycleNotation[110X, [10XAsClassMapping[110X,439[10XPrintNotation[110X and [10XAbridgedNotation[110X to take influence on how certain rcwa440mappings are shown. These options can either be not set, set to [10Xtrue[110X or set441to [10Xfalse[110X. If the option [10XCycleNotation[110X is set, it is tried harder to write442down an rcwa permutation of ℤ of finite order as a product of disjoint443residue class cycles, if this is possible. If the option [10XAsClassMapping[110X is444set, [10XDisplay[110X shows which residue classes are mapped to which by the affine445partial mappings, and marks any loops. The option [10XPrintNotation[110X influences446the output in favour of [5XGAP[105X - readability, and the option [10XAbridgedNotation[110X447can be used to abridge longer names like [10XClassShift[110X, [10XClassReflection[110X etc..448By default, the output of the methods for [10XDisplay[110X and [10XPrint[110X describes an449rcwa mapping in full. The [10XPrint[110Xed representation of an rcwa mapping is [5XGAP[105X -450readable if and only if the [10XPrint[110Xed representation of the elements of the451underlying ring is so.[133X452453[33X[0;0YThere is also an operation [10XLaTeXStringRcwaMapping[110X, which takes as argument454an rcwa mapping and returns a corresponding LaTeX string. The output makes455use of the LaTeX macro package [5Xamsmath[105X. If the option [3XFactorization[103X is set456and the argument is bijective, a factorization into class shifts, class457reflections, class transpositions and prime switches is printed (cf.458[2XFactorizationIntoCSCRCT[102X ([14X2.5-1[114X)). For rcwa mappings with modulus greater459than 1, an indentation by [3XIndentation[103X characters can be obtained by setting460this option value accordingly.[133X461462[4X[32X Example [32X[104X463[4X[28X[128X[104X464[4X[25Xgap>[125X [27XPrint(LaTeXStringRcwaMapping(T));[127X[104X465[4X[28Xn \ \mapsto \[128X[104X466[4X[28X\begin{cases}[128X[104X467[4X[28X n/2 & \text{if} \ n \in 0(2), \\[128X[104X468[4X[28X (3n+1)/2 & \text{if} \ n \in 1(2).[128X[104X469[4X[28X\end{cases}[128X[104X470[4X[28X[128X[104X471[4X[32X[104X472473[33X[0;0YThere is an operation [10XLaTeXAndXDVI[110X which displays an rcwa mapping in an [5Xxdvi[105X474window. This works as follows: The string returned by [10XLaTeXStringRcwaMapping[110X475is inserted into a LaTeX template file. This file is LaTeX'ed, and the476result is shown with [5Xxdvi[105X. Calling [10XDisplay[110X with option [3Xxdvi[103X has the same477effect. The operation [10XLaTeXAndXDVI[110X is only available on UNIX systems, and478requires suitable installations of LaTeX and [5Xxdvi[105X.[133X479480481[1X2.3 [33X[0;0YBasic arithmetic for residue-class-wise affine mappings[133X[101X482483[33X[0;0YTesting rcwa mappings for equality requires only comparing their coefficient484lists, hence is cheap. Rcwa mappings can be multiplied, thus there is a485method for [10X*[110X. Rcwa permutations can also be inverted, thus there is a method486for [10XInverse[110X. The latter method is usually accessed by raising a mapping to a487power with negative exponent. Multiplying, inverting and computing powers of488tame rcwa mappings is cheap. Computing powers of wild mappings is usually489expensive -- run time and memory requirements normally grow approximately490exponentially with the exponent. How expensive multiplying a couple of wild491mappings is, varies very much. In any case, the amount of memory required492for storing an rcwa mapping is proportional to its modulus. Whether a given493mapping is tame or wild can be determined by the operation [10XIsTame[110X. There is494a method for [10XOrder[110X, which can not only compute a finite order, but which can495also detect infinite order.[133X496497[4X[32X Example [32X[104X498[4X[28X[128X[104X499[4X[25Xgap>[125X [27XT := RcwaMapping([[1,0,2],[3,1,2]]);; # The Collatz mapping.[127X[104X500[4X[25Xgap>[125X [27Xa := RcwaMapping([[2,0,3],[4,-1,3],[4,1,3]]);; # Collatz' permutation.[127X[104X501[4X[25Xgap>[125X [27XList([-4..4],k->Modulus(a^k));[127X[104X502[4X[28X[ 256, 64, 16, 4, 1, 3, 9, 27, 81 ][128X[104X503[4X[25Xgap>[125X [27XIsTame(T) or IsTame(a);[127X[104X504[4X[28Xfalse[128X[104X505[4X[25Xgap>[125X [27XIsTame(ClassShift(0,1)) and IsTame(ClassTransposition(0,2,1,2));[127X[104X506[4X[28Xtrue[128X[104X507[4X[25Xgap>[125X [27XT^2*a*T*a^-3;[127X[104X508[4X[28X<rcwa mapping of Z with modulus 768>[128X[104X509[4X[25Xgap>[125X [27X(ClassShift(1,3)*ClassReflection(2,7))^1000000;[127X[104X510[4X[28X<rcwa permutation of Z with modulus 21>[128X[104X511[4X[28X[128X[104X512[4X[32X[104X513514[33X[0;0YThere are methods installed for [10XIsInjective[110X, [10XIsSurjective[110X, [10XIsBijective[110X and515[10XImage[110X.[133X516517[4X[32X Example [32X[104X518[4X[28X[128X[104X519[4X[25Xgap>[125X [27X[ IsInjective(T), IsSurjective(T), IsBijective(a) ];[127X[104X520[4X[28X[ false, true, true ][128X[104X521[4X[25Xgap>[125X [27XImage(RcwaMapping([[2,0,1]]));[127X[104X522[4X[28X0(2)[128X[104X523[4X[28X[128X[104X524[4X[32X[104X525526[33X[0;0YImages of elements, of finite sets of elements and of unions of finitely527many residue classes of the source of an rcwa mapping can be computed with528[10X^[110X, the same symbol as used for exponentiation and conjugation. The same529works for partitions of the source into a finite number of residue classes.[133X530531[4X[32X Example [32X[104X532[4X[28X[128X[104X533[4X[25Xgap>[125X [27X15^T;[127X[104X534[4X[28X23[128X[104X535[4X[25Xgap>[125X [27XResidueClass(1,2)^T;[127X[104X536[4X[28X2(3)[128X[104X537[4X[25Xgap>[125X [27XList([[0,3],[1,3],[2,3]],ResidueClass)^a;[127X[104X538[4X[28X[ 0(2), 1(4), 3(4) ][128X[104X539[4X[28X[128X[104X540[4X[32X[104X541542[33X[0;0YFor computing preimages of elements under rcwa mappings, there are methods543for [10XPreImageElm[110X and [10XPreImagesElm[110X. The preimage of a finite set of ring544elements or of a union of finitely many residue classes under an rcwa545mapping can be computed by [10XPreImage[110X.[133X546547[4X[32X Example [32X[104X548[4X[28X[128X[104X549[4X[25Xgap>[125X [27XPreImagesElm(T,8);[127X[104X550[4X[28X[ 5, 16 ][128X[104X551[4X[25Xgap>[125X [27XPreImage(T,ResidueClass(Integers,3,2));[127X[104X552[4X[28XZ \ 0(6) U 2(6)[128X[104X553[4X[25Xgap>[125X [27XM := [1];; l := [1];;[127X[104X554[4X[25Xgap>[125X [27Xwhile Length(M) < 5000 do M := PreImage(T,M); Add(l,Length(M)); od; l;[127X[104X555[4X[28X[ 1, 1, 2, 2, 4, 5, 8, 10, 14, 18, 26, 36, 50, 67, 89, 117, 157, 208, [128X[104X556[4X[28X 277, 367, 488, 649, 869, 1154, 1534, 2039, 2721, 3629, 4843, 6458 ][128X[104X557[4X[28X[128X[104X558[4X[32X[104X559560[33X[0;0YThere is a method for the operation [10XSupport[110X for computing the support of an561rcwa mapping. A synonym for [10XSupport[110X is [10XMovedPoints[110X. The natural density of562the support of an rcwa mapping of ℤ can be computed efficiently with the563operation [10XDensityOfSupport[110X. Likewise, the natural density of the set of564fixed points of an rcwa mapping of ℤ can be computed efficiently with the565operation [10XDensityOfSetOfFixedPoints[110X. There is also a method for566[10XRestrictedPerm[110X for computing the restriction of an rcwa permutation to a567union of residue classes which it fixes setwise.[133X568569[4X[32X Example [32X[104X570[4X[28X[128X[104X571[4X[25Xgap>[125X [27XList([a,a^2],Support);[127X[104X572[4X[28X[ Z \ [ -1, 0, 1 ], Z \ [ -3, -2, -1, 0, 1, 2, 3 ] ][128X[104X573[4X[25Xgap>[125X [27XRestrictedPerm(ClassShift(0,2)*ClassReflection(1,2),[127X[104X574[4X[25X>[125X [27X ResidueClass(0,2));[127X[104X575[4X[28X<rcwa mapping of Z with modulus 2>[128X[104X576[4X[25Xgap>[125X [27Xlast = ClassShift(0,2);[127X[104X577[4X[28Xtrue[128X[104X578[4X[28X[128X[104X579[4X[32X[104X580581[33X[0;0YRcwa mappings can be added and subtracted pointwise. However, please note582that the set of rcwa mappings of a ring does not form a ring under [10X+[110X and [10X*[110X.[133X583584[4X[32X Example [32X[104X585[4X[28X[128X[104X586[4X[25Xgap>[125X [27Xb := ClassShift(0,3) * a;;[127X[104X587[4X[25Xgap>[125X [27X[ Image((a + b)), Image((a - b)) ];[127X[104X588[4X[28X[ 2(4), [ -2, 0 ] ][128X[104X589[4X[28X[128X[104X590[4X[32X[104X591592[33X[0;0YThere are operations [10XModulus[110X (abbreviated [10XMod[110X) and [10XCoefficients[110X for593retrieving the modulus and the coefficient list of an rcwa mapping. The594meaning of the return values is as described in Section [14X2.2[114X.[133X595596[33X[0;0YGeneral documentation for most operations mentioned in this section can be597found in the [5XGAP[105X reference manual. For rcwa mappings of rings other than ℤ,598not for all operations applicable methods are available.[133X599600[33X[0;0YAs in general a subring relation [22XR_1<R_2[122X does [13Xnot[113X give rise to a natural601embedding of RCWA([22XR_1[122X) into RCWA([22XR_2[122X), there is no coercion between rcwa602mappings or rcwa groups over different rings.[133X603604605[1X2.4 [33X[0;0YAttributes and properties of residue-class-wise affine mappings[133X[101X606607[33X[0;0YA number of basic attributes and properties of an rcwa mapping are derived608immediately from the coefficients of its affine partial mappings. This holds609for example for the multiplier and the divisor. These two values are stored610as attributes [10XMultiplier[110X and [10XDivisor[110X, or for short [10XMult[110X and [10XDiv[110X. The [13Xprime611set[113X of an rcwa mapping is the set of prime divisors of the product of its612modulus and its multiplier. It is stored as an attribute [10XPrimeSet[110X. The613[13Xmaximal shift[113X of an rcwa mapping of ℤ is the maximum of the absolute values614of its coefficients [22Xb_r(m)[122X in the notation introduced in Section [14X2.1[114X. It is615stored as an attribute [10XMaximalShift[110X. An rcwa mapping is called [13Xclass-wise616translating[113X if all of its affine partial mappings are translations, it is617called [13Xintegral[113X if its divisor equals 1, and it is called [13Xbalanced[113X if its618multiplier and its divisor have the same prime divisors. A class-wise619translating mapping has the property [10XIsClassWiseTranslating[110X, an integral620mapping has the property [10XIsIntegral[110X and a balanced mapping has the property621[10XIsBalanced[110X. An rcwa mapping of the ring of integers or of one of its622semilocalizations is called [13Xclass-wise order-preserving[113X if and only if all623coefficients [22Xa_r(m)[122X (cf. Section [14X2.1[114X) in the numerators of the affine624partial mappings are positive. The corresponding property is625[10XIsClassWiseOrderPreserving[110X. An rcwa mapping of ℤ is called [13Xsign-preserving[113X626if it does not map nonnegative integers to negative integers or vice versa.627The corresponding property is [10XIsSignPreserving[110X. All elements of the simple628group CT(ℤ) generated by the set of all class transpositions are629sign-preserving.[133X630631[4X[32X Example [32X[104X632[4X[28X[128X[104X633[4X[25Xgap>[125X [27Xu := RcwaMapping([[3,0,5],[9,1,5],[3,-1,5],[9,-2,5],[9,4,5]]);;[127X[104X634[4X[25Xgap>[125X [27XIsBijective(u);; Display(u);[127X[104X635[4X[28X[128X[104X636[4X[28XRcwa permutation of Z with modulus 5[128X[104X637[4X[28X[128X[104X638[4X[28X /[128X[104X639[4X[28X | 3n/5 if n in 0(5)[128X[104X640[4X[28X | (9n+1)/5 if n in 1(5)[128X[104X641[4X[28X n |-> < (3n-1)/5 if n in 2(5)[128X[104X642[4X[28X | (9n-2)/5 if n in 3(5)[128X[104X643[4X[28X | (9n+4)/5 if n in 4(5)[128X[104X644[4X[28X \[128X[104X645[4X[28X[128X[104X646[4X[25Xgap>[125X [27XMultiplier(u);[127X[104X647[4X[28X9[128X[104X648[4X[25Xgap>[125X [27XDivisor(u);[127X[104X649[4X[28X5[128X[104X650[4X[25Xgap>[125X [27XPrimeSet(u);[127X[104X651[4X[28X[ 3, 5 ][128X[104X652[4X[25Xgap>[125X [27XIsIntegral(u) or IsBalanced(u);[127X[104X653[4X[28Xfalse[128X[104X654[4X[25Xgap>[125X [27XIsClassWiseOrderPreserving(u) and IsSignPreserving(u);[127X[104X655[4X[28Xtrue[128X[104X656[4X[28X[128X[104X657[4X[32X[104X658659[33X[0;0YThere are a couple of further attributes and operations related to the660affine partial mappings of an rcwa mapping:[133X661662[1X2.4-1 LargestSourcesOfAffineMappings[101X663664[29X[2XLargestSourcesOfAffineMappings[102X( [3Xf[103X ) [32X attribute665[6XReturns:[106X [33X[0;10Ythe coarsest partition of [10XSource([3Xf[103X[10X)[110X on whose elements the rcwa666mapping [3Xf[103X is affine.[133X667668[4X[32X Example [32X[104X669[4X[28X[128X[104X670[4X[25Xgap>[125X [27XLargestSourcesOfAffineMappings(ClassShift(3,7));[127X[104X671[4X[28X[ Z \ 3(7), 3(7) ][128X[104X672[4X[25Xgap>[125X [27XLargestSourcesOfAffineMappings(ClassReflection(0,1));[127X[104X673[4X[28X[ Integers ][128X[104X674[4X[25Xgap>[125X [27Xu := RcwaMapping([[3,0,5],[9,1,5],[3,-1,5],[9,-2,5],[9,4,5]]);;[127X[104X675[4X[25Xgap>[125X [27XList( [ u, u^-1 ], LargestSourcesOfAffineMappings );[127X[104X676[4X[28X[ [ 0(5), 1(5), 2(5), 3(5), 4(5) ], [ 0(3), 1(3), 2(9), 5(9), 8(9) ] ][128X[104X677[4X[25Xgap>[125X [27Xkappa := ClassTransposition(2,4,3,4) * ClassTransposition(4,6,8,12)[127X[104X678[4X[25X>[125X [27X * ClassTransposition(3,4,4,6);[127X[104X679[4X[28X<rcwa permutation of Z with modulus 12>[128X[104X680[4X[25Xgap>[125X [27XLargestSourcesOfAffineMappings(kappa);[127X[104X681[4X[28X[ 2(4), 1(4) U 0(12), 3(12) U 7(12), 4(12), 8(12), 11(12) ][128X[104X682[4X[28X[128X[104X683[4X[32X[104X684685[1X2.4-2 FixedPointsOfAffinePartialMappings[101X686687[29X[2XFixedPointsOfAffinePartialMappings[102X( [3Xf[103X ) [32X attribute688[6XReturns:[106X [33X[0;10Ya list of the sets of fixed points of the affine partial mappings689of the rcwa mapping [3Xf[103X in the quotient field of its source.[133X690691[33X[0;0YThe returned list contains entries for the restrictions of [3Xf[103X to all residue692classes modulo [10XMod([3Xf[103X[10X)[110X. A list entry can either be an empty set, the source693of [3Xf[103X or a set of cardinality 1. The ordering of the entries corresponds to694the ordering of the residues in [10XAllResidues(Source([3Xf[103X[10X),[3Xm[103X[10X)[110X.[133X695696[4X[32X Example [32X[104X697[4X[28X[128X[104X698[4X[25Xgap>[125X [27XFixedPointsOfAffinePartialMappings(ClassShift(0,2));[127X[104X699[4X[28X[ [ ], Rationals ][128X[104X700[4X[25Xgap>[125X [27XList([1..3],k->FixedPointsOfAffinePartialMappings(T^k));[127X[104X701[4X[28X[ [ [ 0 ], [ -1 ] ], [ [ 0 ], [ 1 ], [ 2 ], [ -1 ] ], [128X[104X702[4X[28X [ [ 0 ], [ -7 ], [ 2/5 ], [ -5 ], [ 4/5 ], [ 1/5 ], [ -10 ], [ -1 ] ] ][128X[104X703[4X[28X[128X[104X704[4X[32X[104X705706[1X2.4-3 Multpk[101X707708[29X[2XMultpk[102X( [3Xf[103X, [3Xp[103X, [3Xk[103X ) [32X operation709[6XReturns:[106X [33X[0;10Ythe union of the residue classes [22Xr(m)[122X such that [22Xp^k||a_r(m)[122X if [22Xk ≥7100[122X, and the union of the residue classes [22Xr(m)[122X such that [22Xp^k||c_r(m)[122X711if [22Xk ≤ 0[122X. In this context, [22Xm[122X denotes the modulus of [3Xf[103X, and [22Xa_r(m)[122X712and [22Xc_r(m)[122X denote the coefficients of [3Xf[103X as introduced in713Section [14X2.1[114X.[133X714715[4X[32X Example [32X[104X716[4X[28X[128X[104X717[4X[25Xgap>[125X [27XT := RcwaMapping([[1,0,2],[3,1,2]]);; # The Collatz mapping.[127X[104X718[4X[25Xgap>[125X [27X[ Multpk(T,2,-1), Multpk(T,3,1) ];[127X[104X719[4X[28X[ Integers, 1(2) ][128X[104X720[4X[25Xgap>[125X [27Xu := RcwaMapping([[3,0,5],[9,1,5],[3,-1,5],[9,-2,5],[9,4,5]]);;[127X[104X721[4X[25Xgap>[125X [27X[ Multpk(u,3,0), Multpk(u,3,1), Multpk(u,3,2), Multpk(u,5,-1) ];[127X[104X722[4X[28X[ [ ], 0(5) U 2(5), Z \ 0(5) U 2(5), Integers ][128X[104X723[4X[28X[128X[104X724[4X[32X[104X725726[33X[0;0YThere are attributes [10XClassWiseOrderPreservingOn[110X, [10XClassWiseConstantOn[110X and727[10XClassWiseOrderReversingOn[110X which store the union of the residue classes728(mod [10XMod([3Xf[103X[10X)[110X) on which an rcwa mapping [3Xf[103X of ℤ or of a semilocalization729thereof is class-wise order-preserving, class-wise constant or class-wise730order-reversing, respectively.[133X731732[4X[32X Example [32X[104X733[4X[28X[128X[104X734[4X[25Xgap>[125X [27XList([ClassTransposition(1,2,0,4),ClassShift(2,3),[127X[104X735[4X[25X>[125X [27X ClassReflection(2,5)],ClassWiseOrderPreservingOn);[127X[104X736[4X[28X[ Integers, Integers, Z \ 2(5) ][128X[104X737[4X[28X[128X[104X738[4X[32X[104X739740[33X[0;0YAlso there are attributes [10XShiftsUpOn[110X and [10XShiftsDownOn[110X which store the union741of the residue classes (mod [10XMod([3Xf[103X[10X)[110X) on which an rcwa mapping [3Xf[103X of ℤ induces742affine mappings [22Xn ↦ n + c[122X for [22Xc > 0[122X, respectively, [22Xc < 0[122X.[133X743744[33X[0;0YFinally, there are epimorphisms from the subgroup of RCWA(ℤ) formed by all745class-wise order-preserving elements to (ℤ,+) and from RCWA(ℤ) itself to the746cyclic group of order 2, respectively:[133X747748[1X2.4-4 Determinant[101X749750[29X[2XDeterminant[102X( [3Xf[103X ) [32X method751[6XReturns:[106X [33X[0;10Ythe determinant of the rcwa mapping [3Xf[103X of ℤ.[133X752753[33X[0;0YThe [13Xdeterminant[113X of an affine mapping [22Xn ↦ (an+b)/c[122X whose source is a residue754class [22Xr(m)[122X is defined by [22Xb/|a|m[122X. This definition is extended additively to755determinants of rcwa mappings.[133X756757[33X[0;0YLet [22Xf[122X be an rcwa mapping of the integers, and let [22Xm[122X denote its modulus.758Using the notation [22Xf|_r(m): n ↦ (a_r(m) ⋅ n + b_r(m))/c_r(m)[122X for the affine759partial mappings, the [13Xdeterminant[113X det([22Xf[122X) of [22Xf[122X is given by[133X760761-----762\ b_r(m)763> --------------764/ |a_{r(m)}| * m765-----766r(m) in Z/mZ .767768769[33X[0;0YThe determinant mapping is an epimorphism from the group of all class-wise770order-preserving rcwa permutations of ℤ to (ℤ,+), see [Koh05],771Theorem 2.11.9.[133X772773[4X[32X Example [32X[104X774[4X[28X[128X[104X775[4X[25Xgap>[125X [27XList([ClassTransposition(0,4,5,12),ClassShift(3,7)],Determinant);[127X[104X776[4X[28X[ 0, 1 ][128X[104X777[4X[25Xgap>[125X [27XDeterminant(ClassTransposition(0,4,5,12)*ClassShift(3,7)^100); [127X[104X778[4X[28X100[128X[104X779[4X[28X[128X[104X780[4X[32X[104X781782[1X2.4-5 Sign[101X783784[29X[2XSign[102X( [3Xg[103X ) [32X attribute785[6XReturns:[106X [33X[0;10Ythe sign of the rcwa permutation [3Xg[103X of ℤ.[133X786787[33X[0;0YLet [22Xσ[122X be an rcwa permutation of the integers, and let [22Xm[122X denote its modulus.788Using the notation [22Xσ|_r(m): n ↦ (a_r(m) ⋅ n + b_r(m))/c_r(m)[122X for the affine789partial mappings, the [13Xsign[113X of [22Xσ[122X is defined by[133X790791-----792\ m - 2r793det(sigma) + > -------794/ m795-----796a_r(m) < 0797(-1) .798799800[33X[0;0YThe sign mapping is an epimorphism from RCWA(ℤ) to the group [22Xℤ^×[122X of units801of ℤ, see [Koh05], Theorem 2.12.8. Therefore the kernel of the sign mapping802is a normal subgroup of RCWA(ℤ) of index 2. The simple group CT(ℤ) is a803subgroup of this kernel.[133X804805[4X[32X Example [32X[104X806[4X[28X[128X[104X807[4X[25Xgap>[125X [27XList([ClassTransposition(3,4,2,6),[127X[104X808[4X[25X>[125X [27X ClassShift(0,3),ClassReflection(2,5)],Sign);[127X[104X809[4X[28X[ 1, -1, -1 ][128X[104X810[4X[28X[128X[104X811[4X[32X[104X812813814[1X2.5 [33X[0;0YFactoring residue-class-wise affine permutations[133X[101X815816[33X[0;0YFactoring group elements into the members of some [21Xnice[121X set of generators is817often helpful. In this section we describe an operation which attempts to818solve this problem for the group RCWA(ℤ). Elements of finitely generated819rcwa groups can be factored into generators [21Xas usual[121X,820see [2XPreImagesRepresentative[102X ([14X3.2-3[114X).[133X821822[1X2.5-1 FactorizationIntoCSCRCT[101X823824[29X[2XFactorizationIntoCSCRCT[102X( [3Xg[103X ) [32X attribute825[29X[2XFactorization[102X( [3Xg[103X ) [32X method826[6XReturns:[106X [33X[0;10Ya factorization of the rcwa permutation [3Xg[103X of ℤ into class shifts,827class reflections and class transpositions, provided that such a828factorization exists and the method finds it.[133X829830[33X[0;0YThe method may return [10Xfail[110X, stop with an error message or run into an831infinite loop. If it returns a result, this result is always correct.[133X832833[33X[0;0YThe problem of obtaining a factorization as described is algorithmically834difficult, and this factorization routine is currently perhaps the most835sophisticated part of the [5XRCWA[105X package. Information about the progress of836the factorization process can be obtained by setting the info level of the837Info class [2XInfoRCWA[102X ([14X9.5-1[114X) to 2.[133X838839[33X[0;0YBy default, prime switches ([22X→[122X [2XPrimeSwitch[102X ([14X2.5-2[114X)) are taken as one factor.840If the option [3XExpandPrimeSwitches[103X is set, they are each decomposed into the8416 class transpositions given in the definition.[133X842843[33X[0;0YBy default, the factoring process begins with splitting off factors from the844right. This can be changed by setting the option [3XDirection[103X to [10X"from the845left"[110X.[133X846847[33X[0;0YBy default, a reasonably coarse respected partition of the integral mapping848occurring in the final stage of the algorithm is computed. This can be849suppressed by setting the option [3XShortenPartition[103X equal to [10Xfalse[110X.[133X850851[33X[0;0YBy default, at the end it is checked whether the product of the determined852factors indeed equals [3Xg[103X. This check can be suppressed by setting the option853[3XNC[103X.[133X854855[4X[32X Example [32X[104X856[4X[28X[128X[104X857[4X[25Xgap>[125X [27XFactorization(Comm(ClassShift(0,3)*ClassReflection(1,2),[127X[104X858[4X[25X>[125X [27X ClassShift(0,2)));[127X[104X859[4X[28X[ ClassReflection( 2(3) ), ClassShift( 2(6) )^-1, ( 0(6), 2(6) ), [128X[104X860[4X[28X ( 0(6), 5(6) ) ][128X[104X861[4X[28X[128X[104X862[4X[32X[104X863864[33X[0;0YFor purposes of demonstrating the capabilities of the factorization routine,865in Section [14X7.2[114X Collatz' permutation is factored. Lothar Collatz has866investigated this permutation in 1932. Its cycle structure is unknown so867far.[133X868869[33X[0;0YThe permutations of the following kind play an important role in factoring870rcwa permutations of ℤ into class shifts, class reflections and class871transpositions:[133X872873[1X2.5-2 PrimeSwitch[101X874875[29X[2XPrimeSwitch[102X( [3Xp[103X ) [32X method876[29X[2XPrimeSwitch[102X( [3Xp[103X, [3Xk[103X ) [32X method877[29X[2XPrimeSwitch[102X( [3Xp[103X, [3Xr[103X, [3Xm[103X ) [32X method878[29X[2XPrimeSwitch[102X( [3Xp[103X, [3Xcl[103X ) [32X method879[6XReturns:[106X [33X[0;10Yin the first form the [13Xprime switch[113X [22Xσ_p := τ_0(8),1(2p) ⋅880τ_4(8),-1(2p) ⋅ τ_0(4),1(2p) ⋅ τ_2(4),-1(2p) ⋅ τ_2(2p),1(4p) ⋅881τ_4(2p),2p+1(4p)[122X, in the second form the restriction of [22Xσ_p[122X by [22Xn ↦882kn[122X, and in the third and fourth form the [13Xprime switch[113X [22Xσ_p,r(m) :=883τ_r_1(m/2),r_2(m) ⋅ τ_r_2(m),r_1(pm/2) ⋅ τ_r(m/2),r_1(pm/2)[122X. In884the latter case, [3Xcl[103X is the residue class [22Xr(m)[122X, the residue [22Xr_1[122X is885[22X1-(r mod 2)[122X, and [22Xr_2[122X is defined by the equality [22Xr(m) ∪ r_2(m) =886r(m/2)[122X.[133X887888[33X[0;0YFor an odd prime [22Xp[122X, the prime switch [22Xσ_p[122X is an rcwa permutation of ℤ with889modulus [22X4p[122X, multiplier [22Xp[122X and divisor 2. The prime switch [22Xσ_p,r(m)[122X has890multiplier [22Xp[122X and divisor 2, and the class where the multiplication by [22Xp[122X891occurs is just [22Xr(m)[122X. The key mathematical property of a prime switch is that892it is a product of class transpositions whose multiplier and divisor are893coprime.[133X894895[33X[0;0YPrime switches can be distinguished from other rcwa mappings by their [5XGAP[105X896property [10XIsPrimeSwitch[110X.[133X897898[4X[32X Example [32X[104X899[4X[28X[128X[104X900[4X[25Xgap>[125X [27XDisplay(PrimeSwitch(3));[127X[104X901[4X[28X[128X[104X902[4X[28XWild rcwa permutation of Z with modulus 12[128X[104X903[4X[28X[128X[104X904[4X[28X /[128X[104X905[4X[28X | (3n+4)/2 if n in 2(4)[128X[104X906[4X[28X | n-1 if n in 5(6) U 8(12)[128X[104X907[4X[28X | n+1 if n in 1(6)[128X[104X908[4X[28X n |-> < n/2 if n in 0(12)[128X[104X909[4X[28X | n-3 if n in 4(12)[128X[104X910[4X[28X | n if n in 3(6)[128X[104X911[4X[28X |[128X[104X912[4X[28X \[128X[104X913[4X[28X[128X[104X914[4X[25Xgap>[125X [27XDisplay(PrimeSwitch(3):AsClassMapping);[127X[104X915[4X[28X[128X[104X916[4X[28XWild rcwa permutation of Z with modulus 12[128X[104X917[4X[28X[128X[104X918[4X[28X 0(12) -> 0(6) loop[128X[104X919[4X[28X 1(6) -> 2(6)[128X[104X920[4X[28X 2(4) -> 5(6)[128X[104X921[4X[28X 3(6) -> 3(6) id[128X[104X922[4X[28X 4(12) -> 1(12)[128X[104X923[4X[28X 5(6) -> 4(6)[128X[104X924[4X[28X 8(12) -> 7(12)[128X[104X925[4X[28X[128X[104X926[4X[25Xgap>[125X [27XFactorization(PrimeSwitch(3));[127X[104X927[4X[28X[ ( 1(6), 0(8) ), ( 5(6), 4(8) ), ( 0(4), 1(6) ), ( 2(4), 5(6) ), [128X[104X928[4X[28X ( 2(6), 1(12) ), ( 4(6), 7(12) ) ][128X[104X929[4X[25Xgap>[125X [27XDisplay(PrimeSwitch(5,3,4));[127X[104X930[4X[28X[128X[104X931[4X[28XWild rcwa permutation of Z with modulus 20[128X[104X932[4X[28X[128X[104X933[4X[28X /[128X[104X934[4X[28X | n+1 if n in 0(2)[128X[104X935[4X[28X | 5n-5 if n in 3(4)[128X[104X936[4X[28X n |-> < (n-1)/2 if n in 1(4) \ 1(20)[128X[104X937[4X[28X | n-1 if n in 1(20)[128X[104X938[4X[28X |[128X[104X939[4X[28X \[128X[104X940[4X[28X[128X[104X941[4X[25Xgap>[125X [27XMultpk(PrimeSwitch(5,3,4),5,1);[127X[104X942[4X[28X3(4)[128X[104X943[4X[25Xgap>[125X [27XPrimeSwitch(5,3,4) = PrimeSwitch(5,ResidueClass(3,4));[127X[104X944[4X[28Xtrue[128X[104X945[4X[25Xgap>[125X [27XFactorization(PrimeSwitch(5,3,4));[127X[104X946[4X[28X[ ( 0(2), 1(4) ), ( 1(4), 0(10) ), ( 1(2), 0(10) ) ][128X[104X947[4X[28X[128X[104X948[4X[32X[104X949950[33X[0;0YObtaining a factorization of an rcwa permutation into class shifts, class951reflections and class transpositions is particularly difficult if multiplier952and divisor are coprime. A prototype of permutations which have this953property has been introduced in a different context in [Kel99]:[133X954955[1X2.5-3 mKnot[101X956957[29X[2XmKnot[102X( [3Xm[103X ) [32X function958[6XReturns:[106X [33X[0;10Ythe permutation [22Xg_m[122X as defined in [Kel99].[133X959960[33X[0;0YThe argument [3Xm[103X must be an odd integer greater than 1.[133X961962[4X[32X Example [32X[104X963[4X[28X[128X[104X964[4X[25Xgap>[125X [27XDisplay(mKnot(5));[127X[104X965[4X[28X[128X[104X966[4X[28XWild rcwa permutation of Z with modulus 5[128X[104X967[4X[28X[128X[104X968[4X[28X /[128X[104X969[4X[28X | 6n/5 if n in 0(5)[128X[104X970[4X[28X | (4n+1)/5 if n in 1(5)[128X[104X971[4X[28X n |-> < (6n-2)/5 if n in 2(5)[128X[104X972[4X[28X | (4n+3)/5 if n in 3(5)[128X[104X973[4X[28X | (6n-4)/5 if n in 4(5)[128X[104X974[4X[28X \[128X[104X975[4X[28X[128X[104X976[4X[32X[104X977978[33X[0;0YIn his article, Timothy P. Keller shows that a permutation of this type979cannot have infinitely many cycles of any given finite length.[133X980981982[1X2.6 [33X[0;0YExtracting roots of residue-class-wise affine mappings[133X[101X983984[1X2.6-1 Root[101X985986[29X[2XRoot[102X( [3Xf[103X, [3Xk[103X ) [32X method987[6XReturns:[106X [33X[0;10Yan rcwa mapping [10Xg[110X such that [10Xg^[3Xk[103X[10X=[3Xf[103X[10X[110X, provided that such a mapping988exists and that there is a method available which can determine989it.[133X990991[33X[0;0YCurrently, extracting roots is implemented for rcwa permutations of finite992order.[133X993994[4X[32X Example [32X[104X995[4X[28X[128X[104X996[4X[25Xgap>[125X [27XRoot(ClassTransposition(0,2,1,2),100);[127X[104X997[4X[28X( 0(8), 2(8), 4(8), 6(8), 1(8), 3(8), 5(8), 7(8) )[128X[104X998[4X[25Xgap>[125X [27XDisplay(last:CycleNotation:=false);[127X[104X999[4X[28X[128X[104X1000[4X[28XTame rcwa permutation of Z with modulus 8[128X[104X1001[4X[28X[128X[104X1002[4X[28X /[128X[104X1003[4X[28X | n+2 if n in Z \ 6(8) U 7(8)[128X[104X1004[4X[28X n |-> < n-5 if n in 6(8)[128X[104X1005[4X[28X | n-7 if n in 7(8)[128X[104X1006[4X[28X \[128X[104X1007[4X[28X[128X[104X1008[4X[25Xgap>[125X [27Xlast^100 = ClassTransposition(0,2,1,2);[127X[104X1009[4X[28Xtrue[128X[104X1010[4X[28X[128X[104X1011[4X[32X[104X101210131014[1X2.7 [33X[0;0YSpecial functions for non-bijective mappings[133X[101X10151016[1X2.7-1 RightInverse[101X10171018[29X[2XRightInverse[102X( [3Xf[103X ) [32X attribute1019[6XReturns:[106X [33X[0;10Ya right inverse of the injective rcwa mapping [3Xf[103X, i.e. a mapping [22Xg[122X1020such that [3Xf[103X[22Xg[122X = 1.[133X10211022[4X[32X Example [32X[104X1023[4X[28X[128X[104X1024[4X[25Xgap>[125X [27Xtwice := 2*IdentityRcwaMappingOfZ;[127X[104X1025[4X[28XRcwa mapping of Z: n -> 2n[128X[104X1026[4X[25Xgap>[125X [27Xtwice * RightInverse(twice);[127X[104X1027[4X[28XIdentityMapping( Integers )[128X[104X1028[4X[28X[128X[104X1029[4X[32X[104X10301031[1X2.7-2 CommonRightInverse[101X10321033[29X[2XCommonRightInverse[102X( [3Xl[103X, [3Xr[103X ) [32X operation1034[6XReturns:[106X [33X[0;10Ya mapping [22Xd[122X such that [3Xl[103X[22Xd[122X = [3Xr[103X[22Xd[122X = 1.[133X10351036[33X[0;0YThe mappings [3Xl[103X and [3Xr[103X must be injective, and their images must form a1037partition of their source.[133X10381039[4X[32X Example [32X[104X1040[4X[28X[128X[104X1041[4X[25Xgap>[125X [27Xtwice := 2*IdentityRcwaMappingOfZ; twiceplus1 := twice+1;[127X[104X1042[4X[28XRcwa mapping of Z: n -> 2n[128X[104X1043[4X[28XRcwa mapping of Z: n -> 2n + 1[128X[104X1044[4X[25Xgap>[125X [27XDisplay(CommonRightInverse(twice,twiceplus1));[127X[104X1045[4X[28X[128X[104X1046[4X[28XRcwa mapping of Z with modulus 2[128X[104X1047[4X[28X[128X[104X1048[4X[28X /[128X[104X1049[4X[28X | n/2 if n in 0(2)[128X[104X1050[4X[28X n |-> < (n-1)/2 if n in 1(2)[128X[104X1051[4X[28X |[128X[104X1052[4X[28X \[128X[104X1053[4X[28X[128X[104X1054[4X[32X[104X10551056[1X2.7-3 ImageDensity[101X10571058[29X[2XImageDensity[102X( [3Xf[103X ) [32X attribute1059[6XReturns:[106X [33X[0;10Ythe [13Ximage density[113X of the rcwa mapping [3Xf[103X.[133X10601061[33X[0;0YIn the notation introduced in the definition of an rcwa mapping, the [13Ximage1062density[113X of an rcwa mapping [22Xf[122X is defined by 1/m [22X∑_r(m) ∈ R/mR1063|R/c_r(m)R|/|R/a_r(m)R|[122X. The image density of an injective rcwa mapping is [22X≤10641[122X, and the image density of a surjective rcwa mapping is [22X≥ 1[122X (this can be1065seen easily). Thus in particular the image density of a bijective rcwa1066mapping is 1.[133X10671068[4X[32X Example [32X[104X1069[4X[28X[128X[104X1070[4X[25Xgap>[125X [27XT := RcwaMapping([[1,0,2],[3,1,2]]);; # The Collatz mapping.[127X[104X1071[4X[25Xgap>[125X [27XList( [ T, ClassShift(0,1), RcwaMapping([[2,0,1]]) ], ImageDensity );[127X[104X1072[4X[28X[ 4/3, 1, 1/2 ][128X[104X1073[4X[28X[128X[104X1074[4X[32X[104X10751076[33X[0;0YGiven an rcwa mapping [10Xf[110X, the function [10XInjectiveAsMappingFrom[110X returns a set [10XS[110X1077such that the restriction of [10Xf[110X to [10XS[110X is injective, and such that the image of1078[10XS[110X under [10Xf[110X is the entire image of [10Xf[110X.[133X10791080[4X[32X Example [32X[104X1081[4X[28X[128X[104X1082[4X[25Xgap>[125X [27XInjectiveAsMappingFrom(T);[127X[104X1083[4X[28X0(2)[128X[104X1084[4X[28X[128X[104X1085[4X[32X[104X108610871088[1X2.8 [33X[0;0YOn trajectories and cycles of residue-class-wise affine mappings[133X[101X10891090[33X[0;0Y[5XRCWA[105X provides various methods to compute trajectories of rcwa mappings:[133X109110921093[1X2.8-1 [33X[0;0YTrajectory (methods for rcwa mappings)[133X[101X10941095[29X[2XTrajectory[102X( [3Xf[103X, [3Xn[103X, [3Xlength[103X ) [32X method1096[29X[2XTrajectory[102X( [3Xf[103X, [3Xn[103X, [3Xlength[103X, [3Xm[103X ) [32X method1097[29X[2XTrajectory[102X( [3Xf[103X, [3Xn[103X, [3Xterminal[103X ) [32X method1098[29X[2XTrajectory[102X( [3Xf[103X, [3Xn[103X, [3Xterminal[103X, [3Xm[103X ) [32X method1099[6XReturns:[106X [33X[0;10Ythe first [3Xlength[103X iterates in the trajectory of the rcwa mapping [3Xf[103X1100starting at [3Xn[103X, respectively the initial part of the trajectory of1101the rcwa mapping [3Xf[103X starting at [3Xn[103X which ends at the first1102occurrence of an iterate in the set [3Xterminal[103X. If the argument [3Xm[103X is1103given, the iterates are reduced (mod [3Xm[103X).[133X11041105[33X[0;0YTo save memory when computing long trajectories containing huge iterates,1106the reduction (mod [3Xm[103X) is done each time before storing an iterate. In place1107of the ring element [3Xn[103X, the methods also accept a finite set of ring elements1108or a union of residue classes.[133X11091110[4X[32X Example [32X[104X1111[4X[28X[128X[104X1112[4X[25Xgap>[125X [27XT := RcwaMapping([[1,0,2],[3,1,2]]);; # The Collatz mapping.[127X[104X1113[4X[25Xgap>[125X [27XTrajectory(T,27,15); Trajectory(T,27,20,5);[127X[104X1114[4X[28X[ 27, 41, 62, 31, 47, 71, 107, 161, 242, 121, 182, 91, 137, 206, 103 ][128X[104X1115[4X[28X[ 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 0, 3, 0, 0, 3 ][128X[104X1116[4X[25Xgap>[125X [27XTrajectory(T,15,[1]); Trajectory(T,15,[1],2);[127X[104X1117[4X[28X[ 15, 23, 35, 53, 80, 40, 20, 10, 5, 8, 4, 2, 1 ][128X[104X1118[4X[28X[ 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1 ][128X[104X1119[4X[25Xgap>[125X [27XTrajectory(T,ResidueClass(Integers,3,0),Integers);[127X[104X1120[4X[28X[ 0(3), 0(3) U 5(9), 0(3) U 5(9) U 7(9) U 8(27), [128X[104X1121[4X[28X <union of 20 residue classes (mod 27) (6 classes)>, [128X[104X1122[4X[28X <union of 73 residue classes (mod 81)>, Z \ 10(81) U 37(81), Integers ][128X[104X1123[4X[28X[128X[104X1124[4X[32X[104X112511261127[1X2.8-2 [33X[0;0YTrajectory (methods for rcwa mappings -- [21Xaccumulated coefficients[121X[101X[1X)[133X[101X11281129[29X[2XTrajectory[102X( [3Xf[103X, [3Xn[103X, [3Xlength[103X, [3Xwhichcoeffs[103X ) [32X method1130[29X[2XTrajectory[102X( [3Xf[103X, [3Xn[103X, [3Xterminal[103X, [3Xwhichcoeffs[103X ) [32X method1131[6XReturns:[106X [33X[0;10Yeither the list [10Xc[110X of triples of coprime coefficients such that for1132any [10Xk[110X it holds that [10X[3Xn[103X[10X^([3Xf[103X[10X^(k-1)) = (c[k][1]*[3Xn[103X[10X + c[k][2])/c[k][3][110X or1133the last entry of that list, depending on whether [3Xwhichcoeffs[103X is1134[10X"AllCoeffs"[110X or [10X"LastCoeffs"[110X.[133X11351136[33X[0;0YThe meanings of the arguments [3Xlength[103X and [3Xterminal[103X are the same as in the1137methods for the operation [10XTrajectory[110X described above. In general, computing1138only the last coefficient triple ([3Xwhichcoeffs[103X = [10X"LastCoeffs"[110X) needs1139considerably less memory than computing the entire list.[133X11401141[4X[32X Example [32X[104X1142[4X[28X[128X[104X1143[4X[25Xgap>[125X [27XTrajectory(T,27,[1],"LastCoeffs");[127X[104X1144[4X[28X[ 36472996377170786403, 195820718533800070543, 1180591620717411303424 ][128X[104X1145[4X[25Xgap>[125X [27X(last[1]*27+last[2])/last[3];[127X[104X1146[4X[28X1[128X[104X1147[4X[28X[128X[104X1148[4X[32X[104X11491150[33X[0;0YWhen dealing with problems like the [22X3n+1[122X-Conjecture or when determining the1151degree of transitivity of the natural action of an rcwa group on its1152underlying ring, an important task is to determine the residue classes whose1153elements get larger or smaller when applying a given rcwa mapping:[133X115411551156[1X2.8-3 [33X[0;0YIncreasingOn & DecreasingOn (for an rcwa mapping)[133X[101X11571158[29X[2XIncreasingOn[102X( [3Xf[103X ) [32X attribute1159[29X[2XDecreasingOn[102X( [3Xf[103X ) [32X attribute1160[6XReturns:[106X [33X[0;10Ythe union of all residue classes [22Xr(m)[122X such that [22X|R/a_r(m)R| >1161|R/c_r(m)R|[122X or [22X|R/a_r(m)R| < |R/c_r(m)R|[122X, respectively, where [22XR[122X1162denotes the source, [22Xm[122X denotes the modulus and [22Xa_r(m)[122X, [22Xb_r(m)[122X and1163[22Xc_r(m)[122X denote the coefficients of [3Xf[103X as introduced in Section [14X2.1[114X.[133X11641165[33X[0;0YIf the argument is an rcwa mapping of ℤ in sparse representation, an option1166[10Xclasses[110X is interpreted; if set, the step of forming the union of the residue1167classes in question is omitted, and the list of residue classes is returned1168instead of their union. This may save time and memory if the modulus is1169large.[133X11701171[4X[32X Example [32X[104X1172[4X[28X[128X[104X1173[4X[25Xgap>[125X [27XList([1..3],k->IncreasingOn(T^k));[127X[104X1174[4X[28X[ 1(2), 3(4), 3(4) U 1(8) U 6(8) ][128X[104X1175[4X[25Xgap>[125X [27XList([1..3],k->DecreasingOn(T^k));[127X[104X1176[4X[28X[ 0(2), Z \ 3(4), 0(4) U 2(8) U 5(8) ][128X[104X1177[4X[25Xgap>[125X [27Xa := RcwaMapping([[2,0,3],[4,-1,3],[4,1,3]]);; # Collatz' permutation[127X[104X1178[4X[25Xgap>[125X [27XList([-2..2],k->IncreasingOn(a^k));[127X[104X1179[4X[28X[ Z \ 1(8) U 7(8), 0(2), [ ], Z \ 0(3), 1(9) U 4(9) U 5(9) U 8(9) ][128X[104X1180[4X[28X[128X[104X1181[4X[32X[104X11821183[33X[0;0YWe assign certain directed graphs to rcwa mappings, which encode the order1184in which trajectories may traverse the residue classes modulo some modulus:[133X11851186[1X2.8-4 TransitionGraph[101X11871188[29X[2XTransitionGraph[102X( [3Xf[103X, [3Xm[103X ) [32X operation1189[6XReturns:[106X [33X[0;10Ythe transition graph of the rcwa mapping [3Xf[103X for modulus [3Xm[103X.[133X11901191[33X[0;0YThe [13Xtransition graph[113X [22XΓ_f,m[122X of [22Xf[122X for modulus [22Xm[122X is defined as follows:[133X11921193[31X1[131X [33X[0;6YThe vertices are the residue classes (mod [22Xm[122X).[133X11941195[31X2[131X [33X[0;6YThere is an edge from [22Xr_1(m)[122X to [22Xr_2(m)[122X if and only if there is some [22Xn1196∈ r_1(m)[122X such that [22Xn^f ∈ r_2(m)[122X.[133X11971198[33X[0;0YThe assignment of the residue classes (mod [22Xm[122X) to the vertices of the graph1199corresponds to the ordering of the residues in [10XAllResidues(Source([3Xf[103X[10X),[3Xm[103X[10X)[110X. The1200result is returned in the format used by the package [5XGRAPE[105X [Soi16].[133X12011202[33X[0;0YThere are a couple of operations and attributes which are based on these1203graphs:[133X12041205[1X2.8-5 OrbitsModulo[101X12061207[29X[2XOrbitsModulo[102X( [3Xf[103X, [3Xm[103X ) [32X operation1208[6XReturns:[106X [33X[0;10Ythe partition of [10XAllResidues(Source([3Xf[103X[10X),[3Xm[103X[10X)[110X corresponding to the1209weakly connected components of the transition graph of the rcwa1210mapping [3Xf[103X for modulus [3Xm[103X.[133X12111212[4X[32X Example [32X[104X1213[4X[28X[128X[104X1214[4X[25Xgap>[125X [27XOrbitsModulo(ClassTransposition(0,2,1,4),8);[127X[104X1215[4X[28X[ [ 0, 1, 4 ], [ 2, 5, 6 ], [ 3 ], [ 7 ] ][128X[104X1216[4X[28X[128X[104X1217[4X[32X[104X12181219[1X2.8-6 FactorizationOnConnectedComponents[101X12201221[29X[2XFactorizationOnConnectedComponents[102X( [3Xf[103X, [3Xm[103X ) [32X operation1222[6XReturns:[106X [33X[0;10Ythe set of restrictions of the rcwa mapping [3Xf[103X to the weakly1223connected components of its transition graph [22XΓ_f,m[122X.[133X12241225[33X[0;0YThe product of the returned mappings is [3Xf[103X. They have pairwise disjoint1226supports, hence any two of them commute.[133X12271228[4X[32X Example [32X[104X1229[4X[28X[128X[104X1230[4X[25Xgap>[125X [27Xsigma := ClassTransposition(1,4,2,4) * ClassTransposition(1,4,3,4)[127X[104X1231[4X[25X>[125X [27X * ClassTransposition(3,9,6,18) * ClassTransposition(1,6,3,9);;[127X[104X1232[4X[25Xgap>[125X [27XList(FactorizationOnConnectedComponents(sigma,36),Support);[127X[104X1233[4X[28X[ 33(36) U 34(36) U 35(36), 9(36) U 10(36) U 11(36), [128X[104X1234[4X[28X <union of 23 residue classes (mod 36)> \ [ -6, 3 ] ][128X[104X1235[4X[28X[128X[104X1236[4X[32X[104X12371238[1X2.8-7 TransitionMatrix[101X12391240[29X[2XTransitionMatrix[102X( [3Xf[103X, [3Xm[103X ) [32X operation1241[6XReturns:[106X [33X[0;10Ythe transition matrix of the rcwa mapping [3Xf[103X for modulus [3Xm[103X.[133X12421243[33X[0;0YLet [22XM[122X be this matrix. Then for any two residue classes [22Xr_1(m), r_2(m) ∈1244R/mR[122X, the entry [22XM_r_1(m),r_2(m)[122X is defined by[133X12451246[33X[0;0Y(see the PDF- or HTML version of the manual), where [22Xhatm[122X is the product of [3Xm[103X1247and the square of the modulus of [3Xf[103X. The assignment of the residue classes1248(mod [3Xm[103X) to the rows and columns of the matrix corresponds to the ordering of1249the residues in [10XAllResidues(Source([3Xf[103X[10X),[3Xm[103X[10X)[110X.[133X12501251[33X[0;0YThe transition matrix is a weighted adjacency matrix of the corresponding1252transition graph [10XTransitionGraph([3Xf[103X[10X,[3Xm[103X[10X)[110X. The sums of the rows of a transition1253matrix are always equal to 1.[133X12541255[4X[32X Example [32X[104X1256[4X[28X[128X[104X1257[4X[25Xgap>[125X [27XT := RcwaMapping([[1,0,2],[3,1,2]]);; # The Collatz mapping.[127X[104X1258[4X[25Xgap>[125X [27XDisplay(TransitionMatrix(T^3,3));[127X[104X1259[4X[28X[ [ 1/8, 1/4, 5/8 ],[128X[104X1260[4X[28X [ 0, 1/4, 3/4 ],[128X[104X1261[4X[28X [ 0, 3/8, 5/8 ] ][128X[104X1262[4X[28X[128X[104X1263[4X[32X[104X126412651266[1X2.8-8 [33X[0;0YSources & Sinks (of an rcwa mapping)[133X[101X12671268[29X[2XSources[102X( [3Xf[103X ) [32X attribute1269[29X[2XSinks[102X( [3Xf[103X ) [32X attribute1270[6XReturns:[106X [33X[0;10Ya list of unions of residue classes modulo the modulus [22Xm[122X of the1271rcwa mapping [3Xf[103X, as described below.[133X12721273[33X[0;0YThe returned list contains an entry for any strongly connected component of1274the transition graph of [3Xf[103X for modulus [10XMod([3Xf[103X[10X)[110X which has only outgoing edges1275([21Xsource[121X) or which has only ingoing edges ([21Xsink[121X), respectively. The list1276entry corresponding to such a component is the union of the vertices1277belonging to it.[133X12781279[4X[32X Example [32X[104X1280[4X[28X[128X[104X1281[4X[25Xgap>[125X [27Xg := ClassTransposition(0,2,1,2)*ClassTransposition(0,2,1,4);;[127X[104X1282[4X[25Xgap>[125X [27XSources(g); Sinks(g);[127X[104X1283[4X[28X[ 0(4) ][128X[104X1284[4X[28X[ 1(4) ][128X[104X1285[4X[28X[128X[104X1286[4X[32X[104X12871288[1X2.8-9 Loops[101X12891290[29X[2XLoops[102X( [3Xf[103X ) [32X attribute1291[6XReturns:[106X [33X[0;10Yif [3Xf[103X is bijective, the list of non-isolated vertices of the1292transition graph of [3Xf[103X for modulus [10XMod([3Xf[103X[10X)[110X which carry a loop. In1293general, the list of vertices of that transition graph which carry1294a loop, but which [3Xf[103X does not fix setwise.[133X12951296[33X[0;0YThe returned list may also include supersets of the named residue classes1297instead if [3Xf[103X is affine even on these.[133X12981299[4X[32X Example [32X[104X1300[4X[28X[128X[104X1301[4X[25Xgap>[125X [27XLoops(ClassTransposition(0,2,1,2)*ClassTransposition(0,2,1,4));[127X[104X1302[4X[28X[ 0(4), 1(4) ][128X[104X1303[4X[28X[128X[104X1304[4X[32X[104X13051306[33X[0;0YThere is a nice invariant of trajectories of the Collatz mapping:[133X13071308[1X2.8-10 GluckTaylorInvariant[101X13091310[29X[2XGluckTaylorInvariant[102X( [3Xa[103X ) [32X function1311[6XReturns:[106X [33X[0;10Ythe invariant defined in [GT02]. This is [22X(∑_i=1^l a_i ⋅ a_i mod l1312+ 1)/(∑_i=1^l a_i^2)[122X, where [22Xl[122X denotes the length of [3Xa[103X.[133X13131314[33X[0;0YThe argument [3Xa[103X must be a list of integers. In [GT02] it is shown that if [3Xa[103X1315is a trajectory of the `original' Collatz mapping [22Xn[122X [22X↦[122X ([22Xn/2[122X if [22Xn[122X even, [22X3n+1[122X1316if [22Xn[122X odd) starting at an odd integer [22X≥ 3[122X and ending at 1, then the invariant1317lies in the interval [22X]9/13,5/7[[122X.[133X13181319[4X[32X Example [32X[104X1320[4X[28X[128X[104X1321[4X[25Xgap>[125X [27XC := RcwaMapping([[1,0,2],[3,1,1]]);;[127X[104X1322[4X[25Xgap>[125X [27XList([3,5..49],n->Float(GluckTaylorInvariant(Trajectory(C,n,[1]))));[127X[104X1323[4X[28X[ 0.701053, 0.696721, 0.708528, 0.707684, 0.706635, 0.695636, 0.711769,[128X[104X1324[4X[28X 0.699714, 0.707409, 0.693833, 0.710432, 0.706294, 0.714242, 0.699935,[128X[104X1325[4X[28X 0.714242, 0.705383, 0.706591, 0.698198, 0.712222, 0.714242, 0.709048,[128X[104X1326[4X[28X 0.69612, 0.714241, 0.701076 ][128X[104X1327[4X[28X[128X[104X1328[4X[32X[104X13291330[33X[0;0YQuite often one can make certain [21Xeducated guesses[121X on the overall behaviour1331of the trajectories of a given rcwa mapping. For example it is reasonably1332straightforward to make the conjecture that all trajectories of the Collatz1333mapping eventually enter the finite set [22X{-136, -91, -82, -68, -61, -55, -41,1334-37, -34, -25, -17, -10, -7, -5, -1, 0, 1, 2 }[122X, or that [21Xon average[121X the next1335number in a trajectory of the Collatz mapping is smaller than the preceding1336one by a factor of [22Xsqrt3/2[122X. However it is clear that such guesses can be1337wrong, and that they therefore cannot be used to prove anything.1338Nevertheless they can sometimes be useful:[133X13391340[1X2.8-11 LikelyContractionCentre[101X13411342[29X[2XLikelyContractionCentre[102X( [3Xf[103X, [3Xmaxn[103X, [3Xbound[103X ) [32X operation1343[6XReturns:[106X [33X[0;10Ya list of ring elements (see below).[133X13441345[33X[0;0YThis operation tries to compute the [13Xcontraction centre[113X of the rcwa mapping1346[3Xf[103X. Assuming its existence this is the unique finite subset [22XS_0[122X of the source1347of [3Xf[103X on which [3Xf[103X induces a permutation and which intersects non-trivially1348with any trajectory of [3Xf[103X. The mapping [3Xf[103X is assumed to be [13Xcontracting[113X, i.e.1349to have such a contraction centre. As in general contraction centres are1350likely not computable, the methods for this operation are probabilistic and1351may return wrong results. The argument [3Xmaxn[103X is a bound on the starting value1352and [3Xbound[103X is a bound on the elements of the trajectories to be searched. If1353the limit [3Xbound[103X is exceeded, an Info message on Info level 3 of [10XInfoRCWA[110X is1354given.[133X13551356[4X[32X Example [32X[104X1357[4X[28X[128X[104X1358[4X[25Xgap>[125X [27XT := RcwaMapping([[1,0,2],[3,1,2]]);; # The Collatz mapping.[127X[104X1359[4X[25Xgap>[125X [27XS0 := LikelyContractionCentre(T,100,1000);[127X[104X1360[4X[28X#I Warning: `LikelyContractionCentre' is highly probabilistic.[128X[104X1361[4X[28XThe returned result can only be regarded as a rough guess.[128X[104X1362[4X[28XSee ?LikelyContractionCentre for more information.[128X[104X1363[4X[28X[ -136, -91, -82, -68, -61, -55, -41, -37, -34, -25, -17, -10, -7, -5, [128X[104X1364[4X[28X -1, 0, 1, 2 ][128X[104X1365[4X[28X[128X[104X1366[4X[32X[104X13671368[1X2.8-12 GuessedDivergence[101X13691370[29X[2XGuessedDivergence[102X( [3Xf[103X ) [32X operation1371[6XReturns:[106X [33X[0;10Ya floating point value which is intended to be a rough guess on1372how fast the trajectories of the rcwa mapping [3Xf[103X diverge (return1373value greater than 1) or converge (return value smaller than 1).[133X13741375[33X[0;0YNothing particular is guaranteed.[133X13761377[4X[32X Example [32X[104X1378[4X[28X[128X[104X1379[4X[25Xgap>[125X [27XGuessedDivergence(T);[127X[104X1380[4X[28X#I Warning: GuessedDivergence: no particular return value is guaranteed.[128X[104X1381[4X[28X0.866025[128X[104X1382[4X[28X[128X[104X1383[4X[32X[104X138413851386[1X2.9 [33X[0;0YSaving memory -- the sparse representation of rcwa mappings[133X[101X13871388[33X[0;0YIt is quite common that an rcwa mapping with large modulus has only few1389distinct affine partial mappings. In this case the [21Xstandard[121X representation1390which stores a coefficient triple for each residue class modulo the modulus1391is unsuitable. For this reason there is a second representation of rcwa1392mappings, the [21Xsparse[121X representation. Depending on the rcwa mappings1393involved, using this representation may speed up computations and reduce1394memory requirements by orders of magnitude. For rcwa mappings with almost as1395many distinct affine partial mappings as there are residue classes modulo1396the modulus, using sparse representation makes computations slower and more1397memory-consuming. Presently, the sparse representation is only available for1398rcwa mappings of ℤ.[133X13991400[33X[0;0YThe sparse representation of an rcwa mapping consists of the modulus and a1401list of 5-tuples [22X(r,m,a_r(m),b_r(m),c_r(m))[122X of integers. Any such 5-tuple1402specifies the coefficients of the restriction [22Xn ↦ (a_r(m) ⋅ n +1403b_r(m))/c_r(m)[122X of the mapping to a residue class [22Xr(m)[122X. The [22Xr(m)[122X are chosen1404to form the coarsest possible partition of ℤ into residue classes such that1405the restriction of the mapping to any of them is affine. Also the list of1406coefficient tuples is sorted, all [22Xc_r(m)[122X are positive and1407[22Xgcd(c_r(m),gcd(a_r(m),b_r(m))) = 1[122X. This way the coefficient list of an rcwa1408mapping of ℤ is unique.[133X14091410[33X[0;0YChanging the representation of rcwa mappings does not change their behaviour1411with respect to [21X[10X=[110X[121X and [21X[10X<[110X[121X The product of two rcwa mappings in sparse1412representation is in sparse representation again, just like the product of1413two rcwa mappings in standard representation is in standard representation.1414Also, inverses are in the same representation. The product of two rcwa1415mappings in different representation may be in any of the representations of1416the factors.[133X14171418[1X2.9-1 SparseRepresentation[101X14191420[29X[2XSparseRepresentation[102X( [3Xf[103X ) [32X operation1421[29X[2XSparseRep[102X( [3Xf[103X ) [32X operation1422[29X[2XStandardRepresentation[102X( [3Xf[103X ) [32X operation1423[29X[2XStandardRep[102X( [3Xf[103X ) [32X operation1424[6XReturns:[106X [33X[0;10Ythe rcwa mapping [3Xf[103X in sparse, respectively, standard1425representation.[133X14261427[33X[0;0YAppropriate attribute values and properties are copied over to the rcwa1428mapping in the [21Xnew[121X representation.[133X14291430[4X[32X Example [32X[104X1431[4X[28X[128X[104X1432[4X[25Xgap>[125X [27Xa := ClassTransposition(1,2,4,6);[127X[104X1433[4X[28X( 1(2), 4(6) )[128X[104X1434[4X[25Xgap>[125X [27Xb := ClassTransposition(1,3,2,6);[127X[104X1435[4X[28X( 1(3), 2(6) )[128X[104X1436[4X[25Xgap>[125X [27Xc := ClassTransposition(2,3,4,6);[127X[104X1437[4X[28X( 2(3), 4(6) )[128X[104X1438[4X[25Xgap>[125X [27Xg := (b*a*c)^2*a;[127X[104X1439[4X[28X<rcwa permutation of Z with modulus 288>[128X[104X1440[4X[25Xgap>[125X [27Xh := SparseRep(g);[127X[104X1441[4X[28X<rcwa permutation of Z with modulus 288 and 21 affine parts>[128X[104X1442[4X[25Xgap>[125X [27Xg = h;[127X[104X1443[4X[28Xtrue[128X[104X1444[4X[25Xgap>[125X [27XCoefficients(h);[127X[104X1445[4X[28X[ [ 0, 6, 1, 0, 1 ], [ 1, 3, 16, -1, 3 ], [ 2, 96, 9, 14, 16 ], [128X[104X1446[4X[28X [ 3, 24, 9, 5, 4 ], [ 5, 24, 3, 1, 4 ], [ 8, 36, 2, -7, 9 ], [128X[104X1447[4X[28X [ 9, 48, 27, 29, 8 ], [ 11, 24, 9, 5, 4 ], [ 14, 48, 27, 38, 8 ], [128X[104X1448[4X[28X [ 15, 24, 27, 19, 4 ], [ 17, 48, 9, 7, 8 ], [ 20, 72, 3, 4, 4 ], [128X[104X1449[4X[28X [ 21, 24, 1, -3, 6 ], [ 23, 24, 27, 19, 4 ], [ 26, 48, 3, 2, 8 ], [128X[104X1450[4X[28X [ 32, 36, 4, -11, 9 ], [ 33, 48, 9, 7, 8 ], [ 38, 48, 9, 10, 8 ], [128X[104X1451[4X[28X [ 41, 48, 27, 29, 8 ], [ 50, 96, 27, 58, 16 ], [ 56, 72, 1, 0, 4 ] ][128X[104X1452[4X[25Xgap>[125X [27Xh^2;[127X[104X1453[4X[28X<rcwa permutation of Z with modulus 13824 and 71 affine parts>[128X[104X1454[4X[25Xgap>[125X [27Xh^3;[127X[104X1455[4X[28X<rcwa permutation of Z with modulus 663552 and 201 affine parts>[128X[104X1456[4X[28X[128X[104X1457[4X[32X[104X14581459[33X[0;0YMemory consumption may differ a lot between sparse- and standard1460representation:[133X14611462[4X[32X Example [32X[104X1463[4X[25Xgap>[125X [27XMemoryUsage(h^3); # on a 64-bit machine[127X[104X1464[4X[28X18254[128X[104X1465[4X[25Xgap>[125X [27XMemoryUsage(StandardRep(h^3)); # on a 64-bit machine[127X[104X1466[4X[28X42467894[128X[104X1467[4X[32X[104X146814691470[1X2.10 [33X[0;0YThe categories and families of rcwa mappings[133X[101X14711472[1X2.10-1 IsRcwaMapping[101X14731474[29X[2XIsRcwaMapping[102X( [3Xf[103X ) [32X filter1475[29X[2XIsRcwaMappingOfZ[102X( [3Xf[103X ) [32X filter1476[29X[2XIsRcwaMappingOfZ_pi[102X( [3Xf[103X ) [32X filter1477[29X[2XIsRcwaMappingOfGFqx[102X( [3Xf[103X ) [32X filter1478[6XReturns:[106X [33X[0;10Y[10Xtrue[110X if [3Xf[103X is an rcwa mapping, an rcwa mapping of the ring of1479integers, an rcwa mapping of a semilocalization of the ring of1480integers or an rcwa mapping of a polynomial ring in one variable1481over a finite field, respectively, and [10Xfalse[110X otherwise.[133X14821483[33X[0;0YOften the same methods can be used for rcwa mappings of the ring of integers1484and of its semilocalizations. For this reason there is a category1485[10XIsRcwaMappingOfZOrZ_pi[110X which is the union of [10XIsRcwaMappingOfZ[110X and1486[10XIsRcwaMappingOfZ_pi[110X. The internal representation of rcwa mappings is called1487[10XIsRcwaMappingStandardRep[110X. There are methods available for [10XExtRepOfObj[110X and1488[10XObjByExtRep[110X.[133X14891490[1X2.10-2 RcwaMappingsFamily[101X14911492[29X[2XRcwaMappingsFamily[102X( [3XR[103X ) [32X function1493[6XReturns:[106X [33X[0;10Ythe family of rcwa mappings of the ring [3XR[103X.[133X1494149514961497