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”).

A337319
a(n) = Sum_{i = 1..floor(log_2(n))+1} g(frac(n/2^i)), where g(t) = [0 if t = 0, -1 if 0 < t < 1/2, 1 if t >= 1/2], and where frac(x) denotes the fractional part.
1
1, 1, 2, 1, 1, 2, 3, 1, 0, 1, 2, 2, 2, 3, 4, 1, -1, 0, 1, 1, 1, 2, 3, 2, 1, 2, 3, 3, 3, 4, 5, 1, -2, -1, 0, 0, 0, 1, 2, 1, 0, 1, 2, 2, 2, 3, 4, 2, 0, 1, 2, 2, 2, 3, 4, 3, 2, 3, 4, 4, 4, 5, 6, 1, -3, -2, -1, -1, -1, 0, 1, 0, -1, 0, 1, 1, 1, 2, 3, 1
OFFSET
1,3
COMMENTS
The function a(n) is a measure of how many times n rounds up (assigned value +1), down (assigned value -1), or not at all (assigned value 0) when divided by incremental powers of two (see example below).
For n = 2^k, all divisions give integers (not rounded at all) until n/2^(k+1), which rounds up to 1, and so a(2^k) = 1.
n/2^i shifts the bits of n down so the bit of n at position i-1 (least significant bit as position 0) is immediately below the radix point and so determines whether frac(n/2^i) >= 1/2 or < 1/2. frac(n/2^i) = 0 is when the bits of n at i-1 and below are all 0's. So a(n) is sum +1 for each 1-bit of n and -1 for each 0-bit of n but excluding any low 0's. - Kevin Ryde, Aug 31 2020
FORMULA
a(n) = A145037(A000265(n)) = A145037(n) + A007814(n). - Kevin Ryde, Aug 31 2020
EXAMPLE
For n = 10, a(10) = 0 + 1 + (-1) + 1 = 1.
MATHEMATICA
Array[2 DigitCount[#, 2, 1] + IntegerExponent[#, 2] - Floor[Log2[#]] - 1 &, 80] (* Michael De Vlieger, Sep 01 2020 *)
PROG
(JavaScript)
var k = 1;
var r = 0;
for (var i = 0; i < 100; i += 1) {
while ((i+1) >= Math.pow(2, k - 1)) {
if (Math.round((i+1) / Math.pow(2, k)) < ((i+1) / Math.pow(2, k))) {
r -= 1;
} else if (Math.round((i+1) / Math.pow(2, k)) > ((i+1) / Math.pow(2, k))) {
r += 1;
} else {
r += 0;
}
k += 1;
}
document.write(r, ", ");
k = 1;
r = 0;
}
(PARI) a(n) = sum(k = 1, 1+logint(n, 2), my(x=(n % 2^k)/2^k); sign(round(x) - x)); \\ Michel Marcus, Aug 23 2020
(PARI) a(n) = 2*hammingweight(n) + valuation(n, 2) - logint(n, 2) - 1; \\ Kevin Ryde, Aug 29 2020
CROSSREFS
KEYWORD
sign
AUTHOR
Christoph B. Kassir, Aug 23 2020
STATUS
approved