Ruud H.G. van Tol on Wed, 29 Dec 2021 03:35:37 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

fun with Collatz



\\ 4-dimensional approach ;)

im_run1( RI= 23 )=
{
  my
  ( v0= RI
  , v0r= real(v0)
  , v0i= imag(v0)
  , p2c= if(frac(v0r), 1/frac(v0r), if(v0i,1,0)) \\ halving counter
  , p3c= if(frac(v0i), 1/frac(v0i), if(v0i,1,0)) \\ tripling counter
  , c2=  if( v0i, floor(v0i), floor(v0r) )
);

  c2/= 2^valuation(c2, 2);  \\ oddify

  my
  ( c3= c2 \\ (p2c*x + c2) -> (p3c*x + c3)
  , n=  (c2 - 1) / 2
  );
  if( !n, c2= p2c= p3c= 0; c3= 1 );

  while
  ( (c3 > 1) && (c3 >= c2) \\ stop-condition
  , c3= 3 * c3 + 1;
    p3c++;
    while
    ( 0 == (c3 % 2)
    , c3/= 2;
      p2c++;
      if(c3 < c2, break); \\ dropper
    );
  );

  (c2 + if(p2c>1,1/p2c,0)) + I * (c3 + if(p3c>1,1/p3c,0));
};

\\ TEST: my(v= 7, i=0); while(real(v)>1, print("> ",v);
\\ if(i++>5,break); v=im_run1(v))
\\
\\ my(v= 23); while(real(v)>1, print("> ",
\\ floor(if(imag(v),imag(v),real(v)))); v=im_run1(v))
\\
\\ my(v= 9781262575275081247); while(real(v) > 1,
\\ print("> ",floor(if(imag(v),imag(v),real(v))));
\\ v=im_run1(v))

-- Ruud