Visualization of Collatz Conjecture using Python
The Collatz Conjecture
The Problem
The conjecture is that for every positive integer $n$, there exists a $k$ such that $T^k(n) = 1$.
Let us consider an example.
As mentioned above, the conjecture states that this is true for any positive integer n. But what makes this problem interesting is that even after 60 years since its proposal nobody has been able to prove (or disprove) it. Mathematicians say the "Mathematics is yet not ready to tackle such problems." So far the conjecture has been checked for all starting values up to $87 \times 2^{60}$. All initial values tested so far eventually end up in 1.
Program
Visualization
- Stopping time
Python program to compute the stopping time $k$ for each $n$ and plot them against $n$ in a graph.
Program
#Program to compute the stopping time for each n and to plot it in a graph.
import matplotlib.pyplot as plt
def collatz(x):
a = [x]
while x != 1:
if x % 2 == 0:
x = x/2
else:
x = 3*x + 1
a.append(x)
return(a)
x=[]
y=[]
for i in range(1,10000):
a = collatz(i)
x.append(i)
y.append(len(a))
plt.plot(x,y,"o")
plt.show()
We can see a pattern in the obtained graph. - The highest value in the iteration
For each $n$, the composition of the function $T$ yields an upper bound. For example, 16 in the case of n = 6. Let's plot the graph of this largest value obtained in the iteration for each n and try to figure out some patterns from the graph.|
Program
#Highest value in the iteration
import matplotlib.pyplot as plt
def collatz(x):
a = [x]
while x != 1:
if x % 2 == 0:
x =x/2
else:
x = 3*x + 1
a.append(x)
return(a)
b = []
c = []
for i in range(1,1000):
c.append(max(collatz(i)))
b.append(i)
plt.plot(b,c,"o")
plt.show()
Excellent work 👌
ReplyDeleteLet us consider the (4,2,1) cycle on the positive side of Z. Is it isolated ? No. This cycle is the root of a tree growing indefinitely above it. Let us look at the negative side of Z. There are (at least) 3 cycles. Are they isolated ? No, of course. Each cycle is the root of a tree growing indefinitely above it. So let us think a few seconds and state together : Any number is within a tree which expands infinitely. There can be nothing like a cycle with no branches developing out of its 1 mod 3 and 2 mod 3 valued integers. Go down the Collatz algorithm and you get one number at each step of course, but go up and you get 1 or 2 numbers. Take a numeric example and see how many numbers you get after m steps up. Take literal n and write modulo 6’s conditions for the tree growth. Starting from any number you will find approximatively the same population after x steps upwards for sufficient large x. Let us take n not equal to 0 mod 3 which is not in the (4,2,1) tree (and if n is equal to 0 mod 3, just take 3n+1). This number is the root of a tree that develops with the approximate speed of the (4,2,1) tree. Let us have r the density of (4,2,1) tree in the set N. Then the tree to which n belongs has an α.r density in N with α ≠ 0. So this extra tree, with n on its base, has a non-zero density in N. But Riho Terras (Acta Arithmetica. Volume: 30, Issue: 3, page 241-252; ISSN: 0065-1036) proved, as soon as 1976, that the (4,2,1) tree is of density 1 in N, so that α.r+r = α+1 is now the density of our two trees, so we must have α = 0, which is a contradiction. Therefore there is only one tree in N and no exception n whatsoever.
ReplyDeleteLet us note also the Pascal triangle based characteristics of the tree expansion (within appendix 5 of given reference).
https://hubertschaetzel.wixsite.com/website Terras sheet