Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.
%I #32 Sep 28 2019 08:37:31
%S 0,1,2,23,4,13,46,1595,8,6377,26,799,92,101,3190,3283,16,401,12754,
%T 12775,52,61,1598,1643,184,51097,202,946891009738223808271,6380,6389,
%U 6566,118361376217277976035,32,204385,802,823,25508,25517,25550,6540635,104,473445504869111904137
%N Function of natural numbers satisfying the properties a(2*n) = 2*a(n) and a(2*n+1) = -3 + 2*a(3*n+2).
%C This integer sequence exists if and only if the Collatz conjecture is true. The proof is relatively trivial.
%C This is -3 times the Q function from Rozier restricted to the natural numbers.
%C The only multiple of 3 in the sequence is 0.
%H Richard N. Smith, <a href="/A309154/b309154.txt">Table of n, a(n) for n = 0..2000</a>
%H Olivier Rozier, <a href="https://arxiv.org/pdf/1805.00133.pdf">Parity sequences of the 3x+1 map on the 2-adic integers and Euclidean embedding</a>, arXiv:1805.00133 [math.DS], 2018.
%H <a href="/index/3#3x1">Index entries for sequences related to 3x+1 (or Collatz) problem</a>
%F a(2*n) = 2*a(n); a(2*n+1) = -3 + 2*a(3*n+2).
%F a(n) = -3*(n mod 2) + 2*a(A014682(n)) where A014682 is the Collatz function.
%e For n = 0, the equation a(0) = 2*a(0) implies a(0) = 0.
%e For n = 1, the equation becomes a(1) = -3 + 2*a(2) = -3 + 4*a(1), so a(1) = 1.
%e For n = 3, a bit more calculating gives a(3) = -3 + 2*a(5) = -9 + 4*a(8) = -9 + 32*a(1) = 23.
%p a:= proc(n) option remember; `if`(n<2, n,
%p `if`(irem(n, 2, 'r')=0, 2*a(r), 2*a(n+r+1)-3))
%p end:
%p seq(a(n), n=0..40); # _Alois P. Heinz_, Jul 14 2019
%t a[n_] := a[n] = If[n < 2, n, If[EvenQ[n], 2 a[n/2], 2 a[(3n + 1)/2] - 3]];
%t a /@ Range[0, 50] (* _Jean-François Alcover_, Sep 28 2019 *)
%o (Python)
%o def a(x):
%o if x <= 1: return x
%o elif x%2: return -3 + 2 * a((3*x + 1)//2)
%o else: return 2*a(x//2)
%o (PARI) a(n)=if(n<=1, n, if(n%2, -3 + 2*a((3*n+1)/2), 2*a(n/2))) \\ _Richard N. Smith_, Jul 16 2019
%Y Cf. A014682.
%K easy,nonn
%O 0,3
%A _Jan Met den Ancxt_, Jul 14 2019