Ruud H.G. van Tol on Wed, 29 Dec 2021 04:50:32 +0100


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

Re: fun with Collatz




On 2021-12-29 03:35, Ruud H.G. van Tol wrote:

\\ 4-dimensional approach ;)

im_run1( RI= 23 )=
{
   my
   ( v0=  RI
   , v0r= real(v0)
   , v0i= imag(v0)
   , p2=  if(frac(v0r), 1/frac(v0r), if(v0i,1,0)) \\ halving counter
   , p3=  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 \\ (p2*x + c2) -> (p3*x + c3)
   , n=  (c2 - 1) / 2
   );
   if( !n, c2= p2= p3= 0; c3= 1 );

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

   (c2 + if(p2>1,1/p2,0)) + I * (c3 + if(p3>1,1/p3,0));
};

Example usage:

{
my
( v= 9781262575275081247
, w= 1+floor(log(v)/log(10)) \\ digits
);
while
( real(v) > 1
, my(vr=real(v), vi=imag(v), p2=frac(vr), c2=floor(if(vi,vi,vr)));
  p2= if(p2, 1/p2, 0);
  printf("> %*s  2^%s\n", w, c2, p2);
  v=im_run1(v);
)
}

-- Ruud