collatz project

262 days ago by sclauss

Collatz Conjecture Exploration

Sam Clauss

The hailstone sequence or Collatz conjecture is an unsolved problem in mathematics. Conjectured by Luther Collatz in 1937 it still is unproved that no matter the starting point the number will eventually get back to one. Although it is unproven, it still has many interesting properties to be explored. Different things were explored such as the lengths of sequences and which numbers in the sequence are divisible by primes.

 

Methods and Code

            The version of the Collatz conjecture explored was to multiply the number by three and add 1 on the other hand if the number is even, it will be divided by two. Starting by creating a function called Hailstone(n). The Hailstone function would generate the sequence in a list. After making the Hailstone function a list of sizes were created in a list called size. This was done for 10,000 numbers in a for loop storing Hailstone(i) in the size list. The resulting plot from the list size was amongst the most beautiful graphs I have ever seen.

            Next, I wanted to look at the individual steps in the sequence and see if they were divisible by certain primes. Primes 2, 3, 5, 7, and 11 were investigated. This was done by making a nested for loop. Upon entering the first loop a hailstone sequence would be stored into a temporary list, and then the second for loop would iterate through the temporary list checking if it were divisible by 2, 3, 5, 7, or 11. Proportions were calculated of numbers divisible by these primes.

 

Digits Computed

Divisible by 2 (%)

Divisible by 3 (%)

Divisible by 5 (%)

Divisible by 7 (%)

Divisible by 11 (%)

5000

65.97

0.84

21.32

12.44

7.32

10000

66.03

0.77

21.22

12.63

7.47

100000

66.23

0.61

21.00

13.09

7.91

1000000

-

0.50

20.85

13.29

8.14

 

Conclusion

            The investigation in to collatz levels provided some interesting results. The proportion of for all numbers seems to stay close together and oscillating slightly for some. The proportion divisibly by three seemed surprisingly small but makes sense as we are multiplying by three and adding one. Steady decreases were noticed in proportion divisible by 3 and five while increases were seen in seven and eleven. I theorize that for five seven and eleven the percentages will converge to 1/p respectively.

def Hailstone(n): hail_list = [n] while (n > 1): if (n%2==0): n = n/2 else: n = 3*n + 1 hail_list.append(n) return(hail_list) 
       
size = [] for i in srange(0,10000): x = len(Hailstone(i)) size.append(x) 
       
list_plot(size) 
       
frequency = [] whichNums = [] freqWN = [] count = 0 for x in srange(2,200): for y in srange(0, 100): if x == len(Hailstone(y)): whichNums.append(y) count+=1 frequency.append(count) freqWN.append(whichNums) whichNums = [] count = 0 
       
print(frequency[112]) freqWN 
       
