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.
%I A006995 M2403 #240 Jun 11 2024 01:41:24 %S A006995 0,1,3,5,7,9,15,17,21,27,31,33,45,51,63,65,73,85,93,99,107,119,127, %T A006995 129,153,165,189,195,219,231,255,257,273,297,313,325,341,365,381,387, %U A006995 403,427,443,455,471,495,511,513,561,585,633,645,693,717,765,771,819,843 %N A006995 Binary palindromes: numbers whose binary expansion is palindromic. %C A006995 If b > 1 is a binary palindrome then both (2^(m+1) + 1)*b and 2^(m+1) + 2^m - b are also, where m = floor(log_2(b)). - _Hieronymus Fischer_, Feb 18 2012 %C A006995 Floor and ceiling: If d > 0 is any natural number, then A206913(d) is the greatest binary palindrome <= d and A206914(d) is the least binary palindrome >= d. - _Hieronymus Fischer_, Feb 18 2012 %C A006995 The greatest binary palindrome <= the n-th non-binary-palindrome is that binary palindrome with number A154809(n)-n+1. The corresponding formula identity is: A206913(A154809(n)) = A006995(A154809(n)-n+1). - _Hieronymus Fischer_, Mar 18 2012 %C A006995 From _Hieronymus Fischer_, Jan 23 2013: (Start) %C A006995 The number of binary digits of a(n) is A070939(a(n)) = 1 + floor(log_2(n)) + floor(log_2(n/3)), for n > 1. %C A006995 Also: A070939(a(n)) = A070939(n) + A070939(floor(n/3)) - 1, for n <> 2. (End) %C A006995 Rajasekaran, Shallit, & Smith show that this is an additive basis of order 4. - _Charles R Greathouse IV_, Nov 06 2018 %D A006995 N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence). %H A006995 T. D. Noe, <a href="/A006995/b006995.txt">Table of n, a(n) for n = 1..10000</a> %H A006995 James Haoyu Bai, Joseph Meleshko, Samin Riasat, and Jeffrey Shallit, <a href="https://arxiv.org/abs/2202.13694">Quotients of Palindromic and Antipalindromic Numbers</a>, arXiv:2202.13694 [math.NT], 2022. %H A006995 William D. Banks and Igor E. Shparlinski, <a href="https://doi.org/10.4064/ba54-2-1">Average Value of the Euler Function on Binary Palindromes</a>, Bulletin Polish Acad. Sci. Math., Vol. 54 (2006), pp. 95-101, <a href="http://faculty.missouri.edu/~bankswd/papers/2006_palindromes_iii.pdf">alternative link</a>. %H A006995 Manfred Madritsch and Stephan Wagner, <a href="https://doi.org/10.1007/s00605-009-0126-y">A central limit theorem for integer partitions</a>, Monatshefte für Mathematik, Vol. 161, No. 1 (2010), pp. 85-114, <a href="https://www.researchgate.net/publication/225845584_A_central_limit_theorem_for_integer_partitions">alternative link</a>. doi:10.1007/s00605-009-0126-y. %H A006995 Kritkhajohn Onphaeng, Tammatada Khemaratchatakumthorn, Phakhinkon Napp Phunphayap, and Prapanpong Pongsriiam, <a href="https://cs.uwaterloo.ca/journals/JIS/VOL27/Phunphayap/phun7.html">Exact Formulas for the Number of Palindromes in Certain Arithmetic Progressions</a>, Journal of Integer Sequences, Vol. 27 (2024), Article 24.4.8. See p. 2. %H A006995 Aayush Rajasekaran, <a href="http://hdl.handle.net/10012/13202">Using Automata Theory to Solve Problems in Additive Number Theory</a>, MS thesis, University of Waterloo, 2018. %H A006995 Aayush Rajasekaran, Jeffrey Shallit and Tim Smith, <a href="https://arxiv.org/abs/1706.10206">Sums of Palindromes: an Approach via Nested-Word Automata</a>, preprint arXiv:1706.10206 [cs.FL], Jun 30 2017. %H A006995 Aayush Rajasekaran, Jeffrey Shallit and Tim Smith, <a href="https://doi.org/10.1007/s00224-019-09929-9">Additive Number Theory via Automata Theory</a>, Theory of Computing Systems, Vol. 64 (2020), pp. 542-567. %H A006995 L. J. Upton, <a href="/A006993/a006993_1.pdf">Letter to N. J. A. Sloane with attachments, Oct. 1993</a>. %H A006995 <a href="/index/Ab#basis_04">Index entries for sequences that are an additive basis</a>, order 4. %H A006995 <a href="/index/Bi#binary">Index entries for sequences related to binary expansion of n</a> %H A006995 <a href="/index/Pac#palindromes">Index entries for sequences related to palindromes</a> %F A006995 A178225(a(n)) = 1; union of A048700 and A048701. - _Reinhard Zumkeller_, Oct 21 2011 %F A006995 From _Hieronymus Fischer_, Dec 31 2008, Jan 10 2012, Feb 18 2012: (Start) %F A006995 Written as a decimal, a(10^n) has 2*n digits. For n > 1, the decimal expansion of a(10^n) starts with 22..., 23... or 24...: %F A006995 a(1000) = 249903, %F A006995 a(10^4) = 24183069, %F A006995 a(10^5) = 2258634081, %F A006995 a(10^6) = 249410097687, %F A006995 a(10^7) = 24350854001805, %F A006995 a(10^8) = 2229543293296319, %F A006995 a(10^9) = 248640535848971067, %F A006995 a(10^10)= 24502928886295666773. %F A006995 Inequality: (2/9)*n^2 < a(n) < (1/4)*(n+1)^2, if n > 1. %F A006995 lim sup_{n -> oo} a(n)/n^2 = 1/4, lim inf_{n -> oo} a(n)/n^2 = 2/9. %F A006995 For n >= 2, a(2^n-1) = 2^(2n-2) - 1; a(2^n) = 2^(2n-2) + 1; %F A006995 a(2^n+1) = 2^(2n-2) + 2^(n-1) + 1; a(2^n + 2^(n-1)) = 2^(2n-1) + 1. %F A006995 Recursion for n > 2: a(n) = 2^(2k-q) + 1 + 2^p*a(m), where k = floor(log_2(n-1)), and p, q and m are determined as follows: %F A006995 Case 1: If n = 2^(k+1), then p = 0, q = 0, m = 1; %F A006995 Case 2: If 2^k < n < 2^k+2^(k-1), then p = k-floor(log_2(i))-1 with i = n-2^k, q = 2, m = 2^floor(log_2(i)) + i; %F A006995 Case 3: If n = 2^k + 2^(k-1), then p = 0, q = 1, m = 1; %F A006995 Case 4: If 2^k + 2^(k-1) < n < 2^(k+1), then p = k-floor(log_2(j))-1 with j = n-2^k-2^(k-1), q = 1, m = 2*2^floor(log_2(j))+j. %F A006995 Non-recursive formula: %F A006995 Let n >= 3, m = floor(log_2(n)), p = floor((3*2^(m-1)-1)/n), then %F A006995 a(n) = 2^(2*m-1-p) + 1 + p*(1-(-1)^n)*2^(m-1-p) + sum_{k=1 .. m-1-p} (floor((n-(3-p)*2^(m-1))/2^(m-1-k)) mod 2)*(2^k+2^(2*m-1-p-k)). [Typo at the last exponent of the third sum term eliminated by the author, Sep 05 2018] %F A006995 a(n) = 2^(2*m-2) + 1 + 2*floor((n-2^m)/2^(m-1)) + 2^(m-1)*floor((1/2)*min(n+1-2^m,2^(m-1)+1)) + 3*2^(m-1)*floor((1/2)*max(n+1-3*2^(m-1),0)) + 3*sum_{j=2 .. m-1} floor((n+2^(j-1)-2^m)/2^j)*2^(m-j). [Seems correct for n > 3. - The Editors] %F A006995 Inversion formula: The index of any binary palindrome b = a(n) > 0 is n = palindromicIndex(b) = ((5-(-1)^m)/2 + Sum_{k=1..[m/2]} ([b/2^k] mod 2)/2^k)*2^[m/2], where [.] = floor(.) and m = [log_2(b)]. %F A006995 (End) %F A006995 G.f.: g(x) = x^2 + 3x^3 + sum_{j=1..oo}( 3*2^j*(1-x^floor((j+1)/2))/(1-x)*x^((1/2)-floor((j+1)/2)) + f_j(x) - f_j(1/x))*x^(2*2^floor(j/2)+3*2^floor((j-1)/2)-(1/2)), where the f_j(x) are defined as follows: %F A006995 f_1(x) = x^(1/2), and for j > 1, %F A006995 f_j(x) = x^(1/2)*sum_{i=0..2^floor((j-1)/2)-1}((3+(1/2)*sum_{k=1..floor((j-1)/2)}(1-(-1)^floor(2i/2^k))*b(j,k))*x^i), where b(j,k) = 2^(floor((j-1)/2)-k)*((3+(-1)^j)*2^(2*k+1)+4) for k > 1, and b(j,1) = (2+(-1)^j)*2^(floor((j-1)/2)+1). - _Hieronymus Fischer_, Apr 04 2012 %F A006995 A044051(n) = (a(n)+1)/2 for n > 0. - _Reinhard Zumkeller_, Apr 20 2015 %F A006995 A145799(a(n)) = a(n). - _Reinhard Zumkeller_, Sep 24 2015 %F A006995 Sum_{n>=2} 1/a(n) = A244162. - _Amiram Eldar_, Oct 17 2020 %e A006995 a(3) = 3, since 3 = 11_2 is the 3rd symmetric binary number; %e A006995 a(6) = 9, since 9 = 1001_2 is the 6th symmetric binary number. %p A006995 dmax:= 15; # to get all terms with at most dmax binary digits %p A006995 revdigs:= proc(n) %p A006995 local L, Ln, i; %p A006995 L:= convert(n,base,2); %p A006995 Ln:= nops(L); %p A006995 add(L[i]*2^(Ln-i),i=1..Ln); %p A006995 end proc; %p A006995 A:= {0,1}: %p A006995 for d from 2 to dmax do %p A006995 if d::even then %p A006995 A:= A union {seq(2^(d/2)*x + revdigs(x),x=2^(d/2-1)..2^(d/2)-1)} %p A006995 else %p A006995 m:= (d-1)/2; %p A006995 B:={seq(2^(m+1)*x + revdigs(x),x=2^(m-1)..2^m-1)}; %p A006995 A:= A union B union map(`+`,B,2^m) %p A006995 fi %p A006995 od: %p A006995 A; # _Robert Israel_, Aug 17 2014 %t A006995 palQ[n_Integer, base_Integer] := Module[{idn=IntegerDigits[n, base]}, idn==Reverse[idn]]; Select[Range[1000], palQ[ #, 2]&] %t A006995 Select[ Range[0, 1000], # == IntegerReverse[#, 2] &] (* _Robert G. Wilson v_, Feb 24 2018 *) %t A006995 Select[Range[0, 1000], PalindromeQ[IntegerDigits[#, 2]]&] (* _Jean-François Alcover_, Mar 01 2018 *) %o A006995 (PARI) for(n=0,999,n-subst(Polrev(binary(n)),x,2)||print1(n,",")) \\ _Thomas Buchholz_, Aug 16 2014 %o A006995 (PARI) for(n=0,10^3, my(d=digits(n,2)); if(d==Vecrev(d), print1(n,", "))); \\ _Joerg Arndt_, Aug 17 2014 %o A006995 (PARI) is_A006995(n)=Vecrev(n=binary(n))==n \\ _M. F. Hasler_, Feb 23 2018 %o A006995 (PARI) A006995(n,m=logint(n,2),c=1<<(m-1),a,d)={if(n>=3*c,a=n-3*c;d=2*c^2,a=n-2*c;n%2*c+d=c^2)+sum(k=1,m-2^(n<3*c),if(bittest(a,m-1-k),1<<k+d>>k))+(n>2)} \\ Based on Fischer's smalltalk program. - _M. F. Hasler_, Feb 23 2018 %o A006995 (Magma) [n: n in [0..850] | Intseq(n,2) eq Reverse(Intseq(n,2))]; // _Bruno Berselli_, Aug 29 2011 %o A006995 (Haskell) %o A006995 a006995 n = a006995_list !! (n-1) %o A006995 a006995_list = 0 : filter ((== 1) . a178225) a005408_list %o A006995 -- _Reinhard Zumkeller_, Oct 21 2011 %o A006995 (Smalltalk) %o A006995 A006995 %o A006995 "Answer the n-th binary palindrome %o A006995 (nonrecursive implementation)" %o A006995 | m n a b c d k2 | %o A006995 n := self. %o A006995 n = 1 ifTrue: [^0]. %o A006995 n = 2 ifTrue: [^1]. %o A006995 m := n integerFloorLog: 2. %o A006995 c := 2 raisedToInteger: m - 1. %o A006995 n >= (3 * c) %o A006995 ifTrue: %o A006995 [a := n - (3 * c). %o A006995 d := 2 * c * c. %o A006995 b := d + 1. %o A006995 k2 := 1. %o A006995 1 to: m - 1 %o A006995 do: %o A006995 [:k | %o A006995 k2 := 2 * k2. %o A006995 b := b + (a * k2 // c \\ 2 * (k2 + (d // k2)))]] %o A006995 ifFalse: %o A006995 [a := n - (2 * c). %o A006995 d := c * c. %o A006995 b := d + 1 + (n \\ 2 * c). %o A006995 k2 := 1. %o A006995 1 to: m - 2 %o A006995 do: %o A006995 [:k | %o A006995 k2 := 2 * k2. %o A006995 b := b + (a * k2 // c \\ 2 * (k2 + (d // k2)))]]. %o A006995 ^b // by _Hieronymus Fischer_, Feb 15 2013 %o A006995 (Sage) %o A006995 def palgenbase2(): # generator of palindromes in base 2 %o A006995 yield 0 %o A006995 x, n, n2 = 1, 1, 2 %o A006995 while True: %o A006995 for y in range(n,n2): %o A006995 s = format(y,'b') %o A006995 yield int(s+s[-2::-1],2) %o A006995 for y in range(n,n2): %o A006995 s = format(y,'b') %o A006995 yield int(s+s[::-1],2) %o A006995 x += 1 %o A006995 n *= 2 %o A006995 n2 *= 2 # _Chai Wah Wu_, Jan 07 2015 %o A006995 (Sage) %o A006995 [n for n in (0..843) if Word(n.digits(2)).is_palindrome()] # _Peter Luschny_, Sep 13 2018 %o A006995 (Python) %o A006995 from itertools import count, islice, product %o A006995 def bin_pals(): # generator of binary palindromes in base 10 %o A006995 yield from [0, 1] %o A006995 digits, midrange = 2, [[""], ["0", "1"]] %o A006995 for digits in count(2): %o A006995 for p in product("01", repeat=digits//2-1): %o A006995 left = "1"+"".join(p) %o A006995 for middle in midrange[digits%2]: %o A006995 yield int(left + middle + left[::-1], 2) %o A006995 print(list(islice(bin_pals(), 58))) # _Michael S. Branicky_, Jan 09 2023 %o A006995 (Python) %o A006995 def A006995(n): %o A006995 if n == 1: return 0 %o A006995 a = 1<<(l:=n.bit_length()-2) %o A006995 m = a|(n&a-1) %o A006995 return (m<<l+1)+int(bin(m)[-1:1:-1]or'0',2) if a&n else (m<<l)+int(bin(m)[-2:1:-1]or'0',2) # _Chai Wah Wu_, Jun 10 2024 %Y A006995 See A057148 for the binary representations. %Y A006995 Cf. A178225, A005408, A164126, A154809 (complement). %Y A006995 Cf. A002113, A048700, A048701, A206913, A206914, A244162. %Y A006995 Even numbers that are not the sum of two terms: A241491, A261678, A262556. %Y A006995 Cf. A145799. %Y A006995 Primes: A016041 and A117697. %Y A006995 Cf. A000051 (a subsequence). %K A006995 nonn,base,easy,nice,hear %O A006995 1,3 %A A006995 _N. J. A. Sloane_, _Robert G. Wilson v_, _Mira Bernstein_, L. J. Upton %E A006995 Edited and extended by _Hieronymus Fischer_, Feb 21 2012 %E A006995 Edited by _M. F. Hasler_, Feb 23 2018