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

A006995 Binary palindromes: numbers whose binary expansion is palindromic.

Original entry on oeis.org

0, 1, 3, 5, 7, 9, 15, 17, 21, 27, 31, 33, 45, 51, 63, 65, 73, 85, 93, 99, 107, 119, 127, 129, 153, 165, 189, 195, 219, 231, 255, 257, 273, 297, 313, 325, 341, 365, 381, 387, 403, 427, 443, 455, 471, 495, 511, 513, 561, 585, 633, 645, 693, 717, 765, 771, 819, 843
Offset: 1

Views

Author

Keywords

Comments

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
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
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
From Hieronymus Fischer, Jan 23 2013: (Start)
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.
Also: A070939(a(n)) = A070939(n) + A070939(floor(n/3)) - 1, for n <> 2. (End)
Rajasekaran, Shallit, & Smith show that this is an additive basis of order 4. - Charles R Greathouse IV, Nov 06 2018

Examples

			a(3) = 3, since 3 = 11_2 is the 3rd symmetric binary number;
a(6) = 9, since 9 = 1001_2 is the 6th symmetric binary number.
		

References

  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).

Crossrefs

See A057148 for the binary representations.
Cf. A178225, A005408, A164126, A154809 (complement).
Even numbers that are not the sum of two terms: A241491, A261678, A262556.
Cf. A145799.
Primes: A016041 and A117697.
Cf. A000051 (a subsequence).

