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.

Showing 1-3 of 3 results.

A301896 a(n) = product of total number of 0's and total number of 1's in binary expansions of 0, ..., n.

Original entry on oeis.org

0, 1, 4, 8, 20, 35, 54, 72, 117, 165, 221, 280, 352, 425, 504, 576, 726, 875, 1036, 1200, 1386, 1575, 1776, 1976, 2214, 2451, 2700, 2944, 3216, 3479, 3750, 4000, 4455, 4897, 5355, 5808, 6300, 6789, 7296, 7800, 8364, 8925, 9504, 10080, 10695, 11305, 11931, 12544, 13260, 13965, 14688
Offset: 0

Views

Author

Ilya Gutkovskiy, Mar 28 2018

Keywords

Examples

			+---+-----+---+---+---+---+----------+
| n | bin.|0's|sum|1's|sum|   a(n)   |
+---+-----+---+---+---+---+----------+
| 0 |   0 | 1 | 1 | 0 | 0 | 1*0 =  0 |
| 1 |   1 | 0 | 1 | 1 | 1 | 1*1 =  1 |
| 2 |  10 | 1 | 2 | 1 | 2 | 2*2 =  4 |
| 3 |  11 | 0 | 2 | 2 | 4 | 2*4 =  8 |
| 4 | 100 | 2 | 4 | 1 | 5 | 4*5 = 20 |
| 5 | 101 | 1 | 5 | 2 | 7 | 5*7 = 35 |
| 6 | 110 | 1 | 6 | 2 | 9 | 6*9 = 54 |
+---+-----+---+---+---+---+----------+
bin. - n written in base 2;
0's - number of 0's in binary expansion of n;
1's - number of 1's in binary expansion of n;
sum - total number of 0's (or 1's) in binary expansions of 0, ..., n.
		

Crossrefs

