login
The 1's in the binary expansion of a(n) encode the distances between the 1's in the binary expansion of n.
1

%I #17 Oct 18 2021 01:38:54

%S 0,1,1,3,1,5,3,7,1,9,5,15,3,15,7,15,1,17,9,27,5,21,15,31,3,27,15,31,7,

%T 31,15,31,1,33,17,51,9,45,27,63,5,45,21,63,15,47,31,63,3,51,27,59,15,

%U 63,31,63,7,63,31,63,15,63,31,63,1,65,33,99,17,85,51

%N The 1's in the binary expansion of a(n) encode the distances between the 1's in the binary expansion of n.

%C The bit 2^d is set in a(n) iff for some e >= 0, the bits 2^e and 2^(e+d) are set in n.

%C This sequence has similarities with A067398; here we take the absolute differences, there the sums, of indices of 1's in binary expansions.

%C All terms are odd, except a(0) = 0.

%H Rémy Sigrist, <a href="/A348363/b348363.txt">Table of n, a(n) for n = 0..8192</a>

%H Rémy Sigrist, <a href="/A348363/a348363.png">Colored scatterplot of the first 2^20 terms</a> (where the color is function of the 2-adic valuation of n, upper red pixels correspond to odd n's)

%H <a href="/index/Bi#binary">Index entries for sequences related to binary expansion of n</a>

%F a(2*n) = a(n).

%F a(n) = n iff n = 0 or n belongs to A064896.

%F a(n) = 1 iff n is a power of 2 (A000079).

%F a(n) = 3 iff n belongs to A007283.

%F a(n) = 5 iff n belongs to A020714.

%F a(n) AND n = n for any odd number n (where AND denotes the bitwise AND operator).

%e The first terms, in decimal and in binary, are:

%e n a(n) bin(n) bin(a(n))

%e -- ---- ------ ---------

%e 0 0 0 0

%e 1 1 1 1

%e 2 1 10 1

%e 3 3 11 11

%e 4 1 100 1

%e 5 5 101 101

%e 6 3 110 11

%e 7 7 111 111

%e 8 1 1000 1

%e 9 9 1001 1001

%e 10 5 1010 101

%e 11 15 1011 1111

%e 12 3 1100 11

%e 13 15 1101 1111

%e 14 7 1110 111

%e 15 15 1111 1111

%t {0}~Join~Array[Total[2^Append[Union@ Abs[Subtract @@@ Permutations[1 + Length[#] - Position[#, 1][[All, 1]] &@ IntegerDigits[#, 2], {2}]], 0]] &, 70] (* _Michael De Vlieger_, Oct 16 2021 *)

%o (PARI) a(n) = { my (b=vector(hammingweight(n))); for (k=1, #b, n-=2^b[k]=valuation(n, 2);); my (p=setbinop((i,j)->abs(i-j), b)); sum (k=1, #p, 2^p[k]) }

%o (Python)

%o def a(n):

%o locs = [e for e in range(n.bit_length()) if 1 & (n>>e)]

%o diffs = set(abs(e1-e2) for i, e1 in enumerate(locs) for e2 in locs[i:])

%o return sum(2**d for d in diffs)

%o print([a(n) for n in range(71)]) # _Michael S. Branicky_, Oct 16 2021

%Y Cf. A000079, A007283, A020714, A064896, A067398.

%K nonn,base

%O 0,4

%A _Rémy Sigrist_, Oct 15 2021