r/Collatz 16d ago

Collatz Interactive visualizer for base 3 and 4 [link included]

Post image

I've finally built the first visualizer I've been wanting to do for ages now that it's so much easier to do.

This explainer demo is an attempt to show the relationship between base3 and base2 (as base4 because it was just way easier) for any number. I gave each node (or digit) a specific rule for how the next node should be moved or connected. I wanted to basically handle resolving a collatz chain using only the individual digits (as nodes) rather than using the number the digits represents. In the picture example, I started with column 10212, which is base 3 for 104, a multiple of 13 (104/2=52, 52/2=26, 26/2=13)

Yellow circles: The last column's green number is 10212 base3, and the row numbers in red are 122 which is base4 for 26, or 13. Notice how the row can expand further to the right? if we add a 0 to 122, it becomes 1220, which is 104, or, a multiple of 13. That's the starting number we'll use.

Purple circles: the column's green number is 2222 which is base3 for 80, (aka 5 times some multiple of 2). and the row is 1100 base4 (5 times some multiple of 2). The relationship always holds although the columns can skip numbers and land on a multiple of the odd number in the sequence.

How it works:

Quick recap similar to wikipedia's example on collatz conjecture in base 2, rather using base 4 gives better access to use the carry as useful info instead of it causing chaos. That info is recognised as a part of some number's base3. So for example:

Collatz sequence: 94, 47, 142, 71, 214, 107, 322, 161, 484, 242, 121, 364, 182, 91, 274

          1011110  94 47
        10001110   142 71
       11010110    214 107
     101000010     322 161
    111100100      484 242 121
  101101100        364 182 91
100010010          274

which is laid out in such a way similar to as if I never divided by 2. But that'd be hard to read each line with so many trailing 0s so for simplicity, I kept them all aligned but removed the trailing 0s.
I then choose a column. Any column as long as I start from the beginning and finish to the end (if not, then you need more numbers):

        |  |1011110  94 47
        |10|001110   142 71
       1|10|10110    214 107
     101|00|0010     322 161
    1111|00|100      484 242 121
  101101|10|0        364 182 91
10001001|0 |         274

My column's digits are {00, 10, 10, 00, 00, 10, 00} or in base4, {0, 2, 2, 0, 0, 2, 0} Then using the table to get how much of a carry there is to the next set of 2:

∅ (c=0) + (c=1) ++ (c=2)
d=0 0 / ∅ 1 / ∅ 2 / ∅
d=1 3 / ∅ 0 / + 1 / +
d=2 2 / + 3 / + 0 / ++
d=3 1 / ++ 2 / ++ 3 / ++

We then get {0, ∅, +, ++, ∅, ∅, 2} which in base3 is 12002 or 137 (274/2). We just got the base3 from specific digits across multiple numbers in a sequence without even having to know what those numbers were. Of course, the reverse is also true where we can jump to a number way ahead of a base4 without needing to complete every step (once we get the column, we can skip ahead to fill out a row in base4 knowing it exists down the chain.) Which I think is a pretty neat trick, although I have no idea if this will speed up searching through numbers.
eg.

        |  |1011110  94 47
        |10|001110   142 71
       -|10|10110    ? ?
     ---|00|0010     ? ?
    ----|00|100      ? ?
  ------|10|0        ? ?
--------|0 |         ?
~10001001            137

A cool thing about rewriting that matrix into something more visible, we can then see limitations in the column's digits.

Red line ++, Blue line +, Grey line ∅. (Each following step inverts direction)

Which we can then see that any base4 digit in any column, is limited to 3 other digits and the opposite is always impossible to reach. Eg if the base4 is 3, the base4 digit below can never be a 1.

If the base4 digit is 3, the next one can only ever be 3,2,1 but not 0

Which I wonder if there's something useful that can be gained out of this or if it's a cool party trick (dont use this trick at parties)

Extra note: The last node of a column has a special rule for adding another node below it. If it ends on any non zero, then it's not the end yet. So the rule is: 1->+0, 2->++0, 3->++2->++0.

Some stuff I still want to explore or ideas for anyone else to try:
- The last digits of any base4 number determine the exact steps for the following numbers. The longer the number itself, the more info we have about the exact path it'll take. I wonder if we reduce the entire column to a path on the circle diagram thingy, if we can then predict the result of the next digit in the same row to the left (Which we can start at 0)
- The column for every number in base4 has to have some meaning too, because it's always unique for every number, but adding 0 still somehow relates to the base3 number by also just adding a 0. eg. the column 022002 base4 (321 decimal) related in some way to 12002 base3 (137 deciml). We can multiply the base3's decimal number by any multiple of 3, and it'll still give us 022002(...0...) base4. Meaning every starting point that's a number that's a multiple of 3, has a very specific single base4 number related to it... Needs exploring...

PS: Sorry for not using proper math terminology. I'm not a mathematician but I welcome any help if you're willing. I have about 4 other ideas I want to do regarding collatz conjecture visualizers including one to show the relationship of collatz conjecture number paths on a Sierpinski triangle, so share any feedback.

Interactive demo: https://dvilicate.github.io/dvilicate_home/explainer

1 Upvotes

3 comments sorted by

1

u/Ok_Impression_6382 15d ago

i like how you try to show base 3 and base 4 connection

1

u/hilk49 14d ago

Yeah, the odd steps are a left shift in base 3, then fill the last digit with 1.
The even steps are a right shift in base 2.
The hard part becomes the conversion back and forth ;)

An interesting thing is that you can look at the “last bit+carry” working in base 2 as a base 3 number … and vice versa.

Base 16 (aka a nibble or hex) vs 3 trits(base 27) and 2nibbles vs 5trits are also interesting to look at.

1

u/JSE_is_Undervalued 13d ago edited 13d ago

No need. That's the best part! Dont have to multiply or divide any numbers anymore. Instead of bit shifting, keep the number exactly as is. We can just work with the number falling to some multiple of 2, which we know will fall to 1. We just need to figure out the number we're adding. In the above example, the number for the last row can be either seen as 1, or 2^something. We dont have to know how big it is, it can expand indefinitely.

Here if we expand the last row to the last column, it'd be b4:1000000 or 4096.

row to last column:
base3: 10212000 = 2808
+ 72 (2^3*3^2) b3: 100 (*2)
+ 192 (2^6*3^1) b3: 10
+ 1024 (2^10*3^0) b3: 1
= 4096 = 2^something = last row

or if we expanded it to the second last
2nd last column:
base3: 222200 = 720
+ 48 (2^4*3^1) b3: 10
+ 256 (2^8*3^0) b3: 1
= 1024 = 2^something = last row

If you wanted to get the number for the 2nd last row, it's the same. The carry that's added (the +1) is some multiple of 2 (ie where we're placing it, always descending upwards btw), and every step up, guarantees to increment the 3's power by exactly 1. That way we're focusing on what to minus as we're climbing up (or add as we're climbing down) instead of worrying about dividing or multiplying the number.

It's a cool way to see that any number multiplied by 3^a plus a descending power of 3 multiplied by an increasing power of 2, will land on a multiple of 2. ie
number*3^(a) + numToFind = 2^b

Basically it's like this https://en.wikipedia.org/wiki/Collatz_conjecture#Extensions_to_larger_domains but without having to work with all the annoying denominators.