Collatz Variation: The Prime Frog

217 Views Asked by At

On codegolf.SE, there was a post involving a Collatz variation called "the prime frog". Users were asked to create code that iterated the function

$$f(n)=\bigg\{\begin{array}{cc}2n-1 & \mathrm{if\ }n\mathrm{\ is\ prime} \\ n-d &\mathrm{otherwise}\end{array}$$

where in the second case, $d$ is th largest prime divisor of $n$. Users were asked to output whether the function (given a particular input) got stuck in the loop

$$3\to 5\to 9\to 6\to 3$$

or the loop

$$19\to 37\to 73\to 145\to 116\to 87\to 29\to 57\to 38\to 19.$$

My question is: Can it be shown that this always terminates in one of these two loops? According to Keyu Gan on the original post, it has been tested for primes up to $10^8$.

Unsurprisingly, I haven't been able to make much progress on this. The only things I've figured out are relatively elementary:

  1. If a composite number $pm$ has $m\leq p$ ($p$ is prime), the sequence will reduce down to $p$. Specifically, for a product of primes $pq$, the sequence will reduce to the larger of the two primes.

  2. If $p$ is the largest prime dividing $n$, the next prime in the sequence formed by iterating $n$ will be $\geq p$.

Any ideas?

1

There are 1 best solutions below

3
On

I do not know enough about prime numbers and the Prime Number Theorem to give a definite response, but I can generally explain the behavior of the prime frog algorithm and explain how you could break it.

$2n-1$ is a Collatz Rule that takes its odd starting numbers $n$ to infinity. This occurs because every odd number is iterated to another odd number, thus never performing $n/2$ or reducing. This rule is convenient for 'the prime frog' algorithm because all primes are odd, but not all odd numbers are primes (except for 2, but 2 goes to 3 so who cares?)

The second part of the algorithm is $n-d$, which sometimes reduces down to $d$. When it does not reduce to $d$, it will filter through different $n(d)$ until it reaches a larger, final prime factor.

The "decreasing" action will reduce a number $n$ by a minimum of 50%, assuming it reduces down to the original $d$ of $n$. If the reduction leads to another prime number, it is possible the operation $2n-1$ can make up for it. This would only occur however if less than roughly 50% reduction of the original composite number occurred once you reach a prime number. Seeing how 'the prime frog' conditions are true up to $10^8$, this may be a rare occurrence at best.

However, overall reduction or growth is based on how many times the operation $2n-1$ reaches another prime number and how much of the previous composite number was reduced. This relationship of increasing and decreasing is different than that of $3n+1$, and has more to do with how many times prime numbers will line up after performing $2n-1$ and the factorization of the numbers during the process and afterwards.

Unsurprisingly, a Collatz rule loop occurs when the amount of "decreasing" "cancels out" with the amount of "increasing". Since prime numbers are setting the rules for how much change happens when, it is going to be difficult to predict, much more prove the existence of other loops. Therefore, it is completely possible other loops are out there.

Due to this algorithm's unpredictability in how much a composite number reduces, it is possible the right numbers could recreate the overall "increasing" behavior of $5n+1$. 'The prime frog' algorithm could also wander off to infinity by performing $2n-1$ forever. I do not know if this true, but the Prime Number Theorem could be used to figure out if a string of prime numbers can or can not exist. I can at least admit the operation $2n-1$ for any $n$ will always create another number $k$ with a prime factorization that does not contain any of $n$'s prime factors or ever be divisible by 2.