Collatz Sequence Visualization     misc

Leonid Petrov


Simulation Info

Collatz Sequence Visualization     misc

Leonid Petrov

The Collatz conjecture is one of the most famous unsolved problems in mathematics. Given any positive integer:

  • If the number is even, divide it by 2
  • If the number is odd, multiply it by 3 and add 1
The conjecture states that regardless of the starting number, the sequence will always reach 1.

Input
Statistics

Sequence Length: -

Highest Value: -

Steps to Reach 1: -

Visualization
Sequence
Collatz Visualization in Mathematica
Collatz Mathematica Image
Mathematica Code for the image

SetAttributes[Collatz, {Listable}];
Collatz[n_, e_, a_, f_] := Module[{nn = n, bag = Internal`Bag[]}, While[nn =!= 1, Internal`StuffBag[bag, nn]; nn = If[EvenQ[nn], nn/2, 3 nn + 1] ];
   Internal`StuffBag[bag, nn];
   With[{seq = Reverse[Internal`BagPart[bag, All]]}, AnglePath[Transpose[{seq/(1 + seq^e), a*(f - 2 Mod[seq, 2])}]]]];
astroIntensity[l_, s_, r_, h_, g_] :=
  With[{psi = 2 Pi (s/3 + r l), a = h l^g (1 - l^g)/2}, l^g + a*{ {-0.14861, 1.78277}, {-0.29227, -0.90649}, {1.97294, 0.0} }.{Cos[psi], Sin[psi]}];
Manipulate[
 DynamicModule[{seq},
  seq = ControlActive[Collatz[Range[5000, 5020], e, a, f], Collatz[RandomInteger[1000000, {n}], e, a, f]];
  Graphics[{Opacity[o], Thickness[ControlActive[0.01, 0.003]],
    Line[seq,
     VertexColors -> (Table[
          astroIntensity[l, s, r, h, g], {l, 0, 1,
           1/(Length[#] - 1)}] & /@ seq)]}, ImageSize -> 500]
  ]
 , "Colors", { {s, 2.49}, 0, 3}, { {r, 0.76}, 0, 5}, { {h, 1.815}, 0, 2}, { {g, 1.3}, 0.1, 2}, { {o, 0.5}, 0.1, 1},
 Delimiter,
 "Structure", { {e, 1.3}, 0.9, 1.8}, { {a, 0.19}, 0.1, 0.3}, { {f, 0.7}, 0.1, 1.5}, {n, 300, 5000, 1} ]
        

code

(note: parameters in the code might differ from the ones in simulation results below)

Dear colleagues:
Feel free to use code (unless otherwise specified next to the corresponding link), data, and visualizations to illustrate your research in talks and papers, with attribution (CC BY-SA 4.0). Some images are available in very high resolution upon request. I can also produce other simulations upon request - email me at lenia.petrov@gmail.com
This material is based upon work supported by the National Science Foundation under Grant DMS-2153869