%I #64 Oct 22 2021 23:25:31
%S 0,1,2,5,4,7,10,19,8,11,14,23,20,29,38,65,16,19,22,31,28,37,46,73,40,
%T 49,58,85,76,103,130,211,32,35,38,47,44,53,62,89,56,65,74,101,92,119,
%U 146,227,80,89,98,125,116,143,170,251,152,179,206,287,260,341,422,665,64,67
%N Offsets of the terms of the nodes of the reverse Collatz function.
%C Create a binary tree starting with x. To follow 0 from the root, apply f(x)=2x. To follow 1, apply g(x)=(2x-1)/3. For example, starting with x, the string 010 {also known as f(g(f(x)))}, you would get (8x-2)/3. These expressions represent the reverse Collatz function and will provide numbers whose Collatz path may include x. These expressions will all be of the form (2^a*x-b)/3^c. This sequence concerns b. What makes b interesting is that if you draw the tree, each level of the tree will have the same sequence of values for b. The root of the tree x, can be written as (2^0*x-0)/3^0, which has the first value for b. Each subsequent level contains twice as many values of b.
%C This sequence is 0 followed by a permutation of A213539, and therefore consists of 0 plus the elements of A116640 multiplied by 2^k, where k >= 0. E.g., 1, 5, 7, 19 becomes 0, 2^0*1, 2^1*1, 2^0*5, 2^2*1, 2^0*7, 2^1*5, 2^0*19, ... - _Joe Slater_, Dec 19 2016
%C When this sequence is arranged as an irregular triangle the sum of each row a(2^k)...a(2^(k+1)-1) equals A081039(2^k). The cumulative sum from a(0) to a(2^k-1) equals A002697(k). - _Joe Slater_, Apr 12 2018
%H Alois P. Heinz, <a href="/A119733/b119733.txt">Table of n, a(n) for n = 0..16383</a>
%H Víctor Martín Chabrera, <a href="https://upcommons.upc.edu/handle/2117/133344">An algebraic fractal approach to Collatz Conjecture</a>, Bachelor tesis, Universitat Politècnica de Catalunya (Barcelona, 2019), see lemma 6.1 with a(n) = r(A005836(n)).
%F a(0) = 0, a(2*n + 1) = 2*a(n) + 3^wt(n) = 2*a(n) + A048883(n), a(2*n) = 2*a(n), where wt(n) = A000120(n) = the number 1's in the binary representation of n.
%F a(k) = [z^k] 1 + (1/(1-z)) * Sum_{s=0..n-1} 2^s*z^(2^s)*(1 - z^(2^s)) * Product_{r=s+1..n-1} (1 + 3*z^(2^r)), for 0 < k <= 2^n-1. - _Wolfgang Hintze_, Jul 28 2017
%F a(n) = Sum_{i=0..k} 2^e[i] * 3^i where binary expansion n = 2^e[0] + 2^e[1] + ... + 2^e[k] with descending e[0] > e[1] > ... > e[k] (A272011). [Martín Chabrera lemma 6.1, adapting index i] - _Kevin Ryde_, Oct 22 2021
%e a(1) = 1 = 2 * 0 + 3^0 since 0 written in binary contains no 1's.
%p a:= proc(n) `if`(n=0, 0, `if`(irem(n, 2, 'r')=0, 0,
%p 3^add(i, i=convert(r, base, 2)))+2*a(r))
%p end:
%p seq(a(n), n=0..127); # _Alois P. Heinz_, Aug 13 2017
%t a[0] := 0; a[n_?OddQ] := 2a[(n - 1)/2] + 3^Plus@@IntegerDigits[(n - 1)/2, 2]; a[n_?EvenQ] := 2a[n/2]; Table[a[n], {n, 0, 65}] (* _Alonso del Arte_, Apr 21 2011 *)
%o (Perl) # call with n to get 2^n values
%o $depth=shift; sub funct { my ($i, $b, $c) = @_; if ($i < $depth) { funct($i+1, $b*2, $c); funct($i+1, 2*$b+$c, $c*3); } else { print "$b, "; } } funct(0, 0, 1); print " ";
%o (Python)
%o from sympy.core.cache import cacheit
%o @cacheit
%o def a(n): return 0 if n==0 else 2*a((n - 1)//2) + 3**bin((n - 1)//2).count('1') if n%2 else 2*a(n//2)
%o print([a(n) for n in range(131)]) # _Indranil Ghosh_, Aug 13 2017
%o (PARI) a(n) = my(ret=0); if(n, for(i=0,logint(n,2), if(bittest(n,i), ret=3*ret+1<<i))); ret; \\ _Kevin Ryde_, Oct 22 2021
%Y Cf. A002697, A081039, A116623, A116640, A116641, A213539, A226383.
%K nonn
%O 0,3
%A _William Entriken_, Jun 14 2006