#C11.txt: Feb. 25, 2016 ; Collatz cont'd Help:=proc(): print( `CgS(L,n,f), TS(L,n,f,m), AT(L,n,m) , IsP(T,n), FPO(L,n,m) `): end: #CgS(L,n,f): inputs a Collatz-type rule L phrased in terms of the discrete variable #symbol n, and an affine-linear expression,f=A*n+B (where A is divisible by k=nops(L)) #and outputs its image under L #For example for the original Collatz rule L=[(3*n+1)/2,n/2] and #f=4*n+3 the output is (3*(4*n+3)+1)/2=6*n+5 CgS:=proc(L,n,f) local k,A,m: k:=nops(L): A:=coeff(f,n,1): if A mod k<>0 then RETURN(FAIL): fi: m:=coeff(f,n,0) mod k: if m=0 then m:=k: fi: subs( n=f ,L[m]): end: #TS(L,n,f,m): inputs a Collatz-type rule L in n, an affine-linear expression #f, and a pos. integer m, finds its trajecorty of length m TS:=proc(L,n,f,m) local i,M,em: M:=[f]: em:=f: for i from 2 to m do em:=CgS(L,n,em): if em=FAIL then RETURN(M,FAIL): fi: M:=[op(M),em]: od: M: end: #AT(L,n,m): all the possible k^(m-1) symbolic trajectories of length m #of the Collatz-rule L phrased in terms of n #The outout is a list of length k^(m-1) with all the possible moduli AT:=proc(L,n,m) local i,k: k:=nops(L): [ seq(TS(L,n,k^(m-1)*n+i,m),i=0..k^(m-1)-1)]: end: #inputs a trajectory (a list of expressions in n) and outputs #finds whether T[1]=T[nops(T)] is solvable in n pos. integers #and outputs FAIL or the succesful periodic orbit IsP:=proc(T,n) local n0: n0:=solve(T[1]=T[nops(T)],n): if not (type(n0,integer) and n0>= 0) then FAIL: else subs(n=n0,T): fi: end: #FPO(L,n,m): inputs a Collatz-type rule L phrased in terms of n, and a pos. integer m #Finds the set of ALL (numeric) periodic orbits of length m FPO:=proc(L,n,m) local A, S,i,mingjia: A:=AT(L,n,m+1): S:={}: for i from 1 to nops(A) do mingjia:=IsP(A[i],n): if mingjia<>FAIL then S:=S union {mingjia}: fi: od: S: end: