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

A039724 a(n) is the negabinary expansion of n, that is, the expansion of n in base -2.

Original entry on oeis.org

0, 1, 110, 111, 100, 101, 11010, 11011, 11000, 11001, 11110, 11111, 11100, 11101, 10010, 10011, 10000, 10001, 10110, 10111, 10100, 10101, 1101010, 1101011, 1101000, 1101001, 1101110, 1101111, 1101100, 1101101, 1100010, 1100011, 1100000, 1100001, 1100110, 1100111, 1100100
Offset: 0

Views

Author

Robert Lozyniak (11(AT)onna.com)

Keywords

Comments

The numbers written in base -2.
a(A007583(n)) are the only terms with all 1s digits; the number of digits = 2n + 1. - Bob Selcoe, Aug 21 2016

Examples

			2 = 4 + (-2) + 0 = 110_(-2), 3 = 4 + (-2) + 1 = 111_(-2), ..., 6 = 16 + (-8) + 0 + (-2) + 0 = 11010_(-2).
		

References

  • M. Gardner, Knotted Doughnuts and Other Mathematical Entertainments. Freeman, NY, 1986, p. 101.
  • D. E. Knuth, The Art of Computer Programming. Addison-Wesley, Reading, MA, 1969, Vol. 2, p. 189.

Crossrefs

Nonnegative numbers in negative bases: A039723 (b=-10), this sequence (b=-2), A073785 (b=-3), A007608 (b=-4), A073786 (b=-5), A073787 (b=-6), A073788 (b=-7), A073789 (b=-8), A073790 (b=-9).
Cf. A212529 (negative numbers in base -2).

