r/numbertheory • u/Super_Mirror_7286 • 2h ago
How to Make Your Own Collatz Conjecture
The Collatz conjecture can be written in a slightly different way:
- If n is even: f(n) = ceil(n/2)
- If n is odd: f(n) = n + ceil(n/2)
Writing it this way lets us replace the even/odd condition with pretty much any rule we want. For example, we can take a binary sequence such as the Thue-Morse sequence and use its nth term to decide which formula to apply: the first one if it is 1, and the second one if it is 0.
The results are surprisingly interesting. Using the Thue-Morse sequence, every positive integer up to 10,000,000 eventually reaches 1 (which is a fixed point). Reversing the two conditions makes every number fall into the cycle 2 → 3 → 2.
Of course, not every binary sequence gives us such a neat result. For example, using the binary digits of √2 as the rule produces four distinct cycles.
This is python code. (Can be modified to use a different binary sequence instead of Thue-Morse)
def thue_morse(m):
return m.bit_count() % 2
def col(m, decrease_bit=1):
h = (m + 1) // 2
if thue_morse(m) == decrease_bit:
return h
else:
return m + h
def canonical(cycle):
i = cycle.index(min(cycle))
return tuple(cycle[i:] + cycle[:i])
def search_cycles(N, decrease_bit=1):
known = {}
cycles = {}
for start in range(1, N + 1):
path = []
pos = {}
x = start
while x not in pos and x not in known:
pos[x] = len(path)
path.append(x)
x = col(x, decrease_bit)
if x in pos:
cycle = canonical(path[pos[x]:])
else:
cycle = known[x]
cycles[cycle] = cycles.get(cycle, 0) + 1
for v in path:
known[v] = cycle
print("Search range:", N)
print("Number of distinct cycles:", len(cycles))
for cycle, count in sorted(cycles.items()):
print("\nCycle:", cycle)
print("Cycle length:", len(cycle))
print("Number of starting values entering this cycle:", count)
print("\nTotal starting values:", sum(cycles.values()))
search_cycles(10000, decrease_bit=1)