OFFSET
1,3
COMMENTS
Symmetric bit strings (bit-reverse palindromes), including as many leading as trailing zeros.
LINKS
Reinhard Zumkeller, Table of n, a(n) for n = 1..10000
Aayush Rajasekaran, Jeffrey Shallit, and Tim Smith, Sums of Palindromes: an Approach via Nested-Word Automata, preprint arXiv:1706.10206 [cs.FL], June 30 2017.
FORMULA
a(7*2^n-4*n-4) = 4^n + 1, a(10*2^n-4*n-6) = 2*4^n + 1. - Gheorghe Coserea, Apr 05 2017
EXAMPLE
10 is included, since 01010 is a palindrome, but 11 is not because 1011 is not.
MAPLE
dmax:= 10: # to get all terms < 2^dmax
revdigs:= proc(n)
local L, Ln, i;
L:= convert(n, base, 2);
Ln:= nops(L);
add(L[i]*2^(Ln-i), i=1..Ln);
end proc;
P[0]:= {0}:
P[1]:= {1}:
for d from 2 to dmax do
if d::even then
P[d]:= { seq(2^(d/2)*x + revdigs(x), x=2^(d/2-1)..2^(d/2)-1)}
else
m:= (d-1)/2;
B:={seq(2^(m+1)*x + revdigs(x), x=2^(m-1)..2^m-1)};
P[d]:= B union map(`+`, B, 2^m)
fi
od:
A:= `union`(seq(seq(map(`*`, P[d], 2^k), k=0..dmax-d), d=0..dmax)):
sort(convert(A, list)); # Robert Israel, Jun 07 2016
MATHEMATICA
PaleQ[n_Integer, base_Integer] := Module[{idn, trim = n/base^IntegerExponent[n, base]}, idn = IntegerDigits[trim, base]; idn == Reverse[idn]]; Select[Range[0, 150], PaleQ[#, 2] &] (* Lei Zhou, Dec 13 2013 *)
pal2Q[n_]:=Module[{id=Drop[IntegerDigits[n, 2], -IntegerExponent[n, 2]]}, id==Reverse[id]]; Join[{0}, Select[Range[200], pal2Q]] (* Harvey P. Dale, Feb 26 2015 *)
A057890Q = If[# > 0 && EvenQ@#, #0[#/2], # == #~IntegerReverse~2] &; Select[0~Range~146, A057890Q] (* JungHwan Min, Mar 29 2017 *)
Select[Range[0, 200], PalindromeQ[IntegerDigits[#, 2] /. {b__, 0..} -> {b} ]&] (* Jean-François Alcover, Sep 18 2018 *)
PROG
(Haskell)
a057890 n = a057890_list !! (n-1)
a057890_list = 0 : filter ((== 1) . a178225 . a000265) [1..]
-- Reinhard Zumkeller, Oct 21 2011
(Python)
A057890 = [n for n in range(10**6) if bin(n)[2:].rstrip('0') == bin(n)[2:].rstrip('0')[::-1]] # Chai Wah Wu, Aug 12 2014
(PARI)
bitrev(n) = subst(Pol(Vecrev(binary(n>>valuation(n, 2))), 'x), 'x, 2);
is(n) = my(x = n >> valuation(n, 2)); x == bitrev(x);
concat(0, select(is, vector(147, n, n))) \\ Gheorghe Coserea, Jun 07 2016
(PARI) is(n)=n==0 || Vecrev(n=binary(n>>valuation(n, 2)))==n \\ Charles R Greathouse IV, Aug 25 2016
CROSSREFS
KEYWORD
easy,nonn,base,nice
AUTHOR
Marc LeBrun, Sep 25 2000
STATUS
approved