Programs

  • Haskell
    a006995 n = a006995_list !! (n-1)
    a006995_list = 0 : filter ((== 1) . a178225) a005408_list
    -- Reinhard Zumkeller, Oct 21 2011
    
  • Magma
    [n: n in [0..850] | Intseq(n,2) eq Reverse(Intseq(n,2))];  // Bruno Berselli, Aug 29 2011
    
  • Maple
    dmax:= 15; # to get all terms with at most dmax binary digits
    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;
    A:= {0,1}:
    for d from 2 to dmax do
      if d::even then
        A:= A union {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)};
        A:= A union B union map(`+`,B,2^m)
      fi
    od:
    A;  # Robert Israel, Aug 17 2014
  • Mathematica
    palQ[n_Integer, base_Integer] := Module[{idn=IntegerDigits[n, base]}, idn==Reverse[idn]]; Select[Range[1000], palQ[ #, 2]&]
    Select[ Range[0, 1000], # == IntegerReverse[#, 2] &] (* Robert G. Wilson v, Feb 24 2018 *)
    Select[Range[0, 1000], PalindromeQ[IntegerDigits[#, 2]]&] (* Jean-François Alcover, Mar 01 2018 *)
  • PARI
    for(n=0,999,n-subst(Polrev(binary(n)),x,2)||print1(n,",")) \\ Thomas Buchholz, Aug 16 2014
    
  • PARI
    for(n=0,10^3, my(d=digits(n,2)); if(d==Vecrev(d), print1(n,", "))); \\ Joerg Arndt, Aug 17 2014
    
  • PARI
    is_A006995(n)=Vecrev(n=binary(n))==n \\ M. F. Hasler, Feb 23 2018
    
  • 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))+(n>2)} \\ Based on Fischer's smalltalk program. - M. F. Hasler, Feb 23 2018
    
  • Python
    from itertools import count, islice, product
    def bin_pals(): # generator of binary palindromes in base 10
        yield from [0, 1]
        digits, midrange = 2, [[""], ["0", "1"]]
        for digits in count(2):
            for p in product("01", repeat=digits//2-1):
                left = "1"+"".join(p)
                for middle in midrange[digits%2]:
                    yield int(left + middle + left[::-1], 2)
    print(list(islice(bin_pals(), 58))) # Michael S. Branicky, Jan 09 2023
    
  • Python
    def A006995(n):
        if n == 1: return 0
        a = 1<<(l:=n.bit_length()-2)
        m = a|(n&a-1)
        return (m<Chai Wah Wu, Jun 10 2024
  • Sage
    def palgenbase2(): # generator of palindromes in base 2
        yield 0
        x, n, n2 = 1, 1, 2
        while True:
            for y in range(n,n2):
                s = format(y,'b')
                yield int(s+s[-2::-1],2)
            for y in range(n,n2):
                s = format(y,'b')
                yield int(s+s[::-1],2)
            x += 1
            n *= 2
            n2 *= 2 # Chai Wah Wu, Jan 07 2015
    
  • Sage
    [n for n in (0..843) if Word(n.digits(2)).is_palindrome()] # Peter Luschny, Sep 13 2018
    
  • Smalltalk
    A006995
    "Answer the n-th binary palindrome
    (nonrecursive implementation)"
    | m n a b c d k2 |
    n := self.
    n = 1 ifTrue: [^0].
    n = 2 ifTrue: [^1].
    m := n integerFloorLog: 2.
    c := 2 raisedToInteger: m - 1.
    n >= (3 * c)
      ifTrue:
       [a := n - (3 * c).
       d := 2 * c * c.
       b := d + 1.
       k2 := 1.
       1 to: m - 1
        do:
         [:k |
         k2 := 2 * k2.
         b := b + (a * k2 // c \\ 2 * (k2 + (d // k2)))]]
      ifFalse:
       [a := n - (2 * c).
       d := c * c.
       b := d + 1 + (n \\ 2 * c).
       k2 := 1.
       1 to: m - 2
        do:
         [:k |
         k2 := 2 * k2.
         b := b + (a * k2 // c \\ 2 * (k2 + (d // k2)))]].
    ^b // by Hieronymus Fischer, Feb 15 2013
    

Formula

A178225(a(n)) = 1; union of A048700 and A048701. - Reinhard Zumkeller, Oct 21 2011
From Hieronymus Fischer, Dec 31 2008, Jan 10 2012, Feb 18 2012: (Start)
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...:
a(1000) = 249903,
a(10^4) = 24183069,
a(10^5) = 2258634081,
a(10^6) = 249410097687,
a(10^7) = 24350854001805,
a(10^8) = 2229543293296319,
a(10^9) = 248640535848971067,
a(10^10)= 24502928886295666773.
Inequality: (2/9)*n^2 < a(n) < (1/4)*(n+1)^2, if n > 1.
lim sup_{n -> oo} a(n)/n^2 = 1/4, lim inf_{n -> oo} a(n)/n^2 = 2/9.
For n >= 2, a(2^n-1) = 2^(2n-2) - 1; a(2^n) = 2^(2n-2) + 1;
a(2^n+1) = 2^(2n-2) + 2^(n-1) + 1; a(2^n + 2^(n-1)) = 2^(2n-1) + 1.
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:
Case 1: If n = 2^(k+1), then p = 0, q = 0, m = 1;
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;
Case 3: If n = 2^k + 2^(k-1), then p = 0, q = 1, m = 1;
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.
Non-recursive formula:
Let n >= 3, m = floor(log_2(n)), p = floor((3*2^(m-1)-1)/n), then
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]
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]
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)].
(End)
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_1(x) = x^(1/2), and for j > 1,
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
A044051(n) = (a(n)+1)/2 for n > 0. - Reinhard Zumkeller, Apr 20 2015
A145799(a(n)) = a(n). - Reinhard Zumkeller, Sep 24 2015
Sum_{n>=2} 1/a(n) = A244162. - Amiram Eldar, Oct 17 2020

Extensions

Edited and extended by Hieronymus Fischer, Feb 21 2012
Edited by M. F. Hasler, Feb 23 2018

A241491 2*n is not the sum of two base-2 palindromes.

Original entry on oeis.org

88, 94, 104, 121, 122, 155, 262, 314, 328, 368, 377, 397, 416, 431, 433, 434, 440, 466, 472, 497, 500, 590, 620, 654, 655, 664, 671, 676, 688, 704, 710, 716, 720, 905, 945, 961, 973, 977, 1063, 1103, 1114, 1131, 1228, 1234, 1249, 1250, 1270, 1312, 1343, 1348
Offset: 1

Views

Author

Robert Israel, Apr 24 2014

Keywords

Comments

Note that since all nonzero base-2 palindromes are odd, the sum of two nonzero base-2 palindromes is even.

Examples

			86 is not in the sequence because 2*86 = 7 + 165, and 7 and 165 are in A006995.
		

Crossrefs

Cf. A006995, A261678 (values of 2n).

Programs

  • Maple
      N:= 15; # for all entries up to 2^(N-1)
    with(SignalProcessing): # requires Maple 17+
    rev2:= proc(n) option remember;
      rev2(floor(n/2)) + (n mod 2)*2^ilog2(n)
    end;
    rev2(0) := 0; rev2(1):= 1;
    B:= Array(1..2^N,datatype=float[8]);
    for d from 1 to N do
      d1:= ceil(d/2);
      for x from 2^(d1-1) to 2^d1-1 do
        if d::even then y:= x*2^d1+rev2(x)
        else y:= x*2^(d1-1)+rev2(floor(x/2));
        fi;
      B[y]:= 1;
    od od:
    B2:= Convolution(B,B);
    A241491:= select(t -> B2[2*t-1] < 0.5, [$1..2^(N-1)]); # Robert Israel, Apr 24 2014

A261679 Number of ordered pairs (u,v) of binary palindromes (see A006995) with u+v=n.

Original entry on oeis.org

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

Views

Author

N. J. A. Sloane, Sep 04 2015

Keywords

Examples

			8=1+7=3+5=5+3=7+1, so a(8)=4.
		

Crossrefs

For zeros see A241491, A261678.

Formula

G.f. = (Sum_{p in A006995} x^p)^2.

A262556 Even numbers that are not the sum of two binary palindromes (written in base 2).

Original entry on oeis.org

10110000, 10111100, 11010000, 11110010, 11110100, 100110110, 1000001100, 1001110100, 1010010000, 1011100000, 1011110010, 1100011010, 1101000000, 1101011110, 1101100010, 1101100100, 1101110000, 1110100100, 1110110000, 1111100010, 1111101000, 10010011100, 10011011000, 10100011100, 10100011110
Offset: 1

Views

Author

N. J. A. Sloane, Oct 12 2015

Keywords

Comments

This is A261678 written in base 2.
It would be nice to have an independent characterization of these binary strings.
Binary palindromes are odd, so no odd number is the sum of two of them.

Crossrefs

See also A006995 and A057148 (binary palindromes).

A264964 Numbers that are the sum of two binary palindromes of the same (binary) length.

Original entry on oeis.org

0, 2, 6, 10, 12, 14, 18, 24, 30, 34, 38, 42, 44, 48, 52, 54, 58, 62, 66, 78, 84, 90, 96, 102, 108, 114, 126, 130, 138, 146, 150, 158, 164, 166, 170, 172, 178, 180, 184, 186, 192, 198, 200, 204, 206, 212, 214, 218, 220, 226, 234, 238, 246, 254, 258, 282, 294, 306, 318, 324, 330, 342, 348, 354, 360, 372, 378, 384, 390, 396
Offset: 1

Views

Author

N. J. A. Sloane, Nov 29 2015

Keywords

Comments

Theorem: Adding two binary palindromes of length k >= 2 in all possible ways produces 3^floor((k-1)/2) distinct sums. (There are 2^floor((k-1)/2) binary palindromes of length k - see A006995.)

Examples

			There are four binary palindromes of length 5, namely (written in base 10) 17, 21, 27, 31, and adding them in pairs gives nine distinct numbers: 34, 38, 42, 44, 48, 52, 54, 58, 62.
There are eight binary palindromes of length 7, namely (written in base 10) 65, 73, 85, 93, 99, 107, 119, 127, and adding them in pairs gives 27 distinct numbers: 130, 138, 146, 150, 158, 164, 166, 170, 172, 178, 180, 184, 186, 192, 198, 200, 204, 206, 212, 214, 218, 220, 226, 234, 238, 246, 254.
		

Crossrefs

Programs

  • Mathematica
    f[n_] := Select[Map[FromDigits /@ IntegerDigits[#, 2] &, Map[Function[k, {k, # - k}], Range@ Floor[#/2]] &@ n], AllTrue[#, Reverse@ # == # &@ IntegerDigits@ # &] && IntegerLength@ First@ # == IntegerLength@ Last@ # &]; Prepend[Select[Range@ 400, Length@ f@ # > 0 &], 0] (* Michael De Vlieger, Nov 29 2015, Mma version 10 *)
    Join[{0},Table[Total/@Tuples[FromDigits[#,2]&/@Select[Tuples[{1,0},n], #[[1]] != 0&&#==Reverse[#]&],2]//Union,{n,8}]//Flatten] (* Harvey P. Dale, Apr 12 2017 *)

A319439 Number of ways to write n as the sum, u + v + w, of three base-2 palindromes (from A006995) with 0 <= u <= v <= w.

Original entry on oeis.org

1, 1, 1, 2, 1, 2, 2, 3, 2, 4, 3, 4, 2, 4, 2, 6, 2, 6, 3, 6, 2, 7, 3, 7, 3, 7, 2, 9, 2, 7, 3, 9, 3, 10, 4, 10, 4, 11, 3, 12, 2, 11, 3, 11, 1, 12, 2, 10, 4, 11, 2, 14, 3, 11, 4, 13, 1, 13, 2, 11, 3, 12, 2, 15, 2, 13, 5, 14, 3, 17, 2, 13, 4, 15, 2, 17, 2, 12, 4, 15
Offset: 0

Views

Author

Peter Kagey, Sep 18 2018

Keywords

Comments

Every number n can be written as the sum of four base-2 palindromes.
a(A261678(n)) = 0.

Examples

			a(13) = 4 because 13 can be written as the sum of three base-2 palindromes in four different ways:
13 = 5 + 5 + 3 = 101_2  + 101_2 + 11_2,
13 = 7 + 3 + 3 = 111_2  +  11_2 + 11_2,
13 = 7 + 5 + 1 = 111_2  + 101_2 +  1_2, and
13 = 9 + 3 + 1 = 1001_2 +  11_2 +  1_2.
		

Crossrefs

Programs

  • PARI
    See Links section.

Extensions

a(0) corrected by Rémy Sigrist, Sep 19 2018

A290424 Even numbers that are not the sum or difference of two binary palindromes (A006995).

Original entry on oeis.org

9404, 10120, 13714, 14576, 15812, 18622, 35102, 35438, 38696, 39164, 39656, 40072, 40712, 42776, 43096, 43256, 43780, 44560, 45284, 45796, 46346, 46532, 46624, 46858, 46880, 46984, 47936, 49622, 50810, 55048, 56600, 58564, 60932, 61190, 62792, 62986, 67816, 69244
Offset: 1

Views

Author

Altug Alkan, Jul 31 2017

Keywords

Comments

Intersection of A261678 and A290393.

Crossrefs

Programs

  • Mathematica
    g[w_] := FromDigits[Join @@ w, 2]; bp[1]={1}; bp[n_] := Block[{b,r, h = Floor[n/2]}, Sort@ Flatten@ Table[b = IntegerDigits[k, 2, h]; r = Reverse@ b; If[OddQ@n, g /@ {{b, {0}, r}, {b, {1}, r}}, g@{b, r}], {k, 2^h/2, 2^h - 1}]]; pp = Sort@ Flatten[Table[bp[h], {h, 32}]]; T = Range[35000]*0; i = 0; While[i < Length[pp] - 1, i++; j = i + 1; While[j <= Length[pp] && (d = pp[[j]] - pp[[i]]) <= 70000, T[[d/2]] = 1; j++]]; pp = Select[pp, # <= 70000 &]; Select[2 Flatten[ Position[T, 0]], {} == Quiet@ IntegerPartitions[#, {2}, pp, 1] &] (* Giovanni Resta, Aug 08 2017 *)

Extensions

a(7)-a(38) from Giovanni Resta, Aug 08 2017
Showing 1-7 of 7 results.