cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A184615 Positive parts of the nonadjacent forms for n.

This page as a plain text file.
%I A184615 #27 Feb 25 2023 04:28:15
%S A184615 0,1,2,4,4,5,8,8,8,9,10,16,16,17,16,16,16,17,18,20,20,21,32,32,32,33,
%T A184615 34,32,32,33,32,32,32,33,34,36,36,37,40,40,40,41,42,64,64,65,64,64,64,
%U A184615 65,66,68,68,69,64,64,64,65,66,64,64,65,64,64,64,65,66,68,68,69,72,72,72,73,74,80,80,81,80,80,80,81,82,84,84,85,128
%N A184615 Positive parts of the nonadjacent forms for n.
%C A184615 This sequence together with A184616 (negated negative parts) gives the (signed binary) nonadjacent form (NAF) of n, see fxtbook link.
%C A184615 No two adjacent bits in the binary representations of a(n) are 1.
%C A184615 No two adjacent bits in the binary representations of a(n)+A184616(n) are 1.
%H A184615 Rémy Sigrist, <a href="/A184615/b184615.txt">Table of n, a(n) for n = 0..8192</a>
%H A184615 Pages 61-62 of <a href="http://www.jjj.de/fxt/#fxtbook">Matters Computational (The Fxtbook)</a>.
%F A184615 a(n) - A184616(n) = n
%F A184615 a(n) + A184616(n) = A184617(n)
%e A184615 The first few nonadjacent forms (NAF) are
%e A184615 (dots are used for zeros for better readability):
%e A184615      n     binary(n)  NAF(n)
%e A184615    0:    .......    .......      0 =
%e A184615    1:    ......1    ......P      1 =  +1
%e A184615    2:    .....1.    .....P.      2 =  +2
%e A184615    3:    .....11    ....P.M      3 =  +4 -1
%e A184615    4:    ....1..    ....P..      4 =  +4
%e A184615    5:    ....1.1    ....P.P      5 =  +4 +1
%e A184615    6:    ....11.    ...P.M.      6 =  +8 -2
%e A184615    7:    ....111    ...P..M      7 =  +8 -1
%e A184615    8:    ...1...    ...P...      8 =  +8
%e A184615    9:    ...1..1    ...P..P      9 =  +8 +1
%e A184615   10:    ...1.1.    ...P.P.     10 =  +8 +2
%e A184615   11:    ...1.11    ..P.M.M     11 =  +16 -4 -1
%e A184615   12:    ...11..    ..P.M..     12 =  +16 -4
%e A184615   13:    ...11.1    ..P.M.P     13 =  +16 -4 +1
%e A184615   14:    ...111.    ..P..M.     14 =  +16 -2
%e A184615   15:    ...1111    ..P...M     15 =  +16 -1
%e A184615   16:    ..1....    ..P....     16 =  +16
%e A184615   17:    ..1...1    ..P...P     17 =  +16 +1
%e A184615   18:    ..1..1.    ..P..P.     18 =  +16 +2
%e A184615 This sequence gives the words obtained by keeping the 'P' (sum of positive terms in rightmost column), keeping the 'M' gives A184616 (negative sum of negative terms in rightmost column).
%t A184615 bin2naf[x_] := Module[{xh, x3, c, np, nm},
%t A184615   xh = BitShiftRight[x, 1];
%t A184615   x3 = x + xh;
%t A184615   c = BitXor[xh, x3];
%t A184615   np = BitAnd[x3, c];
%t A184615   nm = BitAnd[xh, c];
%t A184615   Return[{np, nm}]];
%t A184615 a[n_] := bin2naf[n][[1]];
%t A184615 Table[a[n], {n, 0, 100}] (* _Jean-François Alcover_, May 30 2019, from PARI *)
%o A184615 (PARI)
%o A184615 bin2naf(x)=
%o A184615 { /* Compute (nonadjacent) signed binary representation of x: */
%o A184615     local(xh,x3,c,np,nm);
%o A184615     xh = x >> 1;
%o A184615     x3 = x + xh;
%o A184615     c = bitxor(xh, x3);
%o A184615     np = bitand(x3, c);  /* bits == +1 */
%o A184615     nm = bitand(xh, c);  /* bits == -1 */
%o A184615     return([np,nm]);  /* np-nm==x */
%o A184615 }
%o A184615 { for(n=0,100, v = bin2naf(n); print1(v[1],", "); ); } /* show terms */
%o A184615 { for(n=0,100, v = bin2naf(n); print1(v[2],", "); ); } /* terms of A184616 */
%o A184615 { for(n=0,100, v = bin2naf(n); print1(v[1]+v[2],", "); ); } /* terms of A184617 */
%o A184615 { for(n=0,100, v = bin2naf(n); print1(v[1]-v[2],", "); ); }  /* == n */
%Y A184615 A184616 (negated negative parts), A184617 (sums of both parts =A184615+A184616).
%Y A184615 A007302 gives the number of nonzero bits ('M' and 'P' in example).
%K A184615 nonn
%O A184615 0,3
%A A184615 _Joerg Arndt_, Jan 18 2011