0
[[2], [4], [8], [16], [5, 32], [10, 64], [3, 20, 21], [6, 40, 42], [12,
13, 80, 84, 85], [24, 26], [48, 52, 53], [17, 96], [34, 35], [11, 68,
69, 70, 75], [22, 23], [7, 44, 45, 46], [14, 15, 88, 90, 92, 93], [28,
29, 30], [9, 56, 58, 60, 61], [18, 19], [36, 37, 38], [72, 74, 76, 77,
81], [25], [49, 50, 51], [98, 99], [33], [65, 66, 67], [], [43], [86,
87, 89], [], [57, 59], [], [39], [78, 79], [], [], [], [], [], [], [],
[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [],
[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [],
[], [], [], [], [], [], [], [], [], [], [], [], [], [91], [], [], [],
[], [], [], [], [], [], [71], [], [47], [94, 95], [31], [62, 63], [],
[41], [82, 83], [27], [54, 55], [], [], [73], [], [], [97], [], [], [],
[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [],
[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [],
[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [],
[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [],
[], [], [], [], []]
0
[[2], [4], [8], [16], [5, 32], [10, 64], [3, 20, 21], [6, 40, 42], [12, 13, 80, 84, 85], [24, 26], [48, 52, 53], [17, 96], [34, 35], [11, 68, 69, 70, 75], [22, 23], [7, 44, 45, 46], [14, 15, 88, 90, 92, 93], [28, 29, 30], [9, 56, 58, 60, 61], [18, 19], [36, 37, 38], [72, 74, 76, 77, 81], [25], [49, 50, 51], [98, 99], [33], [65, 66, 67], [], [43], [86, 87, 89], [], [57, 59], [], [39], [78, 79], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [91], [], [], [], [], [], [], [], [], [], [71], [], [47], [94, 95], [31], [62, 63], [], [41], [82, 83], [27], [54, 55], [], [], [73], [], [], [97], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]
freqWN[4][1] 
       
32
32
print(frequency) 
       
[1, 1, 1, 1, 2, 2, 3, 3, 5, 2, 3, 2, 2, 5, 2, 4, 6, 3, 5, 2, 3, 5, 1, 3,
2, 1, 3, 0, 1, 3, 0, 2, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 0, 1, 2, 1, 2, 0, 1, 2, 1, 2, 0, 0, 1, 0, 0, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0]
[1, 1, 1, 1, 2, 2, 3, 3, 5, 2, 3, 2, 2, 5, 2, 4, 6, 3, 5, 2, 3, 5, 1, 3, 2, 1, 3, 0, 1, 3, 0, 2, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 2, 1, 2, 0, 1, 2, 1, 2, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
frequency[111] 
       
2
2
frequency[11] 
       
0
0
frequency = [] whichNums = [] freqWN = [] count = 0 for x in srange(2,500): for y in srange(0, 500): if x == len(Hailstone(y)): whichNums.append(y) count+=1 frequency.append(count) freqWN.append(whichNums) whichNums = [] count = 0 
       

Lets see which level lengths are divisible by three

 
       
div3 = 0 div5 = 0 div7 = 0 div11 = 0 total = 0 even = 0 for i in srange(0,5000): templist = Hailstone(i) for j in templist: if j%3 == 0: div3+=1 if j%5 ==0: div5+=1 if j%7 == 0: div7+=1 if j%11 == 0: div11+=1 if j%2==0: even+=1 total+=1 
       
print(float(div3/total)) print(float(div5/total)) print(float(div7/total)) print(float(div11/total)) print(float(even/total)) print(total) 
       
0.00847203135339
0.213187764035
0.124426121036
0.0732274647529
0.659797933527
392940
0.00847203135339
0.213187764035
0.124426121036
0.0732274647529
0.659797933527
392940
div3 = 0 div5 = 0 div7 = 0 div11 = 0 total = 0 for i in srange(0,10000): templist = Hailstone(i) for j in templist: if j%3 == 0: div3+=1 if j%5 ==0: div5+=1 if j%7 == 0: div7+=1 if j%11 == 0: div11+=1 total+=1 print(float(div3/total)) print(float(div5/total)) print(float(div7/total)) print(float(div11/total)) print(total) 
       
0.00774978275714
0.212202359833
0.126347516452
0.074760625706
859637
0.00774978275714
0.212202359833
0.126347516452
0.074760625706
859637
div3 = 0 div5 = 0 div7 = 0 div11 = 0 total = 0 for i in srange(0,100000): templist = Hailstone(i) for j in templist: if j%3 == 0: div3+=1 if j%5 ==0: div5+=1 if j%7 == 0: div7+=1 if j%11 == 0: div11+=1 total+=1 print(float(div3/total)) print(float(div5/total)) print(float(div7/total)) print(float(div11/total)) print(total) 
       
0.00614176974661
0.210072001173
0.130852099263
0.0791114597476
10853712
0.00614176974661
0.210072001173
0.130852099263
0.0791114597476
10853712
div3 = 0 div5 = 0 div7 = 0 div11 = 0 total = 0 for i in srange(0,1000000): templist = Hailstone(i) for j in templist: if j%3 == 0: div3+=1 if j%5 ==0: div5+=1 if j%7 == 0: div7+=1 if j%11 == 0: div11+=1 total+=1 print(float(div3/total)) print(float(div5/total)) print(float(div7/total)) print(float(div11/total)) print(total) 
       
0.00503388579053
0.208534736386
0.132961028396
0.0814156021487
132434272
0.00503388579053
0.208534736386
0.132961028396
0.0814156021487
132434272
div3 = 0 div5 = 0 div7 = 0 div11 = 0 total = 0 for i in srange(0,10000): templist = Hailstone(i) for j in templist: if j%3 == 0: div3+=1 if j%5 ==0: div5+=1 if j%7 == 0: div7+=1 if j%11 == 0: div11+=1 total+=1 print(float(div3/total)) print(float(div5/total)) print(float(div7/total)) print(float(div11/total)) print(total) 
       
0.00774978275714
0.212202359833
0.126347516452
0.074760625706
859637
0.00774978275714
0.212202359833
0.126347516452
0.074760625706
859637
div3 = 0 div5 = 0 div7 = 0 div11 = 0 total = 0 for i in srange(0,100000): templist = Hailstone(i) for j in templist: if j%3 == 0: div3+=1 if j%5 ==0: div5+=1 if j%7 == 0: div7+=1 if j%11 == 0: div11+=1 total+=1 print(float(div3/total)) print(float(div5/total)) print(float(div7/total)) print(float(div11/total)) print(total) 
       
0.00614176974661
0.210072001173
0.130852099263
0.0791114597476
10853712
0.00614176974661
0.210072001173
0.130852099263
0.0791114597476
10853712
div3 = 0 div5 = 0 div7 = 0 div11 = 0 total = 0 even = 0 for i in srange(0,100000): templist = Hailstone(i) for j in templist: if j%3 == 0: div3+=1 if j%5 ==0: div5+=1 if j%7 == 0: div7+=1 if j%11 == 0: div11+=1 if j%2==0: even+=1 total+=1 print(float(div3/total)) print(float(div5/total)) print(float(div7/total)) print(float(div11/total)) print(float(even/total)) print(total) 
       
0.00614176974661
0.210072001173
0.130852099263
0.0791114597476
0.662341510444
10853712
0.00614176974661
0.210072001173
0.130852099263
0.0791114597476
0.662341510444
10853712
div3 = 0 div5 = 0 div7 = 0 div11 = 0 total = 0 even = 0 for i in srange(0,10000): templist = Hailstone(i) for j in templist: if j%3 == 0: div3+=1 if j%5 ==0: div5+=1 if j%7 == 0: div7+=1 if j%11 == 0: div11+=1 if j%2==0: even+=1 total+=1 print(float(div3/total)) print(float(div5/total)) print(float(div7/total)) print(float(div11/total)) print(float(even/total)) print(total) 
       
0.00774978275714
0.212202359833
0.126347516452
0.074760625706
0.66030429123
859637
0.00774978275714
0.212202359833
0.126347516452
0.074760625706
0.66030429123
859637