Programs

  • Haskell
    a039724 0 = 0
    a039724 n = a039724 n' * 10 + m where
       (n', m) = if r < 0 then (q + 1, r + 2) else (q, r)
                 where (q, r) = quotRem n (negate 2)
    -- Reinhard Zumkeller, Jul 07 2012
    
  • Maple
    f:= proc(n) option remember; 10*floor((n mod 4)/2) + (n mod 2) + 100*procname(round(n/4)) end proc:
    f(0):= 0:
    seq(f(i),i=0..100); # Robert Israel, Feb 24 2016
  • Mathematica
    ToNegaBases[ i_Integer, b_Integer ] := FromDigits[ Rest[ Reverse[ Mod[ NestWhileList[ (#1 - Mod[ #1, b ])/-b &, i, #1 != 0 & ], b ] ] ] ]; Table[ ToNegaBases[ n, 2 ], {n, 0, 31} ]
  • PARI
    A039724(n)=if(n,A039724(n\(-2))*10+bittest(n,0)) \\ M. F. Hasler, Oct 16 2018
  • Python
    def A039724(n):
        s, q = '', n
        while q >= 2 or q < 0:
            q, r = divmod(q, -2)
            if r < 0:
                q += 1
                r += 2
            s += str(r)
        return int(str(q)+s[::-1]) # Chai Wah Wu, Apr 09 2016
    

Formula

G.f. g(x) satisfies g(x) = (x + 10*x^2 + 11*x^3)/(1 - x^4) + 100(1 + x + x^2 + x^3)*g(x^4)/x^2. - Robert Israel, Feb 24 2016

Extensions

More terms from Eric W. Weisstein

A005352 Base -2 representation of -n reinterpreted as binary.

Original entry on oeis.org

3, 2, 13, 12, 15, 14, 9, 8, 11, 10, 53, 52, 55, 54, 49, 48, 51, 50, 61, 60, 63, 62, 57, 56, 59, 58, 37, 36, 39, 38, 33, 32, 35, 34, 45, 44, 47, 46, 41, 40, 43, 42, 213, 212, 215, 214, 209, 208, 211, 210, 221, 220, 223, 222, 217, 216, 219, 218, 197, 196, 199, 198, 193, 192, 195, 194, 205, 204, 207, 206, 201, 200
Offset: 1

Views

Author

Keywords

Examples

			a(4) = 12 because the negabinary representation of -4 is 1100, and in ordinary binary that is 12.
a(5) = 15 because the negabinary representation of -5 is 1111, and in binary that is 15.
		

References

  • M. Gardner, Knotted Doughnuts and Other Mathematical Entertainments. Freeman, NY, 1986, p. 101.
  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).

Crossrefs

Complement of A005351 in natural numbers.
Cf. A212529.

Programs

  • Haskell
    a005352 = a005351 . negate  -- Reinhard Zumkeller, Feb 05 2014
    
  • Mathematica
    (* This function comes from the Weisstein page *)
    Negabinary[n_Integer] := Module[{t = (2/3)(4^Floor[Log[4, Abs[n] + 1] + 2] - 1)}, IntegerDigits[BitXor[n + t, t], 2]];
    Table[FromDigits[Negabinary[n], 2], {n, -1, -50, -1}]
    (* Alonso del Arte, Apr 04 2011 *)
  • PARI
    a(n) = my(t=(32*4^logint(n+1,4)-2)/3); bitxor(t-n, t); \\ Ruud H.G. van Tol, Oct 19 2023
    
  • Python
    def A005352(n):
        return ((b:=(4 << (n.bit_length() | 1)) // 3) - n)^b # Adrienne Leonardo, Feb 03 2025

Formula

a(n) = A005351(-n). - Reinhard Zumkeller, Feb 05 2014

A305238 Negative numbers in base -10.

Original entry on oeis.org

19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 79, 78, 77, 76, 75
Offset: 1

Views

Author

Jianing Song, Jun 19 2018

Keywords

Comments

a(n) = A039723(-n).
Also base -10 representation of -n reinterpreted as decimal numbers.
The first comment is slightly misleading because sequence A039723 isn't defined for n < 0, and none of the terms a(n) here is a term of A039723. However, it can be seen as the definition of the extension of A039723 to negative indices. Also, the (naïve) recursive definition or implementation of A039723 requires that function to be defined for negative arguments, and using the generic formula it will work as expected for -n, n > 0. - M. F. Hasler, Oct 16 2018

Examples

			-1 in base -10 is represented as 19 (1*(-10) + 9 = -1), so a(1) = 19;
-11 in base -10 is represented as 29 (2*(-10) + 9 = -11), so a(11) = 29;
-99 in base -10 is represented as 1901 (1*(-10)^3 + 9*(-10)^2 + 1 = -99), so a(99) = 1901.
		

Crossrefs

Cf. A039724 (nonnegative numbers in base -2), A212529 (negative numbers in base -2), A007608 (nonnegative numbers in base -4), A212526 (negative numbers in base -4), A039723 (nonnegative numbers in base -10).

Programs

A317050 a(0) = 0 and for any n >= 0, a(n+1) is obtained by changing the rightmost possible digit in the negabinary representation of a(n) so as to get a value not yet in the sequence.

Original entry on oeis.org

0, 1, -1, -2, 2, 3, 5, 4, -4, -3, -5, -6, -10, -9, -7, -8, 8, 9, 7, 6, 10, 11, 13, 12, 20, 21, 19, 18, 14, 15, 17, 16, -16, -15, -17, -18, -14, -13, -11, -12, -20, -19, -21, -22, -26, -25, -23, -24, -40, -39, -41, -42, -38, -37, -35, -36, -28, -27, -29, -30
Offset: 0

Views

Author

Rémy Sigrist, Jul 20 2018

Keywords

Comments

Binary Gray code, interpreted as negabinary number.
This sequence is a bijection from nonnegative integers to signed integers.
This sequence has similarities with A317018; in both sequences, the negabinary representations of consecutive terms differ exactly by one digit.

Examples

			The first terms, alongside their negabinary representation, are:
  n   a(n)  nega(a(n))
  --  ----  ----------
   0     0        0
   1     1        1
   2    -1       11
   3    -2       10
   4     2      110
   5     3      111
   6     5      101
   7     4      100
   8    -4     1100
   9    -3     1101
  10    -5     1111
  11    -6     1110
  12   -10     1010
  13    -9     1011
  14    -7     1001
  15    -8     1000
  16     8    11000
  17     9    11001
  18     7    11011
  19     6    11010
  20    10    11110
a(8) = -4 because nega(a(7)) = 100. Changing the rightmost digit gives 101 of which the decimal value in the sequence. Similarily, changing to 110 and 000 gives no new term. Changing to 1100 does so a(8) is the decimal value of 1100 which is -4. - _David A. Corneth_, Jul 22 2018
		

Crossrefs

Programs

  • PARI
    a(n) = fromdigits(binary(bitxor(n, n>>1)), -2)

Formula

a(n) = A053985(A003188(n)).

A331892 Positive numbers k such that the negabinary expansion (A039724) of -k is palindromic.

Original entry on oeis.org

1, 5, 7, 17, 21, 31, 35, 57, 65, 85, 93, 119, 127, 147, 155, 201, 217, 257, 273, 325, 341, 381, 397, 455, 471, 511, 527, 579, 595, 635, 651, 745, 777, 857, 889, 993, 1025, 1105, 1137, 1253, 1285, 1365, 1397, 1501, 1533, 1613, 1645, 1767, 1799, 1879, 1911, 2015
Offset: 1

Views

Author

Amiram Eldar, Jan 30 2020

Keywords

Comments

Numbers of the form 2^(2*m-1) - 1 (A083420) and 2^(2*m) + 1 (A052539) are terms.

Examples

			5 is a term since the negabinary representation of -5 is 1111 which is palindromic.
		

Crossrefs

Programs

  • Mathematica
    negabin[n_] := negabin[n] = If[n==0, 0, negabin[Quotient[n-1, -2]]*10 + Mod[n, 2]]; Select[Range[2000], PalindromeQ @ negabin[-#] &]

A317018 Sequence of distinct signed integers such that a(1) = 0 and for any n > 0, the negabinary representation of a(n+1) differ by exactly one digit from the negabinary representation of a(n) and has the smallest possible absolute value (in case of a tie, choose the integer with the rightmost difference).

Original entry on oeis.org

0, 1, -1, -2, 2, 3, 5, -3, -4, 4, 20, 12, 8, 6, 7, 9, -7, -8, -10, -6, -5, -9, -41, 23, 22, 24, 25, 29, 27, 26, 28, 36, -28, -12, -11, -13, -14, -18, 14, 15, 17, -15, -16, 16, 80, 48, 32, 30, 31, 33, -31, -27, -29, -30, -34, -32, -40, -24, -20, -19, 13, 11, 10
Offset: 1

Views

Author

Rémy Sigrist, Jul 19 2018

Keywords

Comments

This sequence has similarities with A316995; in both sequences, the absolute value of the difference of two consecutive terms is a power of 2.
This sequence also has similarities with A163252.

Examples

			The first terms, alongside their negabinary representation, are:
  n   a(n)  nega(a(n))
  --  ----  ----------
   1     0        0
   2     1        1
   3    -1       11
   4    -2       10
   5     2      110
   6     3      111
   7     5      101
   8    -3     1101
   9    -4     1100
  10     4      100
  11    20    10100
  12    12    11100
  13     8    11000
  14     6    11010
  15     7    11011
  16     9    11001
  17    -7     1001
  18    -8     1000
  19   -10     1010
  20    -6     1110
		

Crossrefs

Programs

  • PARI
    See Links section.

A320642 Number of 1's in the base-(-2) expansion of -n.

Original entry on oeis.org

2, 1, 3, 2, 4, 3, 2, 1, 3, 2, 4, 3, 5, 4, 3, 2, 4, 3, 5, 4, 6, 5, 4, 3, 5, 4, 3, 2, 4, 3, 2, 1, 3, 2, 4, 3, 5, 4, 3, 2, 4, 3, 5, 4, 6, 5, 4, 3, 5, 4, 6, 5, 7, 6, 5, 4, 6, 5, 4, 3, 5, 4, 3, 2, 4, 3, 5, 4, 6, 5, 4, 3, 5, 4, 6, 5, 7, 6, 5, 4, 6, 5, 7, 6, 8, 7, 6
Offset: 1

Views

Author

Jianing Song, Oct 18 2018

Keywords

Comments

Number of 1's in A212529(n).
Define f(n) as: f(0) = 0, f(-2*n) = f(n), f(-2*n+1) = f(n) + 1, then a(n) = f(-n), n >= 1. See A027615 for the other half of f.
For k > 1, the earliest occurrence of k is n = A086893(k-1).

Examples

			A212529(11) = 110101 which has four 1's, so a(11) = 4.
A212529(25) = 111011 which has five 1's, so a(25) = 5.
A212529(51) = 11011101 which has six 1's, so a(51) = 6.
		

Crossrefs

Programs

  • Mathematica
    b[n_] := b[n] = b[Quotient[n - 1, -2]] + Mod[n, 2]; b[0] = 0; a[n_] := b[-n]; Array[a, 100] (* Amiram Eldar, Jul 23 2023 *)
  • PARI
    b(n) = if(n==0, 0, b(n\(-2))+n%2)
    a(n) = b(-n)

Formula

a(n) == -n (mod 3).
a(n) = A000120(A005352(n)). - Michel Marcus, Oct 23 2018

A331893 Positive numbers k such that both k and -k are a palindromes in negabinary representation.

Original entry on oeis.org

1, 5, 7, 17, 21, 31, 57, 65, 85, 127, 155, 217, 257, 273, 325, 341, 455, 511, 635, 857, 889, 993, 1025, 1105, 1253, 1285, 1365, 1799, 2047, 2159, 2555, 2667, 3417, 3577, 3641, 3937, 4097, 4161, 4369, 4433, 4965, 5125, 5189, 5397, 5461, 6951, 7175, 7967, 8191
Offset: 1

Views

Author

Amiram Eldar, Jan 30 2020

Keywords

Comments

Numbers of the form 2^(2*m-1) - 1 (A083420) and 2^(2*m) + 1 (A052539) are terms.

Examples

			5 is a term since the negabinary representation of 5, 101, and the negabinary representation of -5, 1111, are both palindromic.
		

Crossrefs

Intersection of A331891 and A331892.

Programs

  • Mathematica
    negabin[n_] := negabin[n] = If[n==0, 0, negabin[Quotient[n-1, -2]]*10 + Mod[n, 2]]; nbPalinQ[n_] := And @@ (PalindromeQ @ negabin[#] & /@ {n, -n}); Select[Range[2^13], nbPalinQ]

A320636 Negative numbers in base -3.

Original entry on oeis.org

12, 11, 10, 22, 21, 20, 1202, 1201, 1200, 1212, 1211, 1210, 1222, 1221, 1220, 1102, 1101, 1100, 1112, 1111, 1110, 1122, 1121, 1120, 1002, 1001, 1000, 1012, 1011, 1010, 1022, 1021, 1020, 2202, 2201, 2200, 2212, 2211, 2210, 2222, 2221, 2220, 2102, 2101, 2100, 2112
Offset: 1

Views

Author

Jianing Song, Oct 18 2018

Keywords

Comments

Extend A073785 to negative-indexed terms, then a(n) = A073785(-n).

Examples

			-7 in base -3 is represented as 1202 (1*(-3)^3 + 2*(-3)^2 + 2 = -7), so a(7) = 1202;
-16 in base -3 is represented as 1102 (1*(-3)^3 + 1*(-3)^2 + 2 = -16), so a(16) = 1102;
-40 in base -3 is represented as 2222 (2*(-3)^3 + 2*(-3)^2 + 2*(-3) + 2 = -99), so a(40) = 2222.
		

Crossrefs

Nonnegative numbers in negative bases: A039723 (b=-10), A039724 (b=-2), A073785 (b=-3), A007608 (b=-4), A073786 (b=-5), A073787 (b=-6), A073788 (b=-7), A073789 (b=-8), A073790 (b=-9).
Negative numbers in negative bases: A305238 (b=-10), A212529 (b=-2), this sequence (b=-3), A212526 (b=-4).

Programs

Showing 1-9 of 9 results.