Programs

  • Maple
    b:= proc(n) option remember; `if`(n=0, [1, 0], b(n-1)+
         (l-> [add(1-i, i=l), add(i, i=l)])(Bits[Split](n)))
        end:
    a:= n-> (l-> l[1]*l[2])(b(n)):
    seq(a(n), n=0..50);  # Alois P. Heinz, Mar 01 2023
  • Mathematica
    Accumulate[DigitCount[Range[0, 50], 2, 0]] Accumulate[DigitCount[Range[0, 50], 2, 1]]
  • Python
    def A301896(n): return (2+(n+1)*(m:=(n+1).bit_length())-(1<Chai Wah Wu, Mar 01 2023
    
  • Python
    def A301896(n): return (a:=(n+1)*n.bit_count()+(sum((m:=1<>j)-(r if n<<1>=m*(r:=k<<1|1) else 0)) for j in range(1,n.bit_length()+1))>>1))*(2+(n+1)*(t:=(n+1).bit_length())-(1<Chai Wah Wu, Nov 11 2024

Formula

a(n) = A059015(n)*A000788(n).
a(2^k-1) = 2^(k-2)*(2^k*(k - 2) + 4)*k.

A334841 a(0) = 0; for n > 0, a(n) = (number of 1's and 3's in base 4 representation of n) - (number of 0's and 2's in base 4 representation of n).

Original entry on oeis.org

0, 1, -1, 1, 0, 2, 0, 2, -2, 0, -2, 0, 0, 2, 0, 2, -1, 1, -1, 1, 1, 3, 1, 3, -1, 1, -1, 1, 1, 3, 1, 3, -3, -1, -3, -1, -1, 1, -1, 1, -3, -1, -3, -1, -1, 1, -1, 1, -1, 1, -1, 1, 1, 3, 1, 3, -1, 1, -1, 1, 1, 3, 1, 3, -2, 0, -2, 0, 0, 2, 0, 2, -2, 0, -2, 0, 0, 2, 0, 2, 0, 2, 0, 2, 2, 4, 2, 4, 0
Offset: 0

Views

Author

Keywords

Comments

Values are even for base 4 representations of n with an even number of digits, and odd for base 4 representations of n with an odd number of digits, except for a(0).

Examples

			      n in    #odd    #even
  n  base 4  digits - digits = a(n)
  =  ======  =======================
  0    0        0   -            0
  1    1        1   -    0   =   1
  2    2        0   -    1   =  -1
  3    3        1   -    0   =   1
  4   10        1   -    1   =   0
  5   11        2   -    0   =   2
  6   12        1   -    1   =   0
  7   13        2   -    0   =   2
		

Crossrefs

Programs

  • Maple
    a:= n-> `if`(n=0, 0, add(`if`(i in [1, 3], 1, -1), i=convert(n, base, 4))):
    seq(a(n), n=0..100);  # Alois P. Heinz, May 30 2020
  • Mathematica
    a[0] = 0; a[n_] := Total[-(-1)^(r = Range[0, 3]) * DigitCount[n, 4, r]]; Array[a, 100, 0] (* Amiram Eldar, May 13 2020 *)
    Join[{0},Table[Total[If[EvenQ[#],-1,1]&/@IntegerDigits[n,4]],{n,90}]] (* Harvey P. Dale, Sep 06 2020 *)
  • PARI
    a(n) = my(ret=0); if(n,forstep(i=0,logint(n,2),2, if(bittest(n,i),ret++,ret--))); ret; \\ Kevin Ryde, May 24 2020
    
  • Python
    import numpy as np
    def qnary(n):
        e = n//4
        q = n%4
        if n == 0 : return 0
        if e == 0 : return q
        if e != 0 : return np.append(qnary(e), q)
    m = 400
    v = [0]
    for i in range(1, m+1) :
        t = np.array(qnary(i))
        t[t%2 != 0] = 1
        t[t%2 == 0] = -1
        v = np.append(v, np.sum(t))
    
  • Python
    def A334841(n):
        return 2*bin(n)[-1:1:-2].count('1')-(len(bin(n))-1)//2 if n > 0 else 0 # Chai Wah Wu, Sep 03 2020
  • R
    qnary = function(n, e, q){
      e = floor(n/4)
      q = n%%4
      if(n == 0 ){return(0)}
      if(e == 0){return(q)}
      else{return(c(qnary(e), (q)))}
    }
    m = 400
    s = seq(2, m)
    v = c(0)
    for(i in s){
      x = qnary(i-1)
      x[which(x%%2!=0)] = 1
      x[which(x%%2==0)] = -1
      v[i] = sum(x)
    }
    

Formula

a(n) = 2*A139351(n) - A110591(n), n>0. - R. J. Mathar, Sep 02 2020

A333596 a(0) = 0; for n > 0, a(n) = a(n-1) + (number of 1's and 3's in base-4 representation of n) - (number of 0's and 2's in base-4 representation of n).

Original entry on oeis.org

0, 1, 0, 1, 1, 3, 3, 5, 3, 3, 1, 1, 1, 3, 3, 5, 4, 5, 4, 5, 6, 9, 10, 13, 12, 13, 12, 13, 14, 17, 18, 21, 18, 17, 14, 13, 12, 13, 12, 13, 10, 9, 6, 5, 4, 5, 4, 5, 4, 5, 4, 5, 6, 9, 10, 13, 12, 13, 12, 13, 14, 17, 18, 21, 19, 19, 17, 17, 17, 19, 19, 21, 19, 19
Offset: 0

Views

Author

Keywords

Comments

Local maxima values minus 1 are divisible by 4.
For a digit-wise recurrence, it's convenient to sum n terms so b(n) = a(n-1) = Sum_{i=0..n-1} A334841(i). Then b(4n+r) = 4*b(n) + r*A334841(n) + (1 if r even), for 0 <= r <= 3 and 4n+r >= 1. This is 4 copies of terms 0..n-1 and r copies of the following n. The new lowest digits cancel when r is odd, or net +1 when r is even. Repeatedly expanding gives the PARI code below. - Kevin Ryde, Jun 02 2020

Examples

			      n in    #odd    #even
  n  base 4  digits - digits + a(n-1) = a(n)
  =  ======  ===============================
  0    0        0   -                     0
  1    1        1   -    0   +    0   =   1
  2    2        0   -    1   +    1   =   0
  3    3        1   -    0   +    0   =   1
  4   10        1   -    1   +    1   =   1
  5   11        2   -    0   +    1   =   3
  6   12        1   -    1   +    3   =   3
  7   13        2   -    0   +    3   =   5
		

Crossrefs

Programs

  • Maple
    a:= proc(n) option remember; `if`(n=0, 0, a(n-1) +add(
         `if`(i in [1, 3], 1, -1), i=convert(n, base, 4)))
        end:
    seq(a(n), n=0..80);  # Alois P. Heinz, May 30 2020
  • Mathematica
    f[n_] := Total[(-1)^(r = Range[0, 3]) * DigitCount[n, 4, r]]; a[0] = 0; a[n_] := a[n] = a[n - 1] - f[n]; Array[a, 100, 0] (* Amiram Eldar, Apr 24 2020 *)
  • PARI
    a(n) = my(v=digits(n+1,4),s=0); for(i=1,#v, my(t=v[i]); v[i]=t*s+!(t%2); s-=(-1)^t); fromdigits(v,4); \\ Kevin Ryde, May 30 2020
    
  • PARI
    b(n)=my(d=digits(n,4)); -sum(i=1,#d,(-1)^d[i])
    first(n)=my(s); concat(0,vector(n,k,s+=b(k))) \\ Charles R Greathouse IV, Jul 04 2020
    
  • Python
    import numpy as np
    def qnary(n):
        e = n//4
        q = n%4
        if n == 0 : return 0
        if e == 0 : return q
        if e != 0 : return np.append(qnary(e), q)
    m = 400
    v = [0]
    for i in range(1,m+1) :
        t = np.array(qnary(i))
        t[t%2 != 0] = 1
        t[t%2 == 0] = -1
        v = np.append(v, np.sum([np.sum(t), v[i-1]]))
    
  • Python
    from itertools import accumulate
    def A334841(n):
        return 2*bin(n)[-1:1:-2].count('1')-(len(bin(n))-1)//2 if n > 0 else 0
    A333596_list = list(accumulate(A334841(n) for n in range(10000))) # Chai Wah Wu, Sep 03 2020
  • R
    qnary = function(n, e, q){
      e = floor(n/4)
      q = n%%4
      if(n == 0 ){return(0)}
      if(e == 0){return(q)}
      else{return(c(qnary(e), (q)))}
    }
    m = 400
    s = seq(2,m)
    v = c(0)
    for(i in s){
      x = qnary(i-1)
      x[which(x%%2!=0)] = 1
      x[which(x%%2==0)] = -1
      v[i] = sum(x,v[i-1])
    }
    
Showing 1-3 of 3 results.