A039724 a(n) is the negabinary expansion of n, that is, the expansion of n in base -2.
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
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.
Links
- William A. Tedeschi, Table of n, a(n) for n = 0..10000
- Joerg Arndt, Matters Computational (The Fxtbook), p. 58-59
- Roberto Avanzi, Gerhard Frey, Tanja Lange, and Roger Oyono, On using expansions to the base of -2, International Journal of Computer Mathematics, 81:4 (2004), pp. 403-406. arXiv:math/0312060 [math.NT], 2003.
- Jaime Rangel-Mondragon, Negabinary Numbers to Decimal
- Vladimir Shevelev, Two analogs of Thue-Morse sequence, arXiv:1603.04434 [math.NT], 2016.
- Eric Weisstein's World of Mathematics, Negabinary
- Wikipedia, Negative base
Crossrefs
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
Comments