7

Every positive integer $n$ can be represented as a product \begin{align} n &= a \cdot 2^k \text{,} \end{align} where the $a$ is odd integer and $k$ is an exponent of two. Let $\varepsilon$ be the map $n \mapsto k$, and let $\sigma$ be the map $n \mapsto a$.

Now define two auxiliary functions \begin{align} a(n-1) &= \sigma(n) \cdot 3^{ \varepsilon(n) } \text{,} \\ b(n+1) &= \sigma(n) \cdot 1^{ \varepsilon(n) } \text{,} \end{align} and function composition \begin{align} T(n) &= b(a(n)) \text{.} \end{align}

Collatz problem concerns the question of whether the function iterates reach 1, for all $n>0$. This is nothing new. I just formulated the Collatz problem in a very complicated manner. Instead of tracking $n$ directly, I now track the pair $(\sigma(n), \varepsilon(n))$.

The point of this formulation is that I can verify the convergence of the problem for all $\sigma(\cdot) < \Sigma$ and $\varepsilon(\cdot) < E$. This is much easier than verifying the problem directly on $n$ because pairs of values $(\sigma(n), \varepsilon(n))$ take much smaller magnitudes than the $n$ itself. For example, I have verified the convergence for all $(\sigma, \varepsilon)$ below $(2^{44}, 14)$. This was fairly fast on my desktop computer. For convenience, the pair $(2^{44}, 14)$ corresponds to approximatelly $2^{66.2}$.

Can anyone confirm the mathematical correctness of my verification procedure? Would anyone be willing to implement this effectively (in any programming language) and verify it for higher limits?


As requested in the comment, there is an illustration for $n = 27$:

$$\begin{matrix} n & (\sigma, \varepsilon) \text{ in $a(n-1)$} & T(n) \\ \hline 27 & ( 7, 2) & b( 7 \cdot 3^{ 2}) \\ 31 & ( 1, 5) & b( 1 \cdot 3^{ 5}) \\ 121 & ( 61, 1) & b( 61 \cdot 3^{ 1}) \\ 91 & ( 23, 2) & b( 23 \cdot 3^{ 2}) \\ 103 & ( 13, 3) & b( 13 \cdot 3^{ 3}) \\ 175 & ( 11, 4) & b( 11 \cdot 3^{ 4}) \\ 445 & ( 223, 1) & b( 223 \cdot 3^{ 1}) \\ 167 & ( 21, 3) & b( 21 \cdot 3^{ 3}) \\ 283 & ( 71, 2) & b( 71 \cdot 3^{ 2}) \\ 319 & ( 5, 6) & b( 5 \cdot 3^{ 6}) \\ 911 & ( 57, 4) & b( 57 \cdot 3^{ 4}) \\ 577 & ( 289, 1) & b( 289 \cdot 3^{ 1}) \\ 433 & ( 217, 1) & b( 217 \cdot 3^{ 1}) \\ 325 & ( 163, 1) & b( 163 \cdot 3^{ 1}) \\ 61 & ( 31, 1) & b( 31 \cdot 3^{ 1}) \\ 23 & ( 3, 3) & b( 3 \cdot 3^{ 3}) \\ 5 & ( 3, 1) & b( 3 \cdot 3^{ 1}) \\ 1 & ( 1, 1) & b( 1 \cdot 3^{ 1}) \\ \end{matrix}$$


As requested, there is a pseudocode:

function a(n):
    return σ(n+1) × 3^ε(n+1);

function b(n):
    return σ(n−1) × 1^ε(n−1);

function test_convergence(n):
    while n != 1 do:
        n := b( a(n) )

Or alternativelly:

function f(s, t):
    n := s × 3^t − 1
    return ( σ(n), ε(n) )

function g(s, t):
    n := s × 1^t + 1
    return ( σ(n), ε(n) )

function test_convergence(s, t):
    while (s, t) != (1, 1) do:
        (s, t) = f( g(s, t) )

