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-4 of 4 results.

A035327 Write n in binary, interchange 0's and 1's, convert back to decimal.

Original entry on oeis.org

1, 0, 1, 0, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46
Offset: 0

Views

Author

Keywords

Comments

For n>0: largest m<=n such that no carry occurs when adding m to n in binary arithmetic: A003817(n+1) = a(n) + n = a(n) XOR n. - Reinhard Zumkeller, Nov 14 2009
a(0) could be considered to be 0 (it was set so from 2004 to 2008) if the binary representation of zero was chosen to be the empty string. - Jason Kimberley, Sep 19 2011
For n > 0: A240857(n,a(n)) = 0. - Reinhard Zumkeller, Apr 14 2014
This is a base-2 analog of A048379. Another variant, without converting back to decimal, is given in A256078. - M. F. Hasler, Mar 22 2015
For n >= 2, a(n) is the least nonnegative k that must be added to n+1 to make a power of 2. Hence in a single-elimination tennis tournament with n entrants, a(n-1) is the number of players given a bye in round one, so that the number of players remaining at the start of round two is a power of 2. For example, if 39 players register, a(38)=25 players receive a round-one bye leaving 14 to play, so that round two will have 25+(14/2)=32 players. - Mathew Englander, Jan 20 2024

Examples

			8 = 1000 -> 0111 = 111 = 7.
		

Crossrefs

a(n) = A003817(n) - n, for n>0.
Cf. A240857.

