OFFSET
1,1
COMMENTS
It seems that all 3^x+1 trajectories reach 1; this has been verified up to 10^9. Once a 3^x+1 trajectory reaches 1, it repeats the following cycle: 1, 4, 2, 1, 4, 2, 1, ...
LINKS
Wikipedia, Collatz conjecture
FORMULA
a(n) = floor(log_2(n)) if n is even, 3^n+1 if n is odd.
EXAMPLE
For n = 5, a(5) = 3^5+1 = 244, because 5 is odd.
For n = 6, a(6) = floor(log_2(6)) = 2, because 6 is even.
PROG
(Python)
from math import floor, log
def a(n): return 3**n + 1 if n % 2 else int(floor(log(n, 2)))
print([a(n) for n in range(1, 51)])
(Python)
'''
Program that confirms that 3^x+1 trajectories end with 1.
We avoid the expensive 3^n+1 calculation based on the following:
- 3^n is not a power of two (for n >= 1).
- 3^n+1 is not a power of two (for n > 1) because of the Catalan Conjecture, which was proven in 2002.
- Thus, floor(log2(3^n+1)) == floor(log2(3^n)) == floor(n*log2(3)) for n > 1.
Thanks to Clark R. Lyons for this optimization.
'''
from math import floor, log
log2_of_3 = log(3, 2) # 16 digits after the decimal point.
max_n = 10**15 / 2 # Larger values multiplied by log2_of_3 may have rounding errors.
def check_trajectory(n):
while n > 1:
if n % 2 == 0:
n = int(floor(log(n, 2)))
else:
if n > max_n:
raise ValueError(str(n) + " is too large to be multiplied by log2_of_3")
n = int(floor(n * log2_of_3))
n = 1
while n <= 1000000000:
check_trajectory(n)
n += 1
CROSSREFS
KEYWORD
nonn
AUTHOR
Robert C. Lyons, Aug 08 2020
STATUS
approved