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.

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.

This page as a plain text file.
%I A337319 #64 Jun 27 2021 04:41:05
%S A337319 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,
%T A337319 -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,
%U A337319 -1,-1,-1,0,1,0,-1,0,1,1,1,2,3,1
%N 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.
%C A337319 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).
%C A337319 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.
%C A337319 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
%F A337319 a(n) = A145037(A000265(n)) = A145037(n) + A007814(n). - _Kevin Ryde_, Aug 31 2020
%e A337319 For n = 10, a(10) = 0 + 1 + (-1) + 1 = 1.
%t A337319 Array[2 DigitCount[#, 2, 1] + IntegerExponent[#, 2] - Floor[Log2[#]] - 1 &, 80] (* _Michael De Vlieger_, Sep 01 2020 *)
%o A337319 (JavaScript)
%o A337319 var k = 1;
%o A337319 var r = 0;
%o A337319 for (var i = 0; i < 100; i += 1) {
%o A337319     while ((i+1) >= Math.pow(2, k - 1)) {
%o A337319         if (Math.round((i+1) / Math.pow(2, k)) < ((i+1) / Math.pow(2, k))) {
%o A337319             r -= 1;
%o A337319         } else if (Math.round((i+1) / Math.pow(2, k)) > ((i+1) / Math.pow(2, k))) {
%o A337319             r += 1;
%o A337319         } else {
%o A337319             r += 0;
%o A337319         }
%o A337319         k += 1;
%o A337319     }
%o A337319     document.write(r, ", ");
%o A337319     k = 1;
%o A337319     r = 0;
%o A337319 }
%o A337319 (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
%o A337319 (PARI) a(n) = 2*hammingweight(n) + valuation(n,2) - logint(n,2) - 1; \\ _Kevin Ryde_, Aug 29 2020
%Y A337319 Cf. A000265, A007814, A145037.
%K A337319 sign
%O A337319 1,3
%A A337319 _Christoph B. Kassir_, Aug 23 2020