Programs

  • Haskell
    a035327 n = if n <= 1 then 1 - n else 2 * a035327 n' + 1 - b
                where (n',b) = divMod n 2
    -- Reinhard Zumkeller, Feb 21 2014
    
  • Julia
    using IntegerSequences
    A035327List(len) = [Bits("NAND", n, n) for n in 0:len]
    println(A035327List(100))  # Peter Luschny, Sep 25 2021
  • Magma
    A035327:=func; // Jason Kimberley, Sep 19 2011
    
  • Maple
    seq(2^(1 + ilog2(max(n, 1))) - 1 - n, n = 0..81); # Emeric Deutsch, Oct 19 2008
    A035327 := n -> `if`(n=0, 1, Bits:-Nand(n, n)):
    seq(A035327(n), n=0..81); # Peter Luschny, Sep 23 2019
  • Mathematica
    Table[BaseForm[FromDigits[(IntegerDigits[i, 2]/.{0->1, 1->0}), 2], 10], {i, 0, 90}]
    Table[BitXor[n, 2^IntegerPart[Log[2, n] + 1] - 1], {n, 100}] (* Alonso del Arte, Jan 14 2006 *)
    Join[{1},Table[2^BitLength[n]-n-1,{n,100}]] (* Paolo Xausa, Oct 13 2023 *)
    Table[FromDigits[IntegerDigits[n,2]/.{0->1,1->0},2],{n,0,90}] (* Harvey P. Dale, May 03 2025 *)
  • PARI
    a(n)=sum(k=1,n,if(bitxor(n,k)>n,1,0)) \\ Paul D. Hanna, Jan 21 2006
    
  • PARI
    a(n) = bitxor(n, 2^(1+logint(max(n,1), 2))-1) \\ Rémy Sigrist, Jan 04 2019
    
  • PARI
    a(n)=if(n, bitneg(n, exponent(n)+1), 1) \\ Charles R Greathouse IV, Apr 13 2020
    
  • Python
    def a(n): return int(''.join('1' if i == '0' else '0' for i in bin(n)[2:]), 2) # Indranil Ghosh, Apr 29 2017
    
  • Python
    def a(n): return 1 if n == 0 else n^((1 << n.bit_length()) - 1)
    print([a(n) for n in range(100)]) # Michael S. Branicky, Sep 28 2021
    
  • Python
    def A035327(n): return (~n)^(-1<Chai Wah Wu, Dec 20 2022
    
  • SageMath
    def a(n):
        if n == 0:
            return 1
        return sum([(1 - b) << s for (s, b) in enumerate(n.bits())])
    [a(n) for n in srange(82)]  # Peter Luschny, Aug 31 2019
    

Formula

a(n) = 2^k - n - 1, where 2^(k-1) <= n < 2^k.
a(n+1) = (a(n)+n) mod (n+1); a(0) = 1. - Reinhard Zumkeller, Jul 22 2002
G.f.: 1 + 1/(1-x)*Sum_{k>=0} 2^k*x^2^(k+1)/(1+x^2^k). - Ralf Stephan, May 06 2003
a(0) = 0, a(2n+1) = 2*a(n), a(2n) = 2*a(n) + 1. - Philippe Deléham, Feb 29 2004
a(n) = number of positive integers k < n such that n XOR k > n. a(n) = n - A006257(n). - Paul D. Hanna, Jan 21 2006
a(n) = 2^{1+floor(log[2](n))}-n-1 for n>=1; a(0)=1. - Emeric Deutsch, Oct 19 2008
a(n) = if n<2 then 1 - n else 2*a(floor(n/2)) + 1 - n mod 2. - Reinhard Zumkeller, Jan 20 2010
a(n) = abs(2*A053644(n) - n - 1). - Mathew Englander, Jan 22 2024

Extensions

More terms from Vit Planocka (planocka(AT)mistral.cz), Feb 01 2003
a(0) corrected by Paolo P. Lava, Oct 22 2007
Definition completed by M. F. Hasler, Mar 22 2015

A342126 The binary expansion of a(n) corresponds to that of n where all the 1's have been replaced by 0's except in the first run of 1's.

Original entry on oeis.org

0, 1, 2, 3, 4, 4, 6, 7, 8, 8, 8, 8, 12, 12, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 24, 24, 24, 24, 28, 28, 30, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 48, 48, 48, 48, 48, 48, 48, 48, 56, 56, 56, 56, 60, 60, 62, 63, 64, 64, 64, 64
Offset: 0

Views

Author

Rémy Sigrist, Apr 25 2021

Keywords

Comments

In other words, this sequence gives the first run of 1's in the binary expansion of a number.
A023758(n) appears A057728(n) times.

Examples

			The first terms, alongside their binary expansion, are:
  n   a(n)  bin(n)  bin(a(n))
  --  ----  ------  ---------
   0     0       0          0
   1     1       1          1
   2     2      10         10
   3     3      11         11
   4     4     100        100
   5     4     101        100
   6     6     110        110
   7     7     111        111
   8     8    1000       1000
   9     8    1001       1000
  10     8    1010       1000
  11     8    1011       1000
  12    12    1100       1100
  13    12    1101       1100
  14    14    1110       1110
  15    15    1111       1111
		

Crossrefs

Programs

  • PARI
    a(n) = { my (b=binary(n), p=1); for (k=1, #b, b[k] = p*=b[k]); fromdigits(b, 2) }
    
  • Python
    def A342126(n):
        s = bin(n)[2:]
        i = s.find('0')
        return n if i == -1 else (2**i-1)*2**(len(s)-i) # Chai Wah Wu, Apr 29 2021

Formula

a(n) = n - A087734(n).
a(2*n) = 2*a(n).
a(a(n)) = a(n).
a(n) <= n with equality iff n belongs to A023758.

A373183 Irregular table T(n, k), n >= 0, k > 0, read by rows with row polynomials R(n, x) such that R(2n+1, x) = x*R(n, x) for n >= 0, R(2n, x) = x*(R(n, x+1) - R(n, x)) for n > 0 with R(0, x) = x.

Original entry on oeis.org

1, 0, 1, 1, 2, 0, 0, 1, 3, 4, 0, 1, 2, 1, 3, 3, 0, 0, 0, 1, 7, 8, 0, 3, 4, 3, 8, 6, 0, 0, 1, 2, 7, 15, 9, 0, 1, 3, 3, 1, 4, 6, 4, 0, 0, 0, 0, 1, 15, 16, 0, 7, 8, 7, 18, 12, 0, 0, 3, 4, 17, 34, 18, 0, 3, 8, 6, 3, 11, 15, 8, 0, 0, 0, 1, 2, 31, 57, 27, 0, 7, 15
Offset: 0

Views

Author

Mikhail Kurkov, May 27 2024

Keywords

Comments

Row n length is A000120(n) + 1.

Examples

			Irregular table begins:
  1;
  0,  1;
  1,  2;
  0,  0, 1;
  3,  4;
  0,  1, 2;
  1,  3, 3;
  0,  0, 0, 1;
  7,  8;
  0,  3, 4;
  3,  8, 6
  0,  0, 1, 2
  7, 15, 9;
  0,  1, 3, 3;
  1,  4, 6, 4;
  0,  0, 0, 0, 1;
		

Crossrefs

Programs

  • PARI
    row(n) = my(x = 'x, A = x); forstep(i=if(n == 0, -1, logint(n, 2)), 0, -1, A = if(bittest(n, i), x*A, x*(subst(A, x, x+1) - A))); Vecrev(A/x)

Formula

Conjectured formulas: (Start)
R(2n, x) = R(n, x) + R(n - 2^f(n), x) + R(2n - 2^f(n), x) where f(n) = A007814(n) (see A329369).
b(2^m*n + q) = Sum_{i=A001511(n+1)..A000120(n)+1} T(n, i)*b(2^m*(2^(i-1)-1) + q) for n >= 0, m >= 0, q >= 0 where b(n) = A329369(n). Note that this formula is recursive for n != 2^k - 1.
R(n, x) = c(n, x)
where c(2^k - 1, x) = x^(k+1) for k >= 0,
c(n, x) = Sum_{i=0..s(n)} p(n, s(n)-i)*Sum_{j=0..i} (s(n)-j+1)^A279209(n)*binomial(i, j)*(-1)^j,
p(n, k) = Sum_{i=0..k} c(t(n) + (2^i - 1)*A062383(t(n)), x)*L(s(n), k, i) for 0 <= k < s(n) with p(n, s(n)) = c(t(n) + (2^s(n) - 1)*A062383(t(n)), x),
s(n) = A090996(n), t(n) = A087734(n),
L(n, k, m) are some integer coefficients defined for n > 0, 0 <= k < n, 0 <= m <= k that can be represented as W(n-m, k-m, m+1)
and where W(n, k, m) = (k+m)*W(n-1, k, m) + (n-k)*W(n-1, k-1, m) + [m > 1]*W(n, k, m-1) for 0 <= k < n, m > 0 with W(0, 0, m) = 1, W(n, k, m) = 0 for n < 0 or k < 0.
In particular, W(n, k, 1) = A173018(n, k), W(n, k, 2) = A062253(n, k), W(n, k, 3) = A062254(n, k) and W(n, k, 4) = A062255(n, k).
Here s(n), t(n) and A279209(n) are unique integer sequences such that n can be represented as t(n) + (2^s(n) - 1)*A062383(t(n))*2^A279209(n) where t(n) is minimal. (End)
Conjectures from Mikhail Kurkov, Jun 19 2024: (Start)
T(n, k) = d(n, 1, A000120(n) - k + 2) where d(n, m, k) = (m+1)^g(n)*d(h(n), m+1, k) - m^(g(n)+1)*d(h(n), m, k-1) for n > 0, m > 0, k > 0 with d(n, m, 0) = 0 for n >= 0, m > 0, d(0, m, k) = [k <= m]*abs(Stirling1(m, m-k+1)) for m > 0, k > 0, g(n) = A290255(n) and where h(n) = A053645(n). In particular, d(n, 1, 1) = A341392(n).
Sum_{i=A001511(n+1)..wt(n)+k} d(n, k, wt(n)-i+k+1)*A329369(2^m*(2^(i-1)-1) + q) = k!*A357990(2^m*n + q, k) for n >= 0, k > 0, m >= 0, q >= 0 where wt(n) = A000120(n).
If we change R(0, x) to Product_{i=0..m-1} (x+i), then for resulting irregular table U(n, k, m) we have U(n, k, m) = d(n, m, A000120(n) - k + m + 1).
T(n, k) = (-1)^(wt(n)-k+1)*Sum_{i=1..wt(n)-k+3} Stirling1(wt(n)-i+3, k+1)*A358612(n, wt(n)-i+3) for n >= 0, k > 0 where wt(n) = A000120(n). (End)
Conjecture: T(2^m*(2k+1), q) = (-1)^(wt(k)-q)*Sum_{i=q..wt(k)+2} Stirling1(i,q)*A358612(k,i)*i^m for m >= 0, k >= 0, q > 0 where wt(n) = A000120(n). - Mikhail Kurkov, Jan 17 2025

A373886 a(n) is the least number whose binary expansion can be obtained by reversing one or more consecutive bits in the binary expansion of n.

Original entry on oeis.org

0, 1, 1, 3, 1, 3, 3, 7, 1, 3, 5, 7, 3, 7, 7, 15, 1, 3, 6, 7, 5, 11, 13, 15, 3, 7, 11, 15, 7, 15, 15, 31, 1, 3, 6, 7, 9, 13, 14, 15, 5, 11, 21, 23, 13, 27, 29, 31, 3, 7, 14, 15, 11, 23, 27, 31, 7, 15, 23, 31, 15, 31, 31, 63, 1, 3, 6, 7, 12, 13, 14, 15, 9, 19
Offset: 0

Views

Author

Rémy Sigrist, Aug 10 2024

Keywords

Comments

This sequence has similarities with A087734; here we reverse some consecutive bits, there we negate some consecutive bits.

Examples

			The first terms, alongside their binary expansion, are:
  n   a(n)  bin(n)  bin(a(n))
  --  ----  ------  ---------
   0     0       0          0
   1     1       1          1
   2     1      10          1
   3     3      11         11
   4     1     100          1
   5     3     101         11
   6     3     110         11
   7     7     111        111
   8     1    1000          1
   9     3    1001         11
  10     5    1010        101
  11     7    1011        111
  12     3    1100         11
  13     7    1101        111
  14     7    1110        111
  15    15    1111       1111
  16     1   10000          1
		

Crossrefs

Programs

  • Maple
    f:= proc(n) local L,nL,i,j,k,r,x;
      L:= convert(n,base,2);
      nL:= nops(L);
      r:= n;
      for i from 1 to nL-1 do
        for j from i+1 to nL do
          r:= min(r, n + add((L[j-k]-L[i+k])*2^(i+k-1),k=0..j-i));
      od od;
      r
    end proc:
    map(f, [$0..100]); # Robert Israel, Aug 13 2024
  • PARI
    a(n, base = 2) = { my (d = if (n, digits(n, base), [0])); setbinop((i, j) -> fromdigits(concat([d[1..i-1], Vecrev(d[i..j]), d[j+1..#d]]), base), [1..#d])[1]; }
    
  • Python
    def a(n):
        b = bin(n)[2:]
        return min(int(b[:i]+b[i:j][::-1]+b[j:], 2) for i in range(len(b)) for j in range(i, len(b)+1))
    print([a(n) for n in range(74)]) # Michael S. Branicky, Aug 13 2024

Formula

a(n) <= n with equality iff n belongs to A000225.
a^k(n) = A038573(n) for k sufficiently large (where a^k denotes the k-th iterate of the sequence).
a(2^k) = 1 for any k >= 0.
A000120(a(n)) = A000120(n).
Showing 1-4 of 4 results.