%I #16 Apr 17 2024 00:23:09
%S 0,0,0,1,0,1,2,4,0,1,2,4,4,6,8,11,0,1,2,4,4,6,8,11,8,10,12,15,16,19,
%T 22,26,0,1,2,4,4,6,8,11,8,10,12,15,16,19,22,26,16,18,20,23,24,27,30,
%U 34,32,35,38,42,44,48,52,57,0,1,2,4,4,6,8,11,8,10,12,15,16,19,22,26,16,18,20
%N a(n) = L(n) + a(L(n)), where L(n) = n - 2^floor(log_2(n)) (A053645).
%C a(2^j)=0. Local extrema are a(2^j-1) = 2^j-j-1 (A000295).
%H Jean-Paul Allouche and Jeffrey Shallit, <a href="http://dx.doi.org/10.1016/0304-3975(92)90001-V">The ring of k-regular sequences</a>, Theoretical Computer Sci., Vol. 98 (1992), pp. 163-197, ex. 24. (<a href="http://www.cs.uwaterloo.ca/~shallit/Papers/as0.ps">PS file on author's web page.</a>)
%F a(0)=0, a(1)=0, a(2n)=2a(n), a(4n+1)=2a(n)+a(2n+1), a(4n+3)=-2a(n)+3a(2n+1)+1.
%F a(n) = Sum_{i=0..k} i*2^e[i] where the binary expansion of n is n = Sum_{i=0..k} 2^e[i] with decreasing exponents e[0] > ... > e[k] (A272011). - _Kevin Ryde_, Apr 16 2024
%t f[l_]:=Join[l,l-1+Range[Length[l]]]; Nest[f,{0},7] (* _Ray Chandler_, Jun 01 2010 *)
%o (PARI) a(n)=if(n<2,0,if(n%2==0,2*a(n/2),if(n%4==1,2*a((n-1)/4)+a((n+1)/ 2),-2*a((n-3)/4)+3*a((n-3)/2+1)+1)))
%o (PARI) a(n) = my(v=binary(n),c=-1); for(i=1,#v, if(v[i],v[i]=c++)); fromdigits(v,2); \\ _Kevin Ryde_, Apr 16 2024
%Y Cf. A000295, A272011, A298043.
%K easy,nonn
%O 0,7
%A _Ralf Stephan_, May 05 2003
%E Extended by _Ray Chandler_, Mar 04 2010