Message Boards Message Boards

4
|
1052 Views
|
9 Replies
|
21 Total Likes
View groups...
Share
Share this post:

Is there a ways to make a collapsible tree? Using Collatz Conjecture rules?

Posted 3 months ago

I'm trying to figure out how to make / use Trees in Mathematica. I've made my own very rough tree in Draw.io, but I'd like a more systematic / automatic way of doing it in Mathematica.

But I'm not sure how, or whether Mathematica currently supports the end-product I want to create.

My idea is basically to dynamically create an interactive Collatz tree, preferably in a very specific visual / functional way.

The Collatz conjecture uses two rules:

If an integer is 'even': divide by 2. If an integer is 'odd': multiply it by 3 and then add 1. [Thus making an even integer.]

The conjecture is that any number subjected repeatedly to those rules will eventually lead to 1 and/or the 1 --> 4 --> 2 --> 1 loop.

My thinking is to do the reverse, and create an expandable/collapsible Collatz Tree from the bottom up, starting at 1.

"Trunks" would be vertical series starting at an odd number [1, or the bottom of a "Branch"], and then proceeding upward by multiplying that odd number by ascending powers of 2, essentially to infinity.

"Branches" would be a line to the right at any number where a 3x+1 function would produce that number [or, in reverse, that number minus one, then divided by 3, results in an integer].

The result of each "Branch" [an odd number] would be the start of a new vertical "Trunk."

My notion is to have "branches" be 'collapsible.'

So, you'd basically start with just the vertical "powers of 2" Trunk, and then specific numbers would have a control to expand/collapse a new Branch at that number. Not all numbers have branches as not all numbers would result in an integer as a result of subtracting 1 and then dividing by 3. [Basically works out to every 2nd even number having a Branch.]

I'm just not sure how to go about creating such a tree in Mathematica. Generally, or with collapsible Branches.

How, in general, do you create a Tree, or Graph, or Flow Chart, or whatever, based on the two Collatz rules? [If x is Even, do '1'; if x is Odd do '2'?]

Does Mathematica support 'Collapsible/Expandable' controls in graphs / trees / demonstration projects?

Does Mathematica support kind of formatting how the "Tree" or "Flow Chart" or whatever gets built? Can you specify that like the "odd number times powers of 2" Trunk should be arranged vertically, while the Branches [((x-1)/3) {if the result is an integer}] should be a horizontal node, which then connects to the bottom [odd number] of another vertical Trunk?

POSTED BY: Michael Gmirkin
9 Replies

POSTED BY: Brad Klee

POSTED BY: Ian Ford

POSTED BY: Ian Ford
Posted 3 months ago

Cool. :) Perhaps a bit above my semi-novice pay grade.

Minor note, looks like the OddQ function has an extraneous "divide by 2" in it?

"(3n+1)/2" rather than just "(3n+1)" of Collatz, yeah?

E.g. 3 should hook into 10, not 5. 5 should hook into 16, not 8. etc.

Otherwise, it seems like that collatzTreeGraph[25] graph gets pretty close to what I'm looking for.

Ideally, for me anyway, the "Trunks" would basically go straight up on the left, and the "Branches" would branch to the right, and then basically start a new Trunk. If it's definable which direction things go. Just what makes sense to me, anyway. :) As opposed to having them kinda' go off in all different directions.

Ideally, expanding a higher branch from the same trunk would move any lower branches to the right to make room. If/when stuff gets put in programmatically for expandable/collapsible stuff. Just thinking out loud, from the "way my brain works" department. ;)


I tried fiddling with things in Mathematica to remove the /2 from the OddQ function, but it seemed to break things. So, maybe I did something incorrectly? Not sure...

POSTED BY: Michael Gmirkin

POSTED BY: Ian Ford
Posted 3 months ago

For the other way around, not sure why there's a 2 in the "(2n-1)/3"?

Shouldn't that be "(n-1)/3" and making sure the result is both an integer & odd?

I think this fixes that?

anticollatz[n_] := With[{m = (n - 1)/3}, If[IntegerQ[m] && OddQ[m] && m != 1 && m != 0, {2 n, m}, {2 n}]]

collatzTree[level_] := NestTree[anticollatz, 1, level]

collatzTree[15]
POSTED BY: Michael Gmirkin

For odd n, n is followed by 3n + 1, which is then followed by (3n + 1) / 2. My original comment skipped the intermediate 3n + 1 and went straight to (3n + 1) / 2, so the reverse direction also skipped from n = (3m + 1) / 2 to m = (2n - 1) / 3, which is necessarily odd, see my reply to your other comment for the fixed version.

POSTED BY: Ian Ford
Posted 3 months ago

I hear ya'.

I just like seeing each step in the chain (exactly how numbers relate to other numbers), without skipping steps. ^_^

~MG

POSTED BY: Michael Gmirkin

See also: OEIS A127824 : "The Collatz conjecture asserts that every positive integer occurs in some row of this triangle". And here's another student project on generalized collatz.

POSTED BY: Brad Klee
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract