[1X2. Residue-Class-Wise Affine Mappings[0X In this chapter we give the basic definitions, and describe how to enter residue-class-wise affine mappings and how to compute with them. How to compute with residue-class-wise affine groups is described in detail in the next chapter. The reader is encouraged to look there already after having read the first few pages of this chapter, and to look up definitions as he needs to. [1X2.1 Basic definitions[0X Residue-class-wise affine groups, or [13Xrcwa[0X groups for short, are permutation groups whose elements are bijective residue-class-wise affine mappings. A mapping f: Z -> Z is called [13Xresidue-class-wise affine[0X, or for short an [13Xrcwa[0X mapping, if there is a positive integer m such that the restrictions of f to the residue classes r(m) in Z/mZ are all affine, i.e. given by a_r(m) * n + b_r(m) f|_r(m): r(m) -> Z, n |-> ------------------- c_r(m) for certain coefficients a_r(m), b_r(m), c_r(m) in Z depending on r(m). The smallest possible m is called the [13Xmodulus[0X of f. It is understood that all fractions are reduced, i.e. that gcd( a_r(m), b_r(m), c_r(m) ) = 1, and that c_r(m) > 0. The lcm of the coefficients a_r(m) is called the [13Xmultiplier[0X of f, and the lcm of the coefficients c_r(m) is called the [13Xdivisor[0X of f. It is easy to see that the residue-class-wise affine mappings of Z form a monoid under composition, and that the residue-class-wise affine permutations of Z form a countable subgroup of Sym(Z). We denote the former by Rcwa(Z), and the latter by RCWA(Z). An rcwa mapping is called [13Xtame[0X if the set of moduli of its powers is bounded, or equivalently if it permutes a partition of Z into finitely many residue classes on all of which it is affine. An rcwa group is called [13Xtame[0X if there is a common such partition for all of its elements, or equivalently if the set of moduli of its elements is bounded. Rcwa mappings and -groups which are not tame are called [13Xwild[0X. Tame rcwa mappings and -groups are something which one could call the "trivial cases" or "basic building blocks", while wild rcwa groups are the objects of primary interest. The definitions of residue-class-wise affine mappings and -groups can be generalized in an obvious way to suitable rings other than Z. In fact, this package provides also some support for residue-class-wise affine groups over semilocalizations of Z and over univariate polynomial rings over finite fields. The former of these rings have been chosen as examples of rings with only finitely prime elements, and the latter have been chosen as examples of rings with nonzero characteristic. [1X2.2 Entering residue-class-wise affine mappings[0X Entering an rcwa mapping of Z requires giving the modulus m and the coefficients a_r(m), b_r(m) and c_r(m) for r(m) running over the residue classes (mod m). This can be done easiest by [10XRcwaMapping( [3Xcoeffs[0X )[0X, where [3Xcoeffs[0X is a list of m coefficient triples [10Xcoeffs[[0Xr+1[10X] = [[0Xa_r(m), b_r(m), c_r(m)[10X][0X, with r running from 0 to m-1. If some coefficient c_r(m) is zero or if images of some integers under the mapping to be defined would not be integers, an error message is printed and a break loop is entered. For example, the coefficient triple [10X[1,4,3][0X is not allowed at the first position. The reason for this is that not all integers congruent to 1 * 0 + 4 = 4 mod m are divisible by 3. For the general constructor for rcwa mappings, see [2XRcwaMapping[0X ([14X2.2-5[0X). [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> T := RcwaMapping([[1,0,2],[3,1,2]]); # The Collatz mapping.[0X [4X<rcwa mapping of Z with modulus 2>[0X [4Xgap> [ IsSurjective(T), IsInjective(T) ];[0X [4X[ true, false ][0X [4Xgap> SetName(T,"T"); Display(T);[0X [4X[0X [4XSurjective rcwa mapping of Z with modulus 2[0X [4X[0X [4X n mod 2 | n^T[0X [4X------------------------------------+------------------------------------[0X [4X 0 | n/2[0X [4X 1 | (3n + 1)/2[0X [4X[0X [4Xgap> a := RcwaMapping([[2,0,3],[4,-1,3],[4,1,3]]); SetName(a,"a");[0X [4X<rcwa mapping of Z with modulus 3>[0X [4Xgap> IsBijective(a);[0X [4Xtrue[0X [4Xgap> Display(a); # This is Collatz' permutation:[0X [4X[0X [4XBijective rcwa mapping of Z with modulus 3[0X [4X[0X [4X n mod 3 | n^a[0X [4X------------------------------------+------------------------------------[0X [4X 0 | 2n/3[0X [4X 1 | (4n - 1)/3[0X [4X 2 | (4n + 1)/3[0X [4X[0X [4Xgap> Support(a);[0X [4XZ \ [ -1, 0, 1 ][0X [4Xgap> Cycle(a,44);[0X [4X[ 44, 59, 79, 105, 70, 93, 62, 83, 111, 74, 99, 66 ][0X [4X[0X [4X------------------------------------------------------------------[0X There is computational evidence for the conjecture that any residue-class-wise affine permutation of Z can be factored into members of the following three series of permutations of particularly simple structure (cf. [2XFactorizationIntoCSCRCT[0X ([14X2.5-1[0X)): [1X2.2-1 ClassShift[0X [2X> ClassShift( [0X[3Xr, m[0X[2X ) _______________________________________________[0Xfunction [2X> ClassShift( [0X[3Xcl[0X[2X ) _________________________________________________[0Xfunction [6XReturns:[0X The class shift nu_r(m). The [13Xclass shift[0X nu_r(m) is the rcwa mapping of Z which maps n in r(m) to n + m and which fixes Z \ r(m) pointwise. In the one-argument form, the argument [3Xcl[0X stands for the residue class r(m). Enclosing the argument list in list brackets is permitted. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> Display(ClassShift(5,12));[0X [4X[0X [4XTame bijective rcwa mapping of Z with modulus 12, of order infinity[0X [4X[0X [4X n mod 12 | n^ClassShift(5,12)[0X [4X------------------------------------+------------------------------------[0X [4X 0 1 2 3 4 6 7 8 9 10 11 | n[0X [4X 5 | n + 12[0X [4X[0X [4X[0X [4X------------------------------------------------------------------[0X [1X2.2-2 ClassReflection[0X [2X> ClassReflection( [0X[3Xr, m[0X[2X ) __________________________________________[0Xfunction [2X> ClassReflection( [0X[3Xcl[0X[2X ) ____________________________________________[0Xfunction [6XReturns:[0X The class reflection varsigma_r(m). The [13Xclass reflection[0X varsigma_r(m) is the rcwa mapping of Z which maps n in r(m) to -n + 2r and which fixes Z \ r(m) pointwise, where it is understood that 0 <= r < m. In the one-argument form, the argument [3Xcl[0X stands for the residue class r(m). Enclosing the argument list in list brackets is permitted. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> Display(ClassReflection(5,9));[0X [4X[0X [4XBijective rcwa mapping of Z with modulus 9, of order 2[0X [4X[0X [4X n mod 9 | n^ClassReflection(5,9)[0X [4X------------------------------------+------------------------------------[0X [4X 0 1 2 3 4 6 7 8 | n[0X [4X 5 | -n + 10[0X [4X[0X [4X[0X [4X------------------------------------------------------------------[0X [1X2.2-3 ClassTransposition[0X [2X> ClassTransposition( [0X[3Xr1, m1, r2, m2[0X[2X ) _____________________________[0Xfunction [2X> ClassTransposition( [0X[3Xcl1, cl2[0X[2X ) ___________________________________[0Xfunction [6XReturns:[0X The class transposition tau_r_1(m_1),r_2(m_2). Given two disjoint residue classes r_1(m_1) and r_2(m_2) of the integers, the [13Xclass transposition[0X tau_r_1(m_1),r_2(m_2) in RCWA(Z) is defined as the involution which interchanges r_1+km_1 and r_2+km_2 for any integer k and which fixes all other points. It is understood that m_1 and m_2 are positive, that 0 <= r_1 < m_1 and that 0 <= r_2 < m_2. For a [13Xgeneralized class transposition[0X, the latter assumptions are not made. The class transposition tau_r_1(m_1),r_2(m_2) interchanges the residue classes r_1(m_1) and r_2(m_2) and fixes the complement of their union pointwise. In the four-argument form, the arguments [3Xr1[0X, [3Xm1[0X, [3Xr2[0X and [3Xm2[0X stand for r_1, m_1, r_2 and m_2, respectively. In the two-argument form, the arguments [3Xcl1[0X and [3Xcl2[0X stand for the residue classes r_1(m_1) and r_2(m_2), respectively. Enclosing the argument list in list brackets is permitted. The residue classes r_1(m_1) and r_2(m_2) are stored as an attribute [10XTransposedClasses[0X. A class transposition can be written as a product of any given number k of class transpositions. Such a decomposition can be obtained by [10XSplittedClassTransposition([3Xct[0X,[3Xk[0X)[0X. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> Display(ClassTransposition(1,2,8,10));[0X [4X[0X [4XBijective rcwa mapping of Z with modulus 10, of order 2[0X [4X[0X [4X n mod 10 | n^ClassTransposition(1,2,8,10)[0X [4X------------------------------------+------------------------------------[0X [4X 0 2 4 6 | n[0X [4X 1 3 5 7 9 | 5n + 3[0X [4X 8 | (n - 3)/5[0X [4X[0X [4X[0X [4X------------------------------------------------------------------[0X The set of all class transpositions of the ring of integers generates the simple group CT(Z) mentioned in Chapter [14X1.[0X. This group has a representation as a [5XGAP[0X object -- see [2XCT[0X ([14X3.1-2[0X). The set of all generalized class transpositions of Z generates a simple group as well, cf. [Koh06a]. Class shifts, class reflections and class transpositions of rings R other than Z are defined in an entirely analogous way -- all one needs to do is to replace Z by R and to read < and <= in the sense of the ordering used by [5XGAP[0X. They can also be entered basically as described above -- just prepend the desired ring R to the argument list. Often also a sensible "default ring" (-> [10XDefaultRing[0X in the [5XGAP[0X Reference Manual) is chosen if that optional first argument is omitted. On rings which have more than two units, there is another basic series of rcwa permutations which generalizes class reflections: [1X2.2-4 ClassRotation[0X [2X> ClassRotation( [0X[3Xr, m, u[0X[2X ) _________________________________________[0Xfunction [2X> ClassRotation( [0X[3Xcl, u[0X[2X ) ___________________________________________[0Xfunction [6XReturns:[0X The class rotation rho_r(m),u. Given a residue class r(m) and a unit u of a suitable ring R, the [13Xclass rotation[0X rho_r(m),u is the rcwa mapping which maps n in r(m) to un + (1-u)r and which fixes R \ r(m) pointwise. Class rotations generalize class reflections, as we have rho_r(m),-1 = varsigma_r(m). In the two-argument form, the argument [3Xcl[0X stands for the residue class r(m). Enclosing the argument list in list brackets is permitted. The argument [3Xu[0X is stored as an attribute [10XRotationFactor[0X. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> Display(ClassRotation(ResidueClass(Z_pi(2),2,1),1/3));[0X [4X[0X [4XTame bijective rcwa mapping of Z_( 2 ) with modulus 2, of order infinity[0X [4X[0X [4X n mod 2 | n^ClassRotation(1,2,1/3)[0X [4X------------------------------------+------------------------------------[0X [4X 0 | n[0X [4X 1 | 1/3 n + 2/3[0X [4X[0X [4Xgap> x := Indeterminate(GF(8),1);; SetName(x,"x");[0X [4Xgap> R := PolynomialRing(GF(8),1);;[0X [4Xgap> Display(ClassRotation(1,x,Z(8)*One(R)));[0X [4X[0X [4XBijective rcwa mapping of GF(2^3)[x] with modulus x, of order 7[0X [4X[0X [4X P mod x | P^(ClassRotation(Z(2)^0,x,Z(2^3)))[0X [4X------------------------+------------------------------------------------[0X [4X 0*Z(2) Z(2^3) |[0X [4X Z(2^3)^2 Z(2^3)^3 |[0X [4X Z(2^3)^4 Z(2^3)^5 |[0X [4X Z(2^3)^6 | P[0X [4X Z(2)^0 | Z(2^3)*P + Z(2^3)^3[0X [4X[0X [4X[0X [4X------------------------------------------------------------------[0X There are properties [10XIsClassShift[0X, [10XIsClassReflection[0X, [10XIsClassRotation[0X, [10XIsClassTransposition[0X and [10XIsGeneralizedClassTransposition[0X, which indicate whether a given rcwa mapping belongs to the corresponding series. By default, class shifts, class reflections, class transpositions and class rotations are given descriptive names of the form [10XClass...(...)[0X. They can be given user-defined names upon creation via the option [10XName[0X. Setting the [10XName[0X attribute can be avoided by passing the empty string. In the sequel, a description of the general-purpose constructor for rcwa mappings is given. This might look a bit technical on a first glance, but knowing all possible ways of entering an rcwa mapping is by no means necessary for understanding this manual or for using this package. [1X2.2-5 RcwaMapping (the general constructor)[0X [2X> RcwaMapping( [0X[3XR, m, coeffs[0X[2X ) ________________________________________[0Xmethod [2X> RcwaMapping( [0X[3XR, coeffs[0X[2X ) ___________________________________________[0Xmethod [2X> RcwaMapping( [0X[3Xcoeffs[0X[2X ) ______________________________________________[0Xmethod [2X> RcwaMapping( [0X[3Xperm, range[0X[2X ) _________________________________________[0Xmethod [2X> RcwaMapping( [0X[3Xm, values[0X[2X ) ___________________________________________[0Xmethod [2X> RcwaMapping( [0X[3Xpi, coeffs[0X[2X ) __________________________________________[0Xmethod [2X> RcwaMapping( [0X[3Xq, m, coeffs[0X[2X ) ________________________________________[0Xmethod [2X> RcwaMapping( [0X[3XP1, P2[0X[2X ) ______________________________________________[0Xmethod [2X> RcwaMapping( [0X[3Xcycles[0X[2X ) ______________________________________________[0Xmethod [6XReturns:[0X An rcwa mapping. In all cases the argument [3XR[0X is the underlying ring, [3Xm[0X is the modulus and [3Xcoeffs[0X is the coefficient list. A coefficient list for an rcwa mapping with modulus m consists of |R/mR| coefficient triples [10X[[0Xa_r(m), b_r(m), c_r(m)[10X][0X. Their ordering is determined by the ordering of the representatives of the residue classes (mod m) in the sorted list returned by [10XAllResidues([3XR[0X, [3Xm[0X)[0X. In case R = Z this means that the coefficient triple for the residue class 0(m) comes first and is followed by the one for 1(m), the one for 2(m) and so on. In case one or several of the arguments [3XR[0X, [3Xm[0X and [3Xcoeffs[0X are omitted or replaced by other arguments, the former are either derived from the latter or default values are taken. The meaning of the other arguments is defined in the detailed description of the particular methods given in the sequel: The above methods return the rcwa mapping [8X(a)[0X of [3XR[0X with modulus [3Xm[0X and coefficients [3Xcoeffs[0X, [8X(b)[0X of [3XR[0X = Z or [3XR[0X = Z_(pi) with modulus [10XLength([3Xcoeffs[0X)[0X and coefficients [3Xcoeffs[0X, [8X(c)[0X of [3XR[0X = Z with modulus [10XLength([3Xcoeffs[0X)[0X and coefficients [3Xcoeffs[0X, [8X(d)[0X of [3XR[0X = Z, permuting any set [10X[3Xrange[0X+k*Length([3Xrange[0X)[0X like [3Xperm[0X permutes [3Xrange[0X, [8X(e)[0X of [3XR[0X = Z with modulus [3Xm[0X and values given by a list [3Xval[0X of 2 pairs [10X[[0Xpreimage[10X, [0Ximage[10X][0X per residue class (mod [3Xm[0X), [8X(f)[0X of [3XR[0X = Z_(pi) with modulus [10XLength([3Xcoeffs[0X)[0X and coefficients [3Xcoeffs[0X (the set of primes pi which denotes the underlying ring is passed as argument [3Xpi[0X), [8X(g)[0X of [3XR[0X = GF([3Xq[0X)[[3Xx[0X] with modulus [3Xm[0X and coefficients [3Xcoeffs[0X, [8X(h)[0X a bijective rcwa mapping which induces a bijection between the partitions [3XP1[0X and [3XP2[0X of [3XR[0X into residue classes and which is affine on the elements of [3XP1[0X, or [8X(i)[0X a bijective rcwa mapping with "residue class cycles" given by a list [3Xcycles[0X of lists of pairwise disjoint residue classes which are to be permuted cyclically, each, respectively. The methods for the operation [10XRcwaMapping[0X perform a number of argument checks, which can be skipped by using [10XRcwaMappingNC[0X instead. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> R := PolynomialRing(GF(2),1);; x := X(GF(2),1);; SetName(x,"x");[0X [4Xgap> RcwaMapping(R,x+1,[[1,0,x+One(R)],[x+One(R),0,1]]*One(R)); # (a)[0X [4X<rcwa mapping of GF(2)[x] with modulus x+Z(2)^0>[0X [4Xgap> RcwaMapping(Z_pi(2),[[1/3,0,1]]); # (b)[0X [4XRcwa mapping of Z_( 2 ): n -> 1/3 n[0X [4Xgap> a := RcwaMapping([[2,0,3],[4,-1,3],[4,1,3]]); # (c)[0X [4X<rcwa mapping of Z with modulus 3>[0X [4Xgap> RcwaMapping((1,2,3),[1..4]); # (d)[0X [4X<bijective rcwa mapping of Z with modulus 4, of order 3>[0X [4Xgap> T = RcwaMapping(2,[[1,2],[2,1],[3,5],[4,2]]); # (e)[0X [4Xtrue[0X [4Xgap> RcwaMapping([2],[[1/3,0,1]]); # (f)[0X [4XRcwa mapping of Z_( 2 ): n -> 1/3 n[0X [4Xgap> RcwaMapping(2,x+1,[[1,0,x+One(R)],[x+One(R),0,1]]*One(R)); # (g)[0X [4X<rcwa mapping of GF(2)[x] with modulus x+Z(2)^0>[0X [4Xgap> a = RcwaMapping(List([[0,3],[1,3],[2,3]],ResidueClass),[0X [4X> List([[0,2],[1,4],[3,4]],ResidueClass)); # (h)[0X [4Xtrue[0X [4Xgap> RcwaMapping([List([[0,2],[1,4],[3,8],[7,16]],ResidueClass)]); # (i)[0X [4X<bijective rcwa mapping of Z with modulus 16, of order 4>[0X [4Xgap> Cycle(last,ResidueClass(0,2));[0X [4X[ 0(2), 1(4), 3(8), 7(16) ][0X [4X[0X [4X------------------------------------------------------------------[0X Rcwa mappings of Z can be "translated" to rcwa mappings of some semilocalization Z_(pi) of Z: [1X2.2-6 LocalizedRcwaMapping[0X [2X> LocalizedRcwaMapping( [0X[3Xf, p[0X[2X ) _____________________________________[0Xfunction [2X> SemilocalizedRcwaMapping( [0X[3Xf, pi[0X[2X ) ________________________________[0Xfunction [6XReturns:[0X The rcwa mapping of Z_(p) respectively Z_(pi) with the same coefficients as the rcwa mapping [3Xf[0X of Z. The argument [3Xp[0X or [3Xpi[0X must be a prime or a set of primes, respectively. The argument [3Xf[0X must be an rcwa mapping of Z whose modulus is a power of [3Xp[0X, or whose modulus has only prime divisors which lie in [3Xpi[0X, respectively. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> T := RcwaMapping([[1,0,2],[3,1,2]]);; # The Collatz mapping.[0X [4Xgap> Cycle(LocalizedRcwaMapping(T,2),131/13);[0X [4X[ 131/13, 203/13, 311/13, 473/13, 716/13, 358/13, 179/13, 275/13, [0X [4X 419/13, 635/13, 959/13, 1445/13, 2174/13, 1087/13, 1637/13, 2462/13, [0X [4X 1231/13, 1853/13, 2786/13, 1393/13, 2096/13, 1048/13, 524/13, 262/13 ][0X [4X[0X [4X------------------------------------------------------------------[0X Rcwa mappings can be [10XView[0Xed, [10XDisplay[0Xed, [10XPrint[0Xed and written to a [10XString[0X. The output of the [10XView[0X method is kept reasonably short. In most cases it does not describe an rcwa mapping completely. In these cases the output is enclosed in brackets. The output of the methods for [10XDisplay[0X and [10XPrint[0X describe an rcwa mapping in full. The [10XPrint[0Xed representation of an rcwa mapping is [5XGAP[0X - readable if and only if the [10XPrint[0Xed representation of the elements of the underlying ring is so. There is also a method for [10XLaTeX[0X, respectively [10XLaTeXObj[0X. The output of this method makes use of the LaTeX macro package [5Xamsmath[0X. If the option [3XFactorization[0X is set and the argument is bijective, a factorization into class shifts, class reflections, class transpositions and prime switches is printed (cf. [2XFactorizationIntoCSCRCT[0X ([14X2.5-1[0X)). For rcwa mappings with modulus greater than 1, an indentation by [3XIndentation[0X characters can be obtained by setting this option value accor\-dingly. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> Print(LaTeXObj(T));[0X [4Xn \ \longmapsto \[0X [4X\begin{cases}[0X [4X n/2 & \text{if} \ n \in 0(2), \\[0X [4X (3n + 1)/2 & \text{if} \ n \in 1(2).[0X [4X\end{cases}[0X [4X[0X [4X------------------------------------------------------------------[0X There is an operation [10XLaTeXAndXDVI[0X which displays an rcwa mapping in an [5Xxdvi[0X window. This works as follows: The string returned by the [10XLaTeXObj[0X - method described above is inserted into a LaTeX template file. This file is LaTeX'ed, and the result is shown with [5Xxdvi[0X. Calling [10XDisplay[0X with option [3Xxdvi[0X has the same effect. The operation [10XLaTeXAndXDVI[0X is only available on UNIX systems, and requires suitable installations of LaTeX and [5Xxdvi[0X. [1X2.3 Basic arithmetic for residue-class-wise affine mappings[0X Testing rcwa mappings for equality requires only comparing their coefficient lists, hence is cheap. Rcwa mappings can be multiplied, thus there is a method for [10X*[0X. Bijective rcwa mappings can also be inverted, thus there is a method for [10XInverse[0X. The latter method is usually accessed by raising a mapping to a power with negative exponent. Multiplying, inverting and computing powers of tame rcwa mappings is cheap. Computing powers of wild mappings is usually expensive -- runtime and memory requirements normally grow approximately exponentially with the exponent. How expensive multiplying a couple of wild mappings is, varies very much. In any case, the amount of memory required for storing an rcwa mapping is proportional to its modulus. Whether a given mapping is tame or wild can be determined by the operation [10XIsTame[0X. There is a method for [10XOrder[0X, which can not only compute a finite order, but which can also detect infinite order. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> T := RcwaMapping([[1,0,2],[3,1,2]]);; # The Collatz mapping.[0X [4Xgap> a := RcwaMapping([[2,0,3],[4,-1,3],[4,1,3]]);; # Collatz' permutation.[0X [4Xgap> List([-4..4],k->Modulus(a^k));[0X [4X[ 256, 64, 16, 4, 1, 3, 9, 27, 81 ][0X [4Xgap> IsTame(T) or IsTame(a);[0X [4Xfalse[0X [4Xgap> IsTame(ClassShift(0,1)) and IsTame(ClassTransposition(0,2,1,2));[0X [4Xtrue[0X [4Xgap> T^2*a*T*a^-3;[0X [4X<rcwa mapping of Z with modulus 768>[0X [4Xgap> (ClassShift(1,3)*ClassReflection(2,7))^1000000;[0X [4X<bijective rcwa mapping of Z with modulus 21>[0X [4X[0X [4X------------------------------------------------------------------[0X There are methods installed for [10XIsInjective[0X, [10XIsSurjective[0X, [10XIsBijective[0X and [10XImage[0X. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> [ IsInjective(T), IsSurjective(T), IsBijective(a) ];[0X [4X[ false, true, true ][0X [4Xgap> Image(RcwaMapping([[2,0,1]]));[0X [4X0(2)[0X [4X[0X [4X------------------------------------------------------------------[0X Images of elements, of finite sets of elements and of unions of finitely many residue classes of the source of an rcwa mapping can be computed with [10X^[0X, the same symbol as used for exponentiation and conjugation. The same works for partitions of the source into a finite number of residue classes. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> 15^T;[0X [4X23[0X [4Xgap> ResidueClass(1,2)^T;[0X [4X2(3)[0X [4Xgap> List([[0,3],[1,3],[2,3]],ResidueClass)^a;[0X [4X[ 0(2), 1(4), 3(4) ][0X [4X[0X [4X------------------------------------------------------------------[0X For computing preimages of elements under rcwa mappings, there are methods for [10XPreImageElm[0X and [10XPreImagesElm[0X. The preimage of a finite set of ring elements or of a union of finitely many residue classes under an rcwa mapping can be computed by [10XPreImage[0X. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> PreImagesElm(T,8);[0X [4X[ 5, 16 ][0X [4Xgap> PreImage(T,ResidueClass(Integers,3,2));[0X [4XZ \ 0(6) U 2(6)[0X [4Xgap> M := [1];; l := [1];;[0X [4Xgap> while Length(M) < 5000 do M := PreImage(T,M); Add(l,Length(M)); od; l;[0X [4X[ 1, 1, 2, 2, 4, 5, 8, 10, 14, 18, 26, 36, 50, 67, 89, 117, 157, 208, [0X [4X 277, 367, 488, 649, 869, 1154, 1534, 2039, 2721, 3629, 4843, 6458 ][0X [4X[0X [4X------------------------------------------------------------------[0X There is a method for the operation [10XSupport[0X for computing the support of an rcwa mapping. A synonym for [10XSupport[0X is [10XMovedPoints[0X. There is also a method for [10XRestrictedPerm[0X for computing the restriction of a bijective rcwa mapping to a union of residue classes which it fixes setwise. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> List([a,a^2],Support);[0X [4X[ Z \ [ -1, 0, 1 ], Z \ [ -3, -2, -1, 0, 1, 2, 3 ] ][0X [4Xgap> RestrictedPerm(ClassShift(0,2)*ClassReflection(1,2),[0X [4X> ResidueClass(0,2));[0X [4X<rcwa mapping of Z with modulus 2>[0X [4Xgap> last = ClassShift(0,2);[0X [4Xtrue[0X [4X[0X [4X------------------------------------------------------------------[0X Rcwa mappings can be added and subtracted pointwise. However, please note that the set of rcwa mappings of a ring does not form a ring under [10X+[0X and [10X*[0X. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> b := ClassShift(0,3) * a;;[0X [4Xgap> [ Image((a + b)), Image((a - b)) ];[0X [4X[ 2(4), [ -2, 0 ] ][0X [4X[0X [4X------------------------------------------------------------------[0X There are operations [10XModulus[0X (abbreviated [10XMod[0X) and [10XCoefficients[0X for retrieving the modulus and the coefficient list of an rcwa mapping. The meaning of the return values is as described in Section [14X2.2[0X. General documentation for most operations mentioned in this section can be found in the [5XGAP[0X reference manual. For rcwa mappings of rings other than Z, not for all operations applicable methods are available. As in general a subring relation R_1<R_2 does [13Xnot[0X give rise to a natural embedding of RCWA(R_1) into RCWA(R_2), there is no coercion between rcwa mappings or rcwa groups over different rings. [1X2.4 Attributes and properties of residue-class-wise affine mappings[0X A number of basic attributes and properties of an rcwa mapping are derived immediately from the coefficients of its affine partial mappings. This holds for example for the multiplier and the divisor. These two values are stored as attributes [10XMultiplier[0X and [10XDivisor[0X, or for short [10XMult[0X and [10XDiv[0X. The [13Xprime set[0X of an rcwa mapping is the set of prime divisors of the product of its modulus and its multiplier. It is stored as an attribute [10XPrimeSet[0X. An rcwa mapping is called [13Xintegral[0X if its divisor equals 1. An rcwa mapping is called [13Xbalanced[0X if its multiplier and its divisor have the same prime divisors. An integral mapping has the property [10XIsIntegral[0X and a balanced mapping has the property [10XIsBalanced[0X. An rcwa mapping of the ring of integers or of one of its semilocalizations is called [13Xclass-wise order-preserving[0X if and only if all coefficients a_r(m) (cf. Section [14X2.1[0X) in the numerators of the affine partial mappings are positive. The corresponding property is [10XIsClassWiseOrderPreserving[0X. An rcwa mapping of Z is called [13Xsign-preserving[0X if it does not map nonnegative integers to negative integers or vice versa. The corresponding property is [10XIsSignPreserving[0X. All elements of the simple group CT(Z) generated by the set of all class transpositions are sign-preserving. [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> IsBijective(u);; Display(u);[0X [4X[0X [4XBijective rcwa mapping of Z with modulus 5[0X [4X[0X [4X n mod 5 | n^f[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 [4Xgap> Multiplier(u);[0X [4X9[0X [4Xgap> Divisor(u);[0X [4X5[0X [4Xgap> PrimeSet(u);[0X [4X[ 3, 5 ][0X [4Xgap> IsIntegral(u) or IsBalanced(u);[0X [4Xfalse[0X [4Xgap> IsClassWiseOrderPreserving(u) and IsSignPreserving(u);[0X [4Xtrue[0X [4X[0X [4X------------------------------------------------------------------[0X There are a couple of further attributes and operations related to the affine partial mappings of an rcwa mapping: [1X2.4-1 LargestSourcesOfAffineMappings[0X [2X> LargestSourcesOfAffineMappings( [0X[3Xf[0X[2X ) _____________________________[0Xattribute [6XReturns:[0X The coarsest partition of [10XSource([3Xf[0X)[0X on whose elements the rcwa mapping [3Xf[0X is affine. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> LargestSourcesOfAffineMappings(ClassShift(3,7));[0X [4X[ Z \ 3(7), 3(7) ][0X [4Xgap> LargestSourcesOfAffineMappings(ClassReflection(0,1));[0X [4X[ Integers ][0X [4Xgap> u := RcwaMapping([[3,0,5],[9,1,5],[3,-1,5],[9,-2,5],[9,4,5]]);;[0X [4Xgap> List( [ u, u^-1 ], LargestSourcesOfAffineMappings );[0X [4X[ [ 0(5), 1(5), 2(5), 3(5), 4(5) ], [ 0(3), 1(3), 2(9), 5(9), 8(9) ] ][0X [4Xgap> kappa := ClassTransposition(2,4,3,4) * ClassTransposition(4,6,8,12)[0X [4X> * ClassTransposition(3,4,4,6);[0X [4X<bijective rcwa mapping of Z with modulus 12>[0X [4Xgap> LargestSourcesOfAffineMappings(kappa);[0X [4X[ 2(4), 1(4) U 0(12), 3(12) U 7(12), 4(12), 8(12), 11(12) ][0X [4X[0X [4X------------------------------------------------------------------[0X [1X2.4-2 FixedPointsOfAffinePartialMappings[0X [2X> FixedPointsOfAffinePartialMappings( [0X[3Xf[0X[2X ) _________________________[0Xattribute [6XReturns:[0X A list of the sets of fixed points of the affine partial mappings of the rcwa mapping [3Xf[0X in the quotient field of its source. The returned list contains entries for the restrictions of [3Xf[0X to all residue classes modulo [10XMod([3Xf[0X)[0X. A list entry can either be an empty set, the source of [3Xf[0X or a set of cardinality 1. The ordering of the entries corresponds to the ordering of the residues in [10XAllResidues(Source([3Xf[0X),[3Xm[0X)[0X. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> FixedPointsOfAffinePartialMappings(ClassShift(0,2));[0X [4X[ [ ], Rationals ][0X [4Xgap> List([1..3],k->FixedPointsOfAffinePartialMappings(T^k));[0X [4X[ [ [ 0 ], [ -1 ] ], [ [ 0 ], [ 1 ], [ 2 ], [ -1 ] ], [0X [4X [ [ 0 ], [ -7 ], [ 2/5 ], [ -5 ], [ 4/5 ], [ 1/5 ], [ -10 ], [ -1 ] ] ][0X [4X[0X [4X------------------------------------------------------------------[0X [1X2.4-3 Multpk[0X [2X> Multpk( [0X[3Xf, p, k[0X[2X ) _______________________________________________[0Xoperation [6XReturns:[0X The union of the residue classes r(m) such that p^k||a_r(m) if k >= 0, and the union of the residue classes r(m) such that p^k||c_r(m) if k <= 0. In this context, m denotes the modulus of [3Xf[0X, and a_r(m) and c_r(m) denote the coefficients of [3Xf[0X as introduced in Section [14X2.1[0X. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> T := RcwaMapping([[1,0,2],[3,1,2]]);; # The Collatz mapping.[0X [4Xgap> [ Multpk(T,2,-1), Multpk(T,3,1) ];[0X [4X[ Integers, 1(2) ][0X [4Xgap> u := RcwaMapping([[3,0,5],[9,1,5],[3,-1,5],[9,-2,5],[9,4,5]]);;[0X [4Xgap> [ Multpk(u,3,0), Multpk(u,3,1), Multpk(u,3,2), Multpk(u,5,-1) ];[0X [4X[ [ ], 0(5) U 2(5), Z \ 0(5) U 2(5), Integers ][0X [4X[0X [4X------------------------------------------------------------------[0X There are attributes [10XClassWiseOrderPreservingOn[0X, [10XClassWiseConstantOn[0X and [10XClassWiseOrderReversingOn[0X which store the union of the residue classes (mod [10XMod([3Xf[0X)[0X) on which an rcwa mapping [3Xf[0X of Z or of a semilocalization thereof is class-wise order-preserving, class-wise constant or class-wise order-reversing, respectively. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> List([ClassTransposition(1,2,0,4),ClassShift(2,3),[0X [4X> ClassReflection(2,5)],ClassWiseOrderPreservingOn);[0X [4X[ Integers, Integers, Z \ 2(5) ][0X [4X[0X [4X------------------------------------------------------------------[0X Finally, there are epimorphisms from the subgroup of RCWA(Z) formed by all class-wise order-preserving elements to (Z,+) and from RCWA(Z) itself to the cyclic group of order 2, respectively: [1X2.4-4 Determinant[0X [2X> Determinant( [0X[3Xf[0X[2X ) ___________________________________________________[0Xmethod [6XReturns:[0X The determinant of the rcwa mapping [3Xf[0X of Z. The [13Xdeterminant[0X of an affine mapping n -> (an+b)/c whose source is a residue class r(m) is defined by b/|a|m. This definition is extended additively to determinants of rcwa mappings. Let f be an rcwa mapping of the integers, and let m denote its modulus. Using the notation f|_r(m): n -> (a_r(m) * n + b_r(m))/c_r(m) for the affine partial mappings, the [13Xdeterminant[0X det(f) of f is given by ----- \ b_r(m) > -------------- / |a_{r(m)}| * m ----- r(m) in Z/mZ . The determinant mapping is an epimorphism from the group of all class-wise order-preserving bijective rcwa mappings of Z to (Z,+), see [Koh05], Theorem 2.11.9. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> List([ClassTransposition(0,4,5,12),ClassShift(3,7)],Determinant);[0X [4X[ 0, 1 ][0X [4Xgap> Determinant(ClassTransposition(0,4,5,12)*ClassShift(3,7)^100); [0X [4X100[0X [4X[0X [4X------------------------------------------------------------------[0X [1X2.4-5 Sign[0X [2X> Sign( [0X[3Xg[0X[2X ) _______________________________________________________[0Xattribute [6XReturns:[0X The sign of the bijective rcwa mapping [3Xg[0X of Z. Let sigma be an rcwa permutation of the integers, and let m denote its modulus. Using the notation sigma|_r(m): n -> (a_r(m) * n + b_r(m))/c_r(m) for the affine partial mappings, the [13Xsign[0X of sigma is defined by ----- \ m - 2r det(sigma) + > ------- / m ----- a_r(m) < 0 (-1) . The sign mapping is an epimorphism from RCWA(Z) to the group Z^x of units of Z, see [Koh05], Theorem 2.12.8. Therefore the kernel of the sign mapping is a normal subgroup of RCWA(Z) of index 2. The simple group CT(Z) is a subgroup of this kernel. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> List([ClassTransposition(3,4,2,6),[0X [4X> ClassShift(0,3),ClassReflection(2,5)],Sign);[0X [4X[ 1, -1, -1 ][0X [4X[0X [4X------------------------------------------------------------------[0X [1X2.5 Factoring residue-class-wise affine permutations[0X Factoring group elements into the members of some "nice" set of generators is often helpful. In this section we describe an operation which attempts to solve this problem for the group RCWA(Z). Elements of finitely generated rcwa groups can be factored into generators "as usual", see [2XPreImagesRepresentative[0X ([14X3.2-3[0X). [1X2.5-1 FactorizationIntoCSCRCT[0X [2X> FactorizationIntoCSCRCT( [0X[3Xg[0X[2X ) ____________________________________[0Xattribute [2X> Factorization( [0X[3Xg[0X[2X ) _________________________________________________[0Xmethod [6XReturns:[0X A factorization of the bijective rcwa mapping [3Xg[0X of Z into class shifts, class reflections and class transpositions, provided that such a factorization exists and the method finds it. The method may return [10Xfail[0X, stop with an error message or run into an infinite loop. If it returns a result, this result is always correct. The problem of obtaining a factorization as described is algorithmically difficult, and this factorization routine is currently perhaps the most sophisticated part of the [5XRCWA[0X package. Information about the progress of the factorization process can be obtained by setting the info level of the Info class [2XInfoRCWA[0X ([14X7.3-1[0X) to 2. By default, prime switches (-> [2XPrimeSwitch[0X ([14X2.5-2[0X)) are taken as one factor. If the option [3XExpandPrimeSwitches[0X is set, they are each decomposed into the 6 class transpositions given in the definition. By default, the factoring process begins with splitting off factors from the right. This can be changed by setting the option [3XDirection[0X to [10X"from the left"[0X. By default, a reasonably coarse respected partition of the integral mapping occuring in the final stage of the algorithm is computed. This can be suppressed by setting the option [3XShortenPartition[0X equal to [10Xfalse[0X. By default, at the end it is checked whether the product of the determined factors indeed equals [3Xg[0X. This check can be suppressed by setting the option [3XNC[0X. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> Factorization(Comm(ClassShift(0,3)*ClassReflection(1,2),[0X [4X> ClassShift(0,2)));[0X [4X[ ClassReflection(2,3), ClassShift(2,6)^-1, ClassTransposition(0,6,2,6), [0X [4X ClassTransposition(0,6,5,6) ][0X [4X[0X [4X------------------------------------------------------------------[0X For purposes of demonstrating the capabilities of the factorization routine, in Section [14X5.1[0X Collatz' permutation is factored. Lothar Collatz has investigated this permutation in 1932. Its cycle structure is unknown so far. The permutations of the following kind play an important role in factoring rcwa permutations of Z into class shifts, class reflections and class transpositions: [1X2.5-2 PrimeSwitch[0X [2X> PrimeSwitch( [0X[3Xp[0X[2X ) _________________________________________________[0Xfunction [2X> PrimeSwitch( [0X[3Xp, k[0X[2X ) ______________________________________________[0Xfunction [6XReturns:[0X In the one-argument form the [13Xprime switch[0X sigma_p := tau_0(8),1(2p) * tau_4(8),-1(2p) * tau_0(4),1(2p) * tau_2(4),-1(2p) * tau_2(2p),1(4p) * tau_4(2p),2p+1(4p), and in the two-argument form the restriction of sigma_p by n -> kn. For an odd prime p, the prime switch sigma_p is a bijective rcwa mapping of Z with modulus 4p, multiplier p and divisor 2. The key mathematical property of a prime switch is that it is a product of class transpositions, but that its multiplier and its divisor are coprime anyway. Prime switches can be distinguished from other rcwa mappings by their [5XGAP[0X property [10XIsPrimeSwitch[0X. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> Display(PrimeSwitch(3));[0X [4X[0X [4XWild bijective rcwa mapping of Z with modulus 12[0X [4X[0X [4X n mod 12 | n^PrimeSwitch(3)[0X [4X------------------------------------+------------------------------------[0X [4X 0 | n/2[0X [4X 1 7 | n + 1[0X [4X 2 6 10 | (3n + 4)/2[0X [4X 3 9 | n[0X [4X 4 | n - 3[0X [4X 5 8 11 | n - 1[0X [4X[0X [4Xgap> Factorization(PrimeSwitch(3));[0X [4X[ ClassTransposition(1,6,0,8), ClassTransposition(5,6,4,8), [0X [4X ClassTransposition(0,4,1,6), ClassTransposition(2,4,5,6), [0X [4X ClassTransposition(2,6,1,12), ClassTransposition(4,6,7,12) ][0X [4X[0X [4X------------------------------------------------------------------[0X Obtaining a factorization of a bijective rcwa mapping into class shifts, class reflections and class transpositions is particularly difficult if multiplier and divisor are coprime. A prototype of permutations which have this property has been introduced in a different context in [Kel99]: [1X2.5-3 mKnot[0X [2X> mKnot( [0X[3Xm[0X[2X ) _______________________________________________________[0Xfunction [6XReturns:[0X The permutation g_m as introduced in [Kel99]. The argument [3Xm[0X must be an odd integer greater than 1. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> Display(mKnot(5));[0X [4X[0X [4XWild bijective rcwa mapping of Z with modulus 5[0X [4X[0X [4X n mod 5 | n^mKnot(5)[0X [4X------------------------------------+------------------------------------[0X [4X 0 | 6n/5[0X [4X 1 | (4n + 1)/5[0X [4X 2 | (6n - 2)/5[0X [4X 3 | (4n + 3)/5[0X [4X 4 | (6n - 4)/5[0X [4X[0X [4X[0X [4X------------------------------------------------------------------[0X In his article, Timothy P. Keller shows that a permutation of this type cannot have infinitely many cycles of any given finite length. [1X2.6 Extracting roots of residue-class-wise affine mappings[0X [1X2.6-1 Root[0X [2X> Root( [0X[3Xf, k[0X[2X ) _______________________________________________________[0Xmethod [6XReturns:[0X An rcwa mapping [10Xg[0X such that [10Xg^[3Xk[0X=[3Xf[0X[0X, provided that such a mapping exists and that there is a method available which can determine it. Currently, extracting roots is implemented for rcwa permutations of finite order. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> Root(ClassTransposition(0,2,1,2),100);[0X [4X<bijective rcwa mapping of Z with modulus 8>[0X [4Xgap> Display(last);[0X [4X[0X [4XBijective rcwa mapping of Z with modulus 8[0X [4X[0X [4X n mod 8 | n^f[0X [4X------------------------------------+------------------------------------[0X [4X 0 1 2 3 4 5 | n + 2[0X [4X 6 | n - 5[0X [4X 7 | n - 7[0X [4X[0X [4Xgap> last^100 = ClassTransposition(0,2,1,2);[0X [4Xtrue[0X [4X[0X [4X------------------------------------------------------------------[0X [1X2.7 Special functions for non-bijective mappings[0X [1X2.7-1 RightInverse[0X [2X> RightInverse( [0X[3Xf[0X[2X ) _______________________________________________[0Xattribute [6XReturns:[0X A right inverse of the injective rcwa mapping [3Xf[0X, i.e. a mapping g such that [3Xf[0Xg = 1. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> twice := 2*IdentityRcwaMappingOfZ;[0X [4XRcwa mapping of Z: n -> 2n[0X [4Xgap> twice * RightInverse(twice);[0X [4XIdentityMapping( Integers )[0X [4X[0X [4X------------------------------------------------------------------[0X [1X2.7-2 CommonRightInverse[0X [2X> CommonRightInverse( [0X[3Xl, r[0X[2X ) ______________________________________[0Xoperation [6XReturns:[0X A mapping d such that [3Xl[0Xd = [3Xr[0Xd = 1. The mappings [3Xl[0X and [3Xr[0X must be injective, and their images must form a partition of their source. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> twice := 2*IdentityRcwaMappingOfZ; twiceplus1 := twice+1;[0X [4XRcwa mapping of Z: n -> 2n[0X [4XRcwa mapping of Z: n -> 2n + 1[0X [4Xgap> Display(CommonRightInverse(twice,twiceplus1));[0X [4X[0X [4XRcwa mapping of Z with modulus 2[0X [4X[0X [4X n mod 2 | n^f[0X [4X------------------------------------+------------------------------------[0X [4X 0 | n/2[0X [4X 1 | (n - 1)/2[0X [4X[0X [4X[0X [4X------------------------------------------------------------------[0X [1X2.7-3 ImageDensity[0X [2X> ImageDensity( [0X[3Xf[0X[2X ) _______________________________________________[0Xattribute [6XReturns:[0X The [13Ximage density[0X of the rcwa mapping [3Xf[0X. In the notation introduced in the definition of an rcwa mapping, the [13Ximage density[0X of an rcwa mapping f is defined by 1/m sum_r(m) in R/mR |R/c_r(m)R|/|R/a_r(m)R|. The image density of an injective rcwa mapping is <= 1, and the image density of a surjective rcwa mapping is >= 1 (this can be seen easily). Thus in particular the image density of a bijective rcwa mapping is 1. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> T := RcwaMapping([[1,0,2],[3,1,2]]);; # The Collatz mapping.[0X [4Xgap> List( [ T, ClassShift(0,1), RcwaMapping([[2,0,1]]) ], ImageDensity );[0X [4X[ 4/3, 1, 1/2 ][0X [4X[0X [4X------------------------------------------------------------------[0X Given an rcwa mapping [10Xf[0X, the function [10XInjectiveAsMappingFrom[0X returns a set [10XS[0X such that the restriction of [10Xf[0X to [10XS[0X is injective, and such that the image of [10XS[0X under [10Xf[0X is the entire image of [10Xf[0X. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> InjectiveAsMappingFrom(T);[0X [4X0(2)[0X [4X[0X [4X------------------------------------------------------------------[0X [1X2.8 On trajectories and cycles of residue-class-wise affine mappings[0X [5XRCWA[0X provides various methods to compute trajectories of rcwa mappings: [1X2.8-1 Trajectory (methods for rcwa mappings)[0X [2X> Trajectory( [0X[3Xf, n, length[0X[2X ) _________________________________________[0Xmethod [2X> Trajectory( [0X[3Xf, n, length, m[0X[2X ) ______________________________________[0Xmethod [2X> Trajectory( [0X[3Xf, n, terminal[0X[2X ) _______________________________________[0Xmethod [2X> Trajectory( [0X[3Xf, n, terminal, m[0X[2X ) ____________________________________[0Xmethod [6XReturns:[0X The first [3Xlength[0X iterates in the trajectory of the rcwa mapping [3Xf[0X starting at [3Xn[0X, respectively the initial part of the trajectory of the rcwa mapping [3Xf[0X starting at [3Xn[0X which ends at the first occurence of an iterate in the set [3Xterminal[0X. If the argument [3Xm[0X is given, the iterates are reduced (mod [3Xm[0X). To save memory when computing long trajectories containing huge iterates, the reduction (mod [3Xm[0X) is done each time before storing an iterate. In place of the ring element [3Xn[0X, the methods also accept a finite set of ring elements or a union of residue classes. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> T := RcwaMapping([[1,0,2],[3,1,2]]);; # The Collatz mapping.[0X [4Xgap> Trajectory(T,27,15); Trajectory(T,27,20,5);[0X [4X[ 27, 41, 62, 31, 47, 71, 107, 161, 242, 121, 182, 91, 137, 206, 103 ][0X [4X[ 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 0, 3, 0, 0, 3 ][0X [4Xgap> Trajectory(T,15,[1]); Trajectory(T,15,[1],2);[0X [4X[ 15, 23, 35, 53, 80, 40, 20, 10, 5, 8, 4, 2, 1 ][0X [4X[ 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1 ][0X [4Xgap> Trajectory(T,ResidueClass(Integers,3,0),Integers);[0X [4X[ 0(3), 0(3) U 5(9), 0(3) U 5(9) U 7(9) U 8(27), [0X [4X <union of 20 residue classes (mod 27)>, [0X [4X <union of 73 residue classes (mod 81)>, Z \ 10(81) U 37(81), Integers ][0X [4X[0X [4X------------------------------------------------------------------[0X [1X2.8-2 Trajectory (methods for rcwa mappings -- "accumulated coefficients")[0X [2X> Trajectory( [0X[3Xf, n, length, whichcoeffs[0X[2X ) ____________________________[0Xmethod [2X> Trajectory( [0X[3Xf, n, terminal, whichcoeffs[0X[2X ) __________________________[0Xmethod [6XReturns:[0X Either the list [10Xc[0X of triples of coprime coefficients such that for any [10Xk[0X it holds that [10X[3Xn[0X^([3Xf[0X^(k-1)) = (c[k][1]*[3Xn[0X + c[k][2])/c[k][3][0X or the last entry of that list, depending on whether [3Xwhichcoeffs[0X is [10X"AllCoeffs"[0X or [10X"LastCoeffs"[0X. The meanings of the arguments [3Xlength[0X and [3Xterminal[0X are the same as in the methods for the operation [10XTrajectory[0X described above. In general, computing only the last coefficient triple ([3Xwhichcoeffs[0X = [10X"LastCoeffs"[0X) needs considerably less memory than computing the entire list. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> Trajectory(T,27,[1],"LastCoeffs");[0X [4X[ 36472996377170786403, 195820718533800070543, 1180591620717411303424 ][0X [4Xgap> (last[1]*27+last[2])/last[3];[0X [4X1[0X [4X[0X [4X------------------------------------------------------------------[0X When dealing with problems like the 3n+1-Conjecture or when determining the degree of transitivity of the natural action of an rcwa group on its underlying ring, an important task is to determine the residue classes whose elements get larger or smaller when applying a given rcwa mapping: [1X2.8-3 IncreasingOn & DecreasingOn (for an rcwa mapping)[0X [2X> IncreasingOn( [0X[3Xf[0X[2X ) _______________________________________________[0Xattribute [2X> DecreasingOn( [0X[3Xf[0X[2X ) _______________________________________________[0Xattribute [6XReturns:[0X The union of all residue classes r(m) such that |R/a_r(m)R| > |R/c_r(m)R| or |R/a_r(m)R| < |R/c_r(m)R|, respectively, where R denotes the source, m denotes the modulus and a_r(m), b_r(m) and c_r(m) denote the coefficients of [3Xf[0X as introduced in Section [14X2.1[0X. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> List([1..3],k->IncreasingOn(T^k));[0X [4X[ 1(2), 3(4), 3(4) U 1(8) U 6(8) ][0X [4Xgap> List([1..3],k->DecreasingOn(T^k));[0X [4X[ 0(2), Z \ 3(4), 0(4) U 2(8) U 5(8) ][0X [4Xgap> a := RcwaMapping([[2,0,3],[4,-1,3],[4,1,3]]);; # Collatz' permutation[0X [4Xgap> List([-2..2],k->IncreasingOn(a^k));[0X [4X[ Z \ 1(8) U 7(8), 0(2), [ ], Z \ 0(3), 1(9) U 4(9) U 5(9) U 8(9) ][0X [4X[0X [4X------------------------------------------------------------------[0X We assign certain directed graphs to rcwa mappings, which encode the order in which trajectories may traverse the residue classes modulo some modulus: [1X2.8-4 TransitionGraph[0X [2X> TransitionGraph( [0X[3Xf, m[0X[2X ) _________________________________________[0Xoperation [6XReturns:[0X The transition graph of the rcwa mapping [3Xf[0X for modulus [3Xm[0X. The [13Xtransition graph[0X Gamma_f,m of f for modulus m is defined as follows: (1) The vertices are the residue classes (mod m). (2) There is an edge from r_1(m) to r_2(m) if and only if there is some n in r_1(m) such that n^f in r_2(m). The assignment of the residue classes (mod m) to the vertices of the graph corresponds to the ordering of the residues in [10XAllResidues(Source([3Xf[0X),[3Xm[0X)[0X. The result is returned in the format used by the package [5XGRAPE[0X [Soi02]. There are a couple of operations and attributes which are based on these graphs: [1X2.8-5 OrbitsModulo[0X [2X> OrbitsModulo( [0X[3Xf, m[0X[2X ) ____________________________________________[0Xoperation [6XReturns:[0X The partition of [10XAllResidues(Source([3Xf[0X),[3Xm[0X)[0X corresponding to the weakly connected components of the transition graph of the rcwa mapping [3Xf[0X for modulus [3Xm[0X. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> OrbitsModulo(ClassTransposition(0,2,1,4),8);[0X [4X[ [ 0, 1, 4 ], [ 2, 5, 6 ], [ 3 ], [ 7 ] ][0X [4X[0X [4X------------------------------------------------------------------[0X [1X2.8-6 FactorizationOnConnectedComponents[0X [2X> FactorizationOnConnectedComponents( [0X[3Xf, m[0X[2X ) ______________________[0Xoperation [6XReturns:[0X The set of restrictions of the rcwa mapping [3Xf[0X to the weakly connected components of its transition graph Gamma_f,m. The product of the returned mappings is [3Xf[0X. They have pairwise disjoint supports, hence any two of them commute. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> sigma := ClassTransposition(1,4,2,4) * ClassTransposition(1,4,3,4)[0X [4X> * ClassTransposition(3,9,6,18) * ClassTransposition(1,6,3,9);;[0X [4Xgap> List(FactorizationOnConnectedComponents(sigma,36),Support);[0X [4X[ 33(36) U 34(36) U 35(36), 9(36) U 10(36) U 11(36), [0X [4X <union of 23 residue classes (mod 36)> \ [ -6, 3 ] ][0X [4X[0X [4X------------------------------------------------------------------[0X [1X2.8-7 TransitionMatrix[0X [2X> TransitionMatrix( [0X[3Xf, m[0X[2X ) ________________________________________[0Xoperation [6XReturns:[0X The transition matrix of the rcwa mapping [3Xf[0X for modulus [3Xm[0X. Let M be this matrix. Then for any two residue classes r_1(m), r_2(m) in R/mR, the entry M_r_1(m),r_2(m) is defined by (see the PDF- or HTML version of the manual), where hatm is the product of [3Xm[0X and the square of the modulus of [3Xf[0X. The assignment of the residue classes (mod [3Xm[0X) to the rows and columns of the matrix corresponds to the ordering of the residues in [10XAllResidues(Source([3Xf[0X),[3Xm[0X)[0X. The transition matrix is a weighted adjacency matrix of the corresponding transition graph [10XTransitionGraph([3Xf[0X,[3Xm[0X)[0X. The sums of the rows of a transition matrix are always equal to 1. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> T := RcwaMapping([[1,0,2],[3,1,2]]);; # The Collatz mapping.[0X [4Xgap> Display(TransitionMatrix(T^3,3));[0X [4X[ [ 1/8, 1/4, 5/8 ],[0X [4X [ 0, 1/4, 3/4 ],[0X [4X [ 0, 3/8, 5/8 ] ][0X [4X[0X [4X------------------------------------------------------------------[0X [1X2.8-8 Sources & Sinks (of an rcwa mapping)[0X [2X> Sources( [0X[3Xf[0X[2X ) ____________________________________________________[0Xattribute [2X> Sinks( [0X[3Xf[0X[2X ) ______________________________________________________[0Xattribute [6XReturns:[0X A list of unions of residue classes modulo the modulus m of the rcwa mapping [3Xf[0X, as described below. The returned list contains an entry for any strongly connected component of the transition graph of [3Xf[0X for modulus [10XMod([3Xf[0X)[0X which has only outgoing edges ("source") or which has only ingoing edges ("sink"), respectively. The list entry corresponding to such a component is the union of the vertices belonging to it. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> g := ClassTransposition(0,2,1,2)*ClassTransposition(0,2,1,4);;[0X [4Xgap> Sources(g); Sinks(g);[0X [4X[ 0(4) ][0X [4X[ 1(4) ][0X [4X[0X [4X------------------------------------------------------------------[0X [1X2.8-9 Loops[0X [2X> Loops( [0X[3Xf[0X[2X ) ______________________________________________________[0Xattribute [6XReturns:[0X If [3Xf[0X is bijective, the list of non-isolated vertices of the transition graph of [3Xf[0X for modulus [10XMod([3Xf[0X)[0X which carry a loop. In general, the list of vertices of that transition graph which carry a loop, but which [3Xf[0X does not fix setwise. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> Loops(ClassTransposition(0,2,1,2)*ClassTransposition(0,2,1,4));[0X [4X[ 0(4), 1(4) ][0X [4X[0X [4X------------------------------------------------------------------[0X There is a nice invariant of trajectories of the Collatz mapping: [1X2.8-10 GluckTaylorInvariant[0X [2X> GluckTaylorInvariant( [0X[3Xa[0X[2X ) ________________________________________[0Xfunction [6XReturns:[0X The invariant introduced in [GT02]. This is (sum_i=1^l a_i * a_i mod l + 1)/(sum_i=1^l a_i^2), where l denotes the length of [3Xa[0X. The argument [3Xa[0X must be a list of integers. In [GT02] it is shown that if [3Xa[0X is a trajectory of the `original' Collatz mapping n -> (n/2 if n even, 3n+1 if n odd) starting at an odd integer >= 3 and ending at 1, then the invariant lies in the interval ]9/13,5/7[. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> C := RcwaMapping([[1,0,2],[3,1,1]]);;[0X [4Xgap> List([3,5..49],n->Float(GluckTaylorInvariant(Trajectory(C,n,[1]))));[0X [4X[ 0.701053, 0.696721, 0.708528, 0.707684, 0.706635, 0.695636, 0.711769,[0X [4X 0.699714, 0.707409, 0.693833, 0.710432, 0.706294, 0.714242, 0.699935,[0X [4X 0.714242, 0.705383, 0.706591, 0.698198, 0.712222, 0.714242, 0.709048,[0X [4X 0.69612, 0.714241, 0.701076 ][0X [4X[0X [4X------------------------------------------------------------------[0X Quite often one can make certain "educated guesses" on the overall behaviour of the trajectories of a given rcwa mapping. For example it is reasonably straightforward to make the conjecture that all trajectories of the Collatz mapping eventually enter the finite set -136, -91, -82, -68, -61, -55, -41, -37, -34, -25, -17, -10, -7, -5, -1, 0, 1, 2, or that "on average" the next number in a trajectory of the Collatz mapping is smaller than the preceding one by a factor of sqrt3/2. However it is clear that such guesses can be wrong, and that they therefore cannot be used to prove anything. Nevertheless they can sometimes be useful: [1X2.8-11 LikelyContractionCentre[0X [2X> LikelyContractionCentre( [0X[3Xf, maxn, bound[0X[2X ) _______________________[0Xoperation [6XReturns:[0X A list of ring elements (see below). This operation tries to compute the [13Xcontraction centre[0X of the rcwa mapping [3Xf[0X. Assuming its existence this is the unique finite subset S_0 of the source of [3Xf[0X on which [3Xf[0X induces a permutation and which intersects nontrivially with any trajectory of [3Xf[0X. The mapping [3Xf[0X is assumed to be [13Xcontracting[0X, i.e. to have such a contraction centre. As in general contraction centres are likely not computable, the methods for this operation are probabilistic and may return wrong results. The argument [3Xmaxn[0X is a bound on the starting value and [3Xbound[0X is a bound on the elements of the trajectories to be searched. If the limit [3Xbound[0X is exceeded, an Info message on Info level 3 of [10XInfoRCWA[0X is given. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> T := RcwaMapping([[1,0,2],[3,1,2]]);; # The Collatz mapping.[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 [4X[0X [4X------------------------------------------------------------------[0X [1X2.8-12 GuessedDivergence[0X [2X> GuessedDivergence( [0X[3Xf[0X[2X ) __________________________________________[0Xoperation [6XReturns:[0X A floating point value which is intended to be a rough guess on how fast the trajectories of the rcwa mapping [3Xf[0X diverge (return value greater than 1) or converge (return value smaller than 1). Nothing particular is guaranteed. [4X--------------------------- Example ----------------------------[0X [4X[0X [4Xgap> GuessedDivergence(T);[0X [4X#I Warning: GuessedDivergence: no particular return value is guaranteed.[0X [4X0.866025[0X [4X[0X [4X------------------------------------------------------------------[0X [1X2.9 The categories and families of rcwa mappings[0X [1X2.9-1 IsRcwaMapping[0X [2X> IsRcwaMapping( [0X[3Xf[0X[2X ) _________________________________________________[0Xfilter [2X> IsRcwaMappingOfZ( [0X[3Xf[0X[2X ) ______________________________________________[0Xfilter [2X> IsRcwaMappingOfZ_pi( [0X[3Xf[0X[2X ) ___________________________________________[0Xfilter [2X> IsRcwaMappingOfGFqx( [0X[3Xf[0X[2X ) ___________________________________________[0Xfilter [6XReturns:[0X [10Xtrue[0X if [3Xf[0X is an rcwa mapping, an rcwa mapping of the ring of integers, an rcwa mapping of a semilocalization of the ring of integers or an rcwa mapping of a polynomial ring in one variable over a finite field, respectively, and [10Xfalse[0X otherwise. Often the same methods can be used for rcwa mappings of the ring of integers and of its semilocalizations. For this reason there is a category [10XIsRcwaMappingOfZOrZ_pi[0X which is the union of [10XIsRcwaMappingOfZ[0X and [10XIsRcwaMappingOfZ_pi[0X. The internal representation of rcwa mappings is called [10XIsRcwaMappingStandardRep[0X. There are methods available for [10XExtRepOfObj[0X and [10XObjByExtRep[0X. [1X2.9-2 RcwaMappingsFamily[0X [2X> RcwaMappingsFamily( [0X[3XR[0X[2X ) __________________________________________[0Xfunction [6XReturns:[0X The family of rcwa mappings of the ring [3XR[0X.