Just for the record, I have verified the convergence of the Collatz problem below the following $(\sigma, \varepsilon)$ bounds. I stopped working on it now. So I just share the achieved results for the case someone wants to continue. Verification for higher $\sigma$ values is very computationally demanding.

$$\begin{matrix} (\sigma, \varepsilon) \text{ upper bound} \\ \hline ( 2^{49}, 2 ) \\ ( 2^{48}, 6 ) \\ ( 2^{47}, 9 ) \\ ( 2^{46}, 10 ) \\ ( 2^{45}, 12 ) \\ ( 2^{44}, 16 ) \\ ( 2^{43}, 15 ) \\ ( 2^{42}, 22 ) \\ ( 2^{41}, 24 ) \\ ( 2^{40}, 45 ) \\ ( 2^{39}, 46 ) \\ ( 2^{38}, 47 ) \\ ( 2^{37}, 53 ) \\ ( 2^{36}, 78 ) \\ ( 2^{35}, 84 ) \\ ( 2^{34}, 108 ) \\ ( 2^{33}, 132 ) \\ ( 2^{32}, 256 ) \\ \end{matrix}$$

DaBler
  • 1,000
  • 2
    I don't understand what you have done!! can you illustrate it for example for $n=5$? – C.F.G Aug 21 '19 at 16:27
  • If I understand correctly $\epsilon(n)$ should be zero for odd $n$. Yet in your listing for $n=27$ there are multiple rows with odd numbers but $\epsilon$ is positive and rather large can you please explain how come $5$ corresponds to $(3,1)$? – Radost Aug 21 '19 at 16:57
  • @Radost Note the $n-1$ in the definition of $a$. To express $\varepsilon$ from $n$, you must add one, therefore, $\varepsilon > 0$. – DaBler Aug 21 '19 at 17:02
  • 1
    You are exploiting the fact that any odd number can be written as $n=\sigma \cdot 2^\varepsilon−1$ and that $\sigma \cdot 2^\varepsilon−1$ always go straight to $\sigma \cdot 3^\varepsilon−1$ in exactly $\varepsilon$ steps, number which is even and from which you strip any factor of 2 to find the next odd number. Isn't this an optimisation already used in current algorithm? Note: you can optimise further https://math.stackexchange.com/questions/2428060/how-to-prove-this-inequality-f2h-1%e2%89%a4-frac3h-12/2428208#2428208 – Collag3n Aug 21 '19 at 17:55
  • 1
    Why does $(2^{44}, 14)$ corresponds to $\sim 2^{66.2}$ and not to $2^{44} \cdot 2^{14} = 2^{58}$? – mihaild Aug 21 '19 at 18:47
  • Depends on what you mean by effectively. And also I am not sure if the code I have can be used for this. Do you have any pseudocode or is it too much code to post here? –  Aug 21 '19 at 23:59
  • @mihaild Since the $(2^{44}, 14)$ pair in the $a(n-1)$ corresponds to $2^{44} \cdot 3^{14} \approx 2^{66.189}$. – DaBler Aug 22 '19 at 11:37
  • @mihaild Of course you are right that the previous $n$ was $2^{44} \cdot 2^{14} - 1$. – DaBler Aug 22 '19 at 11:52
  • @NaturalNumberGuy I added just some pseudocode from top of my head. I hope I didn't make a mistake in it. – DaBler Aug 22 '19 at 12:12
  • @NaturalNumberGuy The ctz(n) stands for "count trailing zeros in binary represendation of n" and the odd_part(n) function simply returns n/2^ctz(n). – DaBler Aug 22 '19 at 12:14
  • So you have only checked some number of magnitude $2^{66.2}$, not all numbers up to it? Also, did I understood correct that you checked all numbers up to $2^58$? – mihaild Aug 22 '19 at 12:19
  • @mihaild I checked neither all the numbers under $2^{66.2}$ nor all the numbers under $2^{58}$. I checked all pairs under $(2^{44}, 14)$, which cannot be mapped densely to $n$. – DaBler Aug 22 '19 at 12:23
  • 1
    does this mean $$\begin{align} a(n) &= \sigma(n+1) \cdot 3^{ \varepsilon(n+1) } \text{,} \ b(n) &= \sigma(n-1) \cdot 1^{ \varepsilon(n-1) } \text{?} \end{align}$$ If so, why don't you write it down it this way? The value of the expression $1^{ \varepsilon(n-1) } $ is always $1$, so why is it part of the formula? – miracle173 Aug 22 '19 at 12:31
  • @mihaild Informally speaking, another way to look at this is that you cannot map the plane $(\sigma, \varepsilon)$ below $(\Sigma, E)$ to a line $n$ below $N$. – DaBler Aug 22 '19 at 12:36
  • @miracle173: Yes, $1^n = 1$. I put it this way for the symmetry with $3^n$. – DaBler Aug 22 '19 at 12:37
  • @DaBler om. And why do you not write define $a$ and $b$ in the usual way that I have shown? – miracle173 Aug 22 '19 at 13:04
  • @miracle173 Because I do not want to compute these functions explicitly. The point is to implement the mapping from input pair of values to output pair. The formulation $a(n) = \ldots$ guides you to procedural programming. – DaBler Aug 22 '19 at 13:10
  • @miracle173 Besides, my formulation is more concise. – DaBler Aug 22 '19 at 13:10
  • but mine is correct, too? – miracle173 Aug 22 '19 at 13:14
  • @miracle173 Yes, these should be equivalent. – DaBler Aug 22 '19 at 13:17
  • 1
  • You didn't test all numbers below $2^{66}$ because many of them have $\varepsilon \gt 14$. – Fabius Wiesner Aug 22 '19 at 15:01
  • @mbjoe That is obvious. – DaBler Aug 22 '19 at 15:07
  • Also, many of them have $\sigma \gt 2^{44}$. Thus I don't see where is the advantage of using your method. – Fabius Wiesner Aug 22 '19 at 15:07
  • @DaBler: thanks man. will look into that code –  Aug 22 '19 at 16:02
  • btw. i guess the while loop means that if both $s$ and $t$ are equal to $1$ they branch out of the loop?. since i am not familiar with that syntax i can interpreted as if $s$ or $t$ are equal, but i guess its not the later one. –  Aug 22 '19 at 16:07
  • 1
    @NaturalNumberGuy Yes, the do-while loop is interrupted when (s, t) pair reaches (1, 1). – DaBler Aug 22 '19 at 16:09
  • Your math does not correspond to your pseudocode. Notice that the math gives $a(n)=\sigma(n+1)\cdot 3^{\varepsilon(n+1)}$, but pseudocode is equivalent to $a(n)=\sigma(n)\cdot 3^{\varepsilon(n)}-1$. Also if you claim that your $T(n)$ converge to same values as Collatz, then you should prove it or show its derivation - then it can be verified by others. – Sil Aug 25 '19 at 06:50
  • Also, there is no point in starting from numbers of form $n=s\cdot 2^t$ for $t>0$ since these are equivalent to checking just $s$. Of course you will get $t>0$ for intermediate results though, but whole point of Collatz is to check for large odd numbers, and not large powers of $2$. – Sil Aug 25 '19 at 08:35
  • 1
    @Sil Sorry, I chose confusing names for those functions. Now it should be clear. The math behind is explained here: https://math.stackexchange.com/questions/3311547/alternative-formulation-of-the-collatz-problem – DaBler Aug 25 '19 at 09:12
  • @Sil The bottom line is that this new algorithm seems to be much faster than the existing methods using huge pre-calculated tables for jumps in T(n). My implementation is available here: https://github.com/xbarin02/collatz/ – DaBler Aug 25 '19 at 09:17
  • so does (49,2) mean you have checked the collatz conjecture for all numbers of the a*2^k, where a is odd and in (1,2^44), and k in {0,1,2} ? – miracle173 Aug 25 '19 at 15:21
  • $T(n)$ is prety simple to implement: Add 1 to $n$, divide by $2^\varepsilon$ (or remove any factor 2), multiply by $3^\varepsilon$, substract 1 and remove any factor 2. I am prety sure it can be done in assembler/c++ with a few ADD and bitwise shift/count. – Collag3n Aug 25 '19 at 15:58
  • @Collag3n can you tell me how long such a sequence of operations will take? I want to estimate how much time is needed to check the numbers from 1 to N. – miracle173 Aug 26 '19 at 05:24
  • Do you have any idea how far Collatz has already been verified? See http://sweet.ua.pt/tos/3x+1.html – Gerry Myerson Aug 26 '19 at 06:42
  • http://www.ericr.nl/wondrous/index.html has perhaps gone even farther. – Gerry Myerson Aug 26 '19 at 06:53
  • @GerryMyerson Chrisitan Hercher from University of Flensburg (Germany) proved it for $n \le 87 \cdot 2^{60} \approx 10^{20}$. I think this was 2016. https://www.uni-flensburg.de/fileadmin/content/abteilungen/mathematik/hercher/forschung/wurzel-artikel-collatz.pdf – miracle173 Aug 26 '19 at 07:11
  • @miracle173 No, it is upper bound. The (2^49, 2) means I have verified all odd $1 \le \sigma < 2^{49}$ and $1 \le \varepsilon < 2$. – DaBler Aug 26 '19 at 09:20
  • @Collag3n I have done this in C using compiler intrinsics which compile directly into TZCNT instruction on newer x86-64 processors: https://github.com/xbarin02/collatz – DaBler Aug 26 '19 at 09:23
  • @GerryMyerson This was already answered here: https://math.stackexchange.com/questions/3314430/how-far-has-collatz-conjecture-been-computationally-verified – DaBler Aug 26 '19 at 09:25
  • @miracle173 Testing $2^{40}$ numbers from $0$ up to $2^{40}$ takes approximatelly 3 minutes and 23 seconds on 2.40 GHz CPU. This corresponds to the throughput $8.67 \times 10^{10}$ numbers per seconds. Testing $2^{40}$ numbers starting from $2^{68}$ takes approximatelly 1 hour and 14 minutes on the same machine. This gives the throughput about $3.99 \times 10^9$ 128-bit numbers per seconds. – DaBler Aug 26 '19 at 09:27
  • @miracle173 This is much better than state-of-the-art implementations (see this paper), since they deal only with 64-bit numbers, that have been verified for long time. – DaBler Aug 26 '19 at 09:31
  • @miracle173 Also, I see you had put the text from my answer to my question. I just wanted to say that I have no problem at all with this. – DaBler Aug 26 '19 at 09:34
  • @DaBler I posted again in the chat (https://chat.stackexchange.com/rooms/97719/discussion-between-miracle173-and-dabler) because i think this needs some discussion. I must leave now but will be back later. – miracle173 Aug 27 '19 at 07:15
  • @DaBler in https://matheplanet.com/matheplanet/nuke/html/viewtopic.php?rd2&topic=223140&start=80#p1636745 they say they are scanning 10^13 numbers per hour per core. "cyrus" is Chrisitan Hercher from University of Flensburg from https://www.uni-flensburg.de/fileadmin/content/abteilungen/mathematik/hercher/forschung/wurzel-artikel-collatz.pdf – miracle173 Aug 28 '19 at 08:12
  • @miracle173 Let's continue the discussion again in the chat ... – DaBler Aug 28 '19 at 10:51
  • For those who are interested, I managed to verify, using a similar algorithm, all the numbers up to $2^{68}$. Details in this paper. – DaBler Jul 03 '20 at 09:46

1 Answers1

3

Edit 2019-08-30:

Added algorithm in pseudocode

Edit 20190831

added Python code and description and reference to C implementation on codereview


The Collatz function is defined as $$ \text{collatz}(n):=\begin{cases} 3n+1,& n\equiv 1 \pmod 2 \\ \frac n 2, & n \equiv 0 \pmod 2 \end{cases}$$

A trajectory of n with respect to a function $f$ or an $f$-trajectory of $n$ is the sequence $$n, \;f(n), \;f(f(n)), \;f^3(n),\;\ldots$$

A subsequence of such a trajectory I will call a subtrajectory.

We are interested if the collatz-trajectory of a positive integer $n$ is either unbounded or if it will cycle. At the moment the trajectories of all numbers investigated so far will cycle. The cycle for all these number is the cycle $4,2,1,4,..$

If a trajectory cycles then a subtracjectory must contain identical values and vice versa.

We define now the following function that is related to the Collatz function: $$ \text{c}(n):=\begin{cases} \frac {3n+1} 2, & n\equiv 1 \pmod 2 \\ \frac n 2, & n \equiv 0 \pmod 2 \end{cases}\tag{1.1} $$ A c-trajectory of $n$ will be a Collatz-subtrajectory of $n$.

Instead of the $c$-trajectory of $n$ $$n, c(n), c^2(n),\ldots$$ we can construct a new sequence

$$n+1, c(n)+1, c^2(n)+1, \ldots$$

This is a trajectory with respect to the function $d$

$$d(n):=c(n-1)+1\tag{2.1}$$

$$\begin{array} 27&41&62&31&47&71&\ldots\\ 28&42&63&32&48&72\ldots \end{array}\tag{2.2}$$

From $(2.1)$ follows

$$c(n)=d(n+1)-1$$ and by induction one can prove $$d^k(n)=c^k(n-1)+1\tag{2.3}$$ $$c^k(n)=d^k(n)-1$$

From $(1.1)$ and $(2.1)$ we get $$ \text{d}(n):=\begin{cases} \frac{n+1} 2,& n\equiv 1 \pmod 2 \\ \frac {3n} 2, & n \equiv 0 \pmod 2 \end{cases}\tag{2.4}$$

From $c$ and $d$ we can generate new functions

$$c^+(n)=\begin{cases} \frac{3n+1}2 , & n\equiv 1 \pmod 2 \\ \frac n {2^k},& n=2^ka, k>0, a\equiv 1\pmod 2 \end{cases} $$

$$d^+(n)=\begin{cases} \frac{n+1}2 , & n\equiv 1 \pmod 2 \\ \left(\frac {3} {2}\right)^kn,& n=2^ka, k>0, a\equiv 1\pmod 2 \end{cases} $$

We can rewrite this definitions as

$$c^+(n)=\begin{cases} c(n) , & n\equiv 1 \pmod 2 \\ c^k(n),& n=2^ka, k>0, a\equiv 1\pmod 2 \end{cases} $$

$$d^+(n)=\begin{cases} d(n) , & n\equiv 1 \pmod 2 \\ d^k(n),& n=2^ka, k>0, a\equiv 1\pmod 2 \end{cases} $$

and we see that $c^+$-trajectories are $c$-subtrajectories and $d^+$-trajectories are $d$-subtrajectories.

Finally we define

$$T(n)=\begin{cases} c^+(n) , & n\equiv 1 \pmod 2 \\ c^+(d^+(n+1)-1),& n\equiv 1\pmod 2 \end{cases} $$

An again we have that a trajectory of $T$ is a subtrajectory of $c$. If $n$ is odd this is trivial, if $n$ is even then $$T(n)=c^+(d^+(n+1)-1)=c^+(d^{k_1}(n+1)-1)=c^+(c^{k_1}(n))=c^{k_2}(c^{k_1}(n))=c^{k_2+k_1}(n)$$

The function $T$ is the function that you use for your calculations.

The following algorithm assumes that $k$ is a positive integer and $u$ is an odd positive integer. There are two different variables $n_c$ and $n_d$ instead of one variable to show which values are from the trajectory of $c$ and therefore of the Collatz function and which values are from the trajectory of $d$ and therefore from the sequence that we get by adding $1$ to the trajectory values of the Collatz function. The termination condition depends on the purpose of the algorithm. Step 2 is used to simplify the comments and should not be implemented. $$ \begin{array}[lrc]\\ Step&Precondition&Action&Comment &&Comment\\ 1&&n_c\gets n_0&/* n_0 \; \text{is the start value}&*/\\ 2&&&/*x\gets n_c&*/&\\ 3&/*n_c \text{ is odd}*/&n_d\gets n_c+1&/*x+1&*/\\ 4&/*n_d=2^ku*/&n_d\gets 3^ku&/*d^+(x+1)&*/&/*a(x)*/\\ 5&/*n_d \text{ is odd}*/&n_c\gets n_d-1&/*d^+(x+1)-1&*/\\ 6&/*n_c=2^ku*/&n_c\gets u&/*c^+(d^+(x+1)-1)&*/&/*b(a(x))*/\\ 7&&\mathbf{if }\;n_c =1 \; \mathbf{then}&/* \text{or} \; n_c<n&*/\\ &&\quad \text{stop}\\ &&\mathbf{else}\\ &&\quad \mathbf{goto} \text{ Step 2} \end{array} $$

This algorithm can be easily transformed to a pseudocode/Python3 program.

  • % is the modulo operator
  • // is integer division
  • ** is the power operator
  • x += y means x=x+1, similar holds for other operators

Here is the program:

n=n0
while n>1:
    n+=1
    k=0
    while n%2==0:
        k+=1
        n//=2
    n*=3**k
    n-=1
    while n%2==0:
        n//=2

It can be rewritten by using some functions and replacing the variable k by e.

  • ctz(n) returns e, where $n=2^eu$, $u$ is odd
  • rsh(n,e) returns $\frac n{2^e}$
  • lut(e) returns $3^e$

the new program:

n=n0
while n>1:
    n+=1
    e=ctz(n)
    n=rsh(n,e)
    n*=lut(e)
    n-=1
    n=rsh(n,ctz(n))
  • The function ctz can be implemented by counting how often n can be repeatedly divided by two until the result is odd or by counting the number of trailing $0$ of the binary representation of n.
  • The function rsh can be implemented by multiplying n n-times by $2$ or by shifting the binary representation $n$-times to the right.
  • The function lut(e) returns $3^k$ and can be implemented by a lookup table if the number e will not become too large.

This program now looks like to the C-implementation of the algorithm posted by the OP at codereview.stackexchange.

You can get the $c^+$-trajectory from the $c$-trajectory in the following way: If you current value on the trajectory is odd, than proceed on the $c$-trajectory to the next value. If it is even then proceed to the next odd value (the second branch of the definition of $c^+$) The same holds for the construction of $d^+$ from $d$. This method is shown on the picture. The circled numbers are the values of the $c^+$ (first line) and $d^+$ (second line) trajectory of 27. The last two lines show how to construct the trajectory of $T$ from a trajectory of $c$ and $d$. If you start from an odd value $n$ then got to the opposite even value n+1 of the $d$ trajectory. From this go to the next odd value of the $d$-trajectory. Then go to the opposite even value of the $c$-trajectory by subtracting $1$ and from this go to the next odd value of the $c$-trajectory.

enter image description here

At the moment I cannot see any advantage in using the function $T$ instead of $c^+$ or $d^+$.

I evaluated the number of function calls one needs using $c^+$, $d^+$ and $T$ until the the trajectory reaches $1$. For all odd numbers $n \in \{3,...,N\}$ I summed these path lengths up and got the following numbers

     N  c+ all   c+ 2nd  d+ all   d+ 2nd    T all
  1000   16506     5469   16267     5461     5452
 10000  229650    76314  226297    76302    76275
100000 2848611   949409 2829632   949374   949358

So from this we see that the number of function calls need to reach the value $1$ in the trajectory is for the functions $d$ and $c$ about the same and three times higher than for the function $T$. But note that a call of the function $T$ contains a call to the second branch of $c^+ $ and a call to the second branch of $d^+$. So all in all one I cannot see that there is any large improvement in using $T$

To check if the trajectory of all numbers $n$ less than $N$ cycles one does not calculate the trajectory values until they reach $1$ but only until it reaches a value less than the start value $n$. I also calculated the number of iterations for different $N$

      N    c+all   c+2nd    d+all   d+2nd    T all
   1000     2696     895     2166     637     892
  10000    25909    8662    21002    6145    8660
 100000   260246   86777   210708   61692   86760
1000000  2612479  871075  2114522  620923  871073

Conclusion

The OP asked if his procedure is correct and I showed here that he uses the function $T$ and that a trajectory of $T$ is a subtrajectory of the Collatz function. So his procedure is correct. Additionally I showed that he cannot expect a substantial performance gain by using $T$ instead of $c^+$ because the number of iteration is the same (maybe they differ by a constant factor).


This is the Python 3 program that generates the data of the table

def c(n):
    # this is the function c+
    if n%2==1:
        return (3*n+1)//2
    else:
        while n%2==0:
            n//=2
        return n
def d(n):
    # this is the function d+
    if n%2==1:
        return (n+1)//2
    else:
        m=1
        while n%2==0:
            n//=2
            m*=3
        return m*n
def T(n):
    # this is the function T
    if n%2==1:
        return c(d(n+1)-1)
    else:
        return(c(n))

def statistics(n,f):
    if f == d:
        i=n+1
    else:
        i=n
    # stop_value=i  # stop if trajectory <=n 
    stop_value=2 # stop if trajectory <=2
    cnt=0
    even_cnt=0
    while i>stop_value:
        i=f(i)
        cnt+=1
        if i%2==0:
            even_cnt+=1
    return(cnt,even_cnt)

for N in [1000,10000,100000]:
    print(N)
    for f in (c,d,T):
        all_calls=0
        even_calls=0
        for N in range(3,N,2):
            tmp=statistics(N,f)
            all_calls+=tmp[0]
            even_calls+=tmp[1]
        print(f,all_calls,even_calls)
miracle173
  • 11,049
  • I think you missed the main point. The improvement is that you need far less iterations of this new algorithm compared to the original Collatz function. The $(3/2)^k$ and $(1/2)^k$ in your equations are just a single CTZ operation. So the convergence test has just changed to iterations of CTZ and multiplication with an entry in a look-up table. – DaBler Aug 26 '19 at 09:40
  • I tried to prove that conjecture. I did make some progress using Markov Chains, but I am nowhere close to a solution. In any case, I posted my findings on my website at https://www.analyticbridge.datasciencecentral.com/forum/topics/self-replicating-programs. Could be an interesting read. – Vincent Granville Aug 26 '19 at 15:23
  • @DaBler I added a "conclusion". The main point is that you asked if your procedure is correct but the switching between c+ an d+ is not an improvement against c+. If using ctz and table lookup will bring a performance improvement is not in scope of this post. But you cannot expect more than improvement by a constant factor. The simplest way to see if your algorithm is an improvement is to implement the standard solution and compare the running times. you will see there is no relevant improvement. – miracle173 Aug 27 '19 at 06:21
  • @DaBler I did some further testing and it seems that length of a trajectory until it cycles of your function is only about 6% of the length of the trajectory of the collatz function. So maybe your function is 17 times faster than the original collatz function. I will post more details later – miracle173 Aug 28 '19 at 06:38
  • @miracle173 Sounds great! – DaBler Aug 28 '19 at 10:50
  • @miracle173 Interestingly, I have found that the processing time of individual blocks (blocks of numbers) is independent of their magnitude, therefore it is constant. See the figure here: https://github.com/xbarin02/collatz – DaBler Aug 29 '19 at 13:18
  • The rsh(n,e) should return n/2^e, not n×2^e. – DaBler Sep 01 '19 at 08:56
  • @DaBler thank's, I repaired id. – miracle173 Sep 01 '19 at 09:11