top of page
Photo-01_edited.jpg

Collatz   Conjecture

The Collatz conjecture, waiting for a demonstration, asks whether, in mathematics, repeating certain simple arithmetic operations will eventually transform every positive integer into one. It concerns sequences of integers in which each term is obtained from the previous term as follows: if the previous term is even, the next term is one half of the previous term. If the previous term is odd, the next term is 3 times the previous term plus 1. The conjecture is that these sequences always reach 1, no matter which positive integer is chosen to start the sequence. Lately I have seen several posts on the Collatz conjecture so I wrote a program in Python that implemented the operations required for verifying the integers of which I am attaching the script. Have fun hunting for the number that will refute the hypothesis!

 

Example:

Program to implement Collatz conjecture from every positive integer

Edited by Gasbion 01/2021

Enter a positive integer: 54613

163840

81920

40960

20480

10240

5120

2560

1280

640

320

160

80

40

20

10

5

16

8

4

2

1

Done!

((19, 'steps down'), (2, 'steps up)', (21, 'total steps')))

Python script:

while True:

    n=0

    def main():

     print ("Program to implement Collatz conjecture from every positive integer)")

     print ("Edited by Gasbion 01/2021")

     n=int(input("Enter a positive integer:"))

     a=0

     b=0

     while(n>0):

            if n%2==0:

             n=n/2

             print n

             a=a+1

            else:

                n=3*n+1

                print n               

                b=b+1

            if(n==1):

              print("Done!")

              print((a, "steps down"), (b, "steps up)", (a+b, "total steps")))

              break

            

    if __name__=='__main__':

     main()

ans = raw_input('wish to continue? y=yes' )

if not 'y' in ans.lower():

     exit()       

 

I was still working on the Collatz conjecture (after my previous post https://lnkd.in/d9cN6nUx), I want publish the results I have reached so far concerning, above all, the research on inverse numbers, those, to be clear, that can be identified, starting from the even number 2 and going backwards by applying the inverse formulas of the Collatz conjecture: 2 * n and when possible (n-1) / 3. It is interesting to note how at each backward step new numbers are identified which starting from step 11 begin to overcome and more and more add new numbers with respect to the number of steps. For this purpose I have written a small program in Python language (2.7) through which it is possible to count how many new numbers are added to each increment of the steps (in reality the number of steps is equal to p + 1 since the program does not count the last step leading to 1) and which are these numbers:
 

Program to search how many and which are the numbers of the Collatz conjecture that we can find in a number of steps back Edited by Gasbion 11/2021
 

How many steps? 1
1 set ([4])
How many steps? 2
2 sets ([8, 1])
How many steps? 3
1 set ([16])
How many steps? 4
2 set ([32, 5] How many steps? 5
2 sets ([64, 10])
How many steps? 6
4 sets ([128, 3, 20, 21])
How many steps? 7
4 sets ([256, 40, 42, 6]
How many steps? 8
6 sets ([512, 80, 84, 85, 12, 13])
How many steps? 9
6 sep ([1024, 160, 24, 168, 170, 26])
How many steps? 10
8 sep ([2048, 320, 340, 341, 336, 48, 52, 53])
How many steps? 20
91 set ([2097152, 327680, 49152, 8874, 267, 9684, 54608, 57856, 57984, 58112, 1450, 36, 37, 38, 9685, 349504, 9096, 9600, 9045, 9098, 1613, 9024, 1604, 1605, 1606, 1608, 58252, 1610, 1611, 1612, 9698, 58253, 9040, 1507, 9044, 58197, 58176, 54613, 344064, 54272, 8704, 9669, 8832, 54592, 348160, 58248, 58250, 9100, 9101, 9680, 1476, 8960, 1440, 1478, 349184, 241, 58024, 58026, 54528, 1472, 58192, 349440, 9664, 8864, 9668, 1477, 9670, 8872, 9699, 1488, 53248, 1492, 1493, 58016, 224, 349520, 1506, 9640, 232, 234, 240, 1448, 9632, 244, 245, 58196, 54612, 1408, 9642, 349524, 349525])
How many steps? 30
926
How many steps? 40
9635
How many steps? 50
100144
How many steps? 60
1040490
How many steps? 70
10812460

 

Here I stopped because the time taken for the calculation began to be in the order of minutes and I only reported the number of numbers after 20th step. However, it is possible to note that for every ten steps the number of new numbers roughly increases tenfold and with this trend it seems plausible to think that it tends to infinity.

 

Python script:

while True:

    print ("Program to search  how many and which are the numbers of the Collatz conjecture")

    print ("that we can finds in a number of steps back Edited by Gasbion 11/2021")

    a = 2

    b = input("How many steps? ")

    if a == 1:

        a = 2

        b -= 1

    c = {a}

    for step in range(b):

        n = set(number * 2 for number in c if number != 1) | set((number - 1) // 3 for number in c if number % 6 == 4)

        #print n

        c = n

    print(len(n)), n

bottom of page