login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

a(n) is the sum of digits of n in signed binary nonadjacent form.
2

%I #27 Jul 16 2021 01:34:57

%S 0,1,1,0,1,2,0,0,1,2,2,-1,0,1,0,0,1,2,2,1,2,3,-1,-1,0,1,1,-1,0,1,0,0,

%T 1,2,2,1,2,3,1,1,2,3,3,-2,-1,0,-1,-1,0,1,1,0,1,2,-1,-1,0,1,1,-1,0,1,0,

%U 0,1,2,2,1,2,3,1,1,2,3,3,0,1,2,1,1,2,3,3,2

%N a(n) is the sum of digits of n in signed binary nonadjacent form.

%H Joerg Arndt, <a href="http://www.jjj.de/fxt/#fxtbook">Matters Computational - Ideas, Algorithms, Source Code</a>, 2011, Springer, pp. 61-62.

%H Helmut Prodinger, <a href="http://www.emis.de/journals/INTEGERS/papers/a8/a8.Abstract.html">On binary representations of integers with digits -1,0,1</a>, Integers 0 (2000), #A08.

%F a(n) = hammingweight(A184615(n)) - hammingweight(A184616(n)). - _Joerg Arndt_, Jun 13 2020

%t BBN[a_] := Module[{n = a, b}, b = IntegerDigits[n, 2]; b = Prepend[b, 0];

%t l = Length[b];

%t Do[If[b[[i]] == 2, b[[i]] = 0; b[[i - 1]]++,

%t If[b[[i]] == 1,

%t If[b[[i + 1]] == 1, b[[i - 1]]++; b[[i]] = 0;

%t b[[i + 1]] = -1]]], {i, l - 1, 2, -1}];

%t If[b[[1]] == 0, b = Delete[b, 1]]; b]

%t Table[a = BBN[i]; sod = 0; l = Length[a];

%t Do[sod = sod + a[[j]], {j, 1, l}]; sod, {i, 0, 83}]

%o (PARI)

%o bin2naf(x)=

%o { /* Compute (nonadjacent) signed binary representation of x: */

%o local(xh, x3, c, np, nm);

%o xh = x >> 1;

%o x3 = x + xh;

%o c = bitxor(xh, x3);

%o np = bitand(x3, c); /* bits == +1 */

%o nm = bitand(xh, c); /* bits == -1 */

%o return([np, nm]); /* np-nm==x */

%o }

%o a(n) = my(b=bin2naf(n)); return(hammingweight(b[1])-hammingweight(b[2]));

%o vector(99,n,a(n-1)) \\ _Joerg Arndt_, Jun 13 2020

%Y Cf. A000120, A001045, A007302, A184615, A184616.

%K base,easy,sign

%O 0,6

%A _Lei Zhou_, May 16 2020