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-10 of 18 results. Next

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

A030101 a(n) is the number produced when n is converted to binary digits, the binary digits are reversed and then converted back into a decimal number.

Original entry on oeis.org

0, 1, 1, 3, 1, 5, 3, 7, 1, 9, 5, 13, 3, 11, 7, 15, 1, 17, 9, 25, 5, 21, 13, 29, 3, 19, 11, 27, 7, 23, 15, 31, 1, 33, 17, 49, 9, 41, 25, 57, 5, 37, 21, 53, 13, 45, 29, 61, 3, 35, 19, 51, 11, 43, 27, 59, 7, 39, 23, 55, 15, 47, 31, 63, 1, 65, 33, 97, 17, 81, 49, 113, 9, 73, 41, 105, 25, 89, 57
Offset: 0

Views

Author

Keywords

Comments

As with decimal reversal, initial zeros are ignored; otherwise, the reverse of 1 would be 1000000... ad infinitum.
Numerators of the binary van der Corput sequence. - Eric Rowland, Feb 12 2008
It seems that in most cases A030101(x) = A000265(x) and that if A030101(x) <> A000265(x), the next time A030101(y) = A000265(x), A030101(x) = A000265(y). Also, it seems that if a pair of values exist at one index, they will exist at any index where one of them exist. It also seems like the greater of the pair always shows up on A000265 first. - Dylan Hamilton, Aug 04 2010
The number of occasions A030101(n) = A000265(n) before n = 2^k is A053599(k) + 1. For n = 0..2^19, the sequences match less than 1% of the time. - Andrew Woods, May 19 2012
For n > 0: a(a(n)) = n if and only if n is odd; a(A006995(n)) = A006995(n). - Juli Mallett, Nov 11 2010, corrected: Reinhard Zumkeller, Oct 21 2011
n is binary palindromic if and only if a(n) = n. - Reinhard Zumkeller, corrected: Jan 17 2012, thanks to Hieronymus Fischer, who pointed this out; Oct 21 2011
Given any n > 1, the set of numbers A030109(i) = (A030101(i) - 1)/2 for indexes i ranging from 2^n to 2^(n + 1) - 1 is a permutation of the set of consecutive integers {0, 1, 2, ..., 2^n - 1}. This is important in the standard FFT algorithms (starting or ending bit-reversal permutation). - Stanislav Sykora, Mar 15 2012
Row n of A030308 gives the binary digits of a(n), prepended with zero at even positions. - Reinhard Zumkeller, Jun 17 2012
The binary van der Corput sequence is the infinite sequence of fractions { A030101(n)/A062383(n), n = 0, 1, 2, 3, ... }, and begins 0, 1/2, 1/4, 3/4, 1/8, 5/8, 3/8, 7/8, 1/16, 9/16, 5/16, 13/16, 3/16, 11/16, 7/16, 15/16, 1/32, 17/32, 9/32, 25/32, 5/32, 21/32, 13/32, 29/32, 3/32, 19/32, 11/32, 27/32, 7/32, 23/32, 15/32, 31/32, 1/64, 33/64, 17/64, 49/64, ... - N. J. A. Sloane, Dec 01 2019
Record highs occur at n = A209492(m) (for n>=1) with values a(n) = A224195(m) (for n>=3). - Bill McEachen, Aug 02 2023

Examples

			a(100) = 19 because 100 (base 10) = 1100100 (base 2) and R(1100100 (base 2)) = 10011 (base 2) = 19 (base 10).
		

References

  • Hlawka E. The theory of uniform distribution. Academic Publishers, Berkhamsted, 1984. See pp. 93, 94 for the van der Corput sequence. - N. J. A. Sloane, Dec 01 2019

Crossrefs

Cf. A055944 (reverse and add), A178225, A273258.
Cf. A056539, A057889 (bijective variants), A224195, A209492.

Programs

  • Haskell
    a030101 = f 0 where
       f y 0 = y
       f y x = f (2 * y + b) x'  where (x', b) = divMod x 2
    -- Reinhard Zumkeller, Mar 18 2014, Oct 21 2011
    
  • J
    ([: #. [: |. #:)"0 NB. Stephen Makdisi, May 07 2018
    
  • Magma
    A030101:=func; // Jason Kimberley, Sep 19 2011
    
  • Maple
    A030101 := proc(n)
        convert(n,base,2) ;
        ListTools[Reverse](%) ;
        add(op(i,%)*2^(i-1),i=1..nops(%)) ;
    end proc: # R. J. Mathar, Mar 10 2015
    # second Maple program:
    a:= proc(n) local m, r; m:=n; r:=0;
          while m>0 do r:=r*2+irem(m, 2, 'm') od; r
        end:
    seq(a(n), n=0..80);  # Alois P. Heinz, Nov 17 2015
  • Mathematica
    Table[FromDigits[Reverse[IntegerDigits[i, 2]], 2], {i, 0, 80}]
    bitRev[n_] := Switch[Mod[n, 4], 0, bitRev[n/2], 1, 2 bitRev[(n + 1)/2] - bitRev[(n - 1)/4], 2, bitRev[n/2], 3, 3 bitRev[(n - 1)/2] - 2 bitRev[(n - 3)/4]]; bitRev[0] = 0; bitRev[1] = 1; bitRev[3] = 3; Array[bitRev, 80, 0] (* Robert G. Wilson v, Mar 18 2014 *)
  • PARI
    a(n)=if(n<1,0,subst(Polrev(binary(n)),x,2))
    
  • PARI
    a(n) = fromdigits(Vecrev(binary(n)), 2); \\ Michel Marcus, Nov 10 2017
    
  • Python
    def a(n): return int(bin(n)[2:][::-1], 2) # Indranil Ghosh, Apr 24 2017
    
  • Sage
    def A030101(n): return Integer(bin(n).lstrip("0b")[::-1],2) if n!=0 else 0
    [A030101(n) for n in (0..78)]  # Peter Luschny, Aug 09 2012
    
  • Scala
    (0 to 127).map(n => Integer.parseInt(Integer.toString(n, 2).reverse, 2)) // Alonso del Arte, Feb 11 2020

Formula

a(n) = 0, a(2n) = a(n), a(2n+1) = a(n) + 2^(floor(log_2(n)) + 1). For n > 0, a(n) = 2*A030109(n) - 1. - Ralf Stephan, Sep 15 2003
a(n) = b(n, 0) with b(n, r) = r if n = 0, otherwise b(floor(n/2), 2*r + n mod 2). - Reinhard Zumkeller, Mar 03 2010
a(1) = 1, a(3) = 3, a(2n) = a(n), a(4n+1) = 2a(2n+1) - a(n), a(4n+3) = 3a(2n+1) - 2a(n) (as in the Project Euler problem). To prove this, expand the recurrence into binary strings and reversals. - David Applegate, Mar 16 2014, following a posting to the Sequence Fans Mailing List by Martin Møller Skarbiniks Pedersen.
Conjecture: a(n) = 2*w(n) - 2*w(A053645(n)) - 1 for n > 0, where w = A264596. - Velin Yanev, Sep 12 2017

Extensions

Edits (including correction of an erroneous date pointed out by J. M. Bergot) by Jon E. Schoenfield, Mar 16 2014
Name clarified by Antti Karttunen, Nov 09 2017

A007632 Numbers that are palindromic in bases 2 and 10.

Original entry on oeis.org

0, 1, 3, 5, 7, 9, 33, 99, 313, 585, 717, 7447, 9009, 15351, 32223, 39993, 53235, 53835, 73737, 585585, 1758571, 1934391, 1979791, 3129213, 5071705, 5259525, 5841485, 13500531, 719848917, 910373019, 939474939, 1290880921, 7451111547
Offset: 1

Views

Author

Keywords

Comments

Charlton Harrison found a new record binary-decimal palindrome: 11000101111000010101010110100001110100000100000101110000101101010101000011110100011_2 = 7475703079870789703075747_10 on Dec 01 2001. The binary string contains 83 digits! Since then he has added twenty more terms. - Robert G. Wilson v, Jul 03 2006
Intersection of A002113 and A006995. - Reinhard Zumkeller, Jan 22 2012, Feb 07 2010

References

  • M. R. Calandra, Integers which are palindromic in both decimal and binary notation, J. Rec. Math., 18 (No. 1, 1985-1986), 47.
  • S. Pilpel, Some More Double Palindromic Integers, J. Rec. Math., 18 (1985), 174-176.
  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).

Crossrefs

For number of terms less than or equal to 10^n, see A120764.

Programs

  • Haskell
    a007632 n = a007632_list !! (n-1)
    a007632_list = filter ((== 1) . a178225) a002113_list
    -- Reinhard Zumkeller, Jan 22 2012
    
  • Magma
    [n: n in [0..2*10^7] | Intseq(n, 10) eq Reverse(Intseq(n, 10))and Intseq(n, 2) eq Reverse(Intseq(n, 2))]; // Vincenzo Librandi, Dec 31 2015
    
  • Maple
    N:= 12: # to get all terms <= 10^N
    ispal2:= proc(n) local L; if n::even then return false fi;
      L:= convert(n,base,2); evalb(L=ListTools:-Reverse(L)) end proc:
    rev10:= proc(n) local L; L:= convert(n,base,10); add(10^i*L[-i-1],i=0..nops(L)-1) end proc:
    pals10:= proc(d) local x,y;
      if d::even then [seq(x*10^(d/2)+rev10(x),x=10^(d/2-1)..10^(d/2)-1)]
      else [seq(seq(x*10^((d+1)/2)+y*10^((d-1)/2)+rev10(x), y=0..9), x=10^((d-1)/2-1)..10^((d-1)/2)-1)]
      fi
    end proc:
    0, 1, 3, 5, 7, 9, seq(op(select(ispal2,pals10(d))),d=2..N); # Robert Israel, Dec 31 2015
  • Mathematica
    NextPalindrome[n_] := Block[{l = Floor[ Log[10, n] + 1], idn = IntegerDigits[n]}, If[ Union[ idn] == {9}, Return[n + 2], If[l < 2, Return[n + 1], If[ FromDigits[ Reverse[ Take[idn, Ceiling[l/2]] ]] > FromDigits[ Take[idn, -Ceiling[l/2]]], FromDigits[ Join[ Take[idn, Ceiling[l/2]], Reverse[ Take[idn, Floor[l/2]]] ]], idfhn = FromDigits[ Take[idn, Ceiling[l/2]]] + 1; idp = FromDigits[ Join[ IntegerDigits[ idfhn], Drop[ Reverse[ IntegerDigits[ idfhn]], Mod[l, 2]] ]] ]] ]]; palQ[n_Integer, base_Integer]:= Block[{idn = IntegerDigits[n, base]}, idn == Reverse[idn]]; l = {0}; a = 0; Do[a = NextPalindrome[a]; If[ palQ[a, 2], AppendTo[l, a]], {n, 1000000}]; l (* Robert G. Wilson v, Sep 30 2004 *)
    b1=2; b2=10; lst={}; Do[d1=IntegerDigits[n, b1]; d2=IntegerDigits[n, b2]; If[d1==Reverse[d1]&&d2==Reverse[d2], AppendTo[lst, n]], {n, 0, 2 10^7}]; lst (* Vincenzo Librandi, Dec 31 2015 *)
    Select[Range[0,10^5], PalindromeQ[#] && # == IntegerReverse[#, 2] &] (* Robert Price, Nov 09 2019 *)
  • PARI
    isok(n) = my(d = digits(n), b=binary(n)); (d == Vecrev(d)) && (b == Vecrev(b)); \\ Michel Marcus, Dec 31 2015
  • Python
    from itertools import chain
    A007632_list = sorted([n for n in chain((int(str(x)+str(x)[::-1]) for x in range(1,10**6)),(int(str(x)+str(x)[-2::-1]) for x in range(10**6))) if bin(n)[2:] == bin(n)[:1:-1]]) # Chai Wah Wu, Nov 23 2014
    

Extensions

One more term from George Russell (ger(AT)tzi.de), Nov 20 2000
Two further terms from Harvey P. Dale, Mar 09 2001
Further terms from George Russell (ger(AT)tzi.de), Nov 02 2001

A136522 a(n) = 1 if n is a palindrome, otherwise 0.

Original entry on oeis.org

1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Offset: 0

Views

Author

N. J. A. Sloane, Apr 21 2008

Keywords

Comments

a(A002113(n)) = 1; a(A029742(n)) = 0.
a(n) = A202022(n) for n <= 100, a(101) = 1, A202022(101) = 0. - Reinhard Zumkeller, Dec 10 2011

Crossrefs

Programs

  • Haskell
    a136522 n = fromEnum $ n == a004086 n  -- Reinhard Zumkeller, Apr 08 2011
    
  • Mathematica
    fQ[n_]:=Module[{id=IntegerDigits[n]}, Boole[id==Reverse[id]]]; Array[fQ, 100] (* Vladimir Joseph Stephan Orlovsky, Dec 29 2010 *)
    Table[If[PalindromeQ[n],1,0],{n,0,120}] (* Requires Mathematica version 10 or later *) (* Harvey P. Dale, Aug 23 2019 *)
  • Python
    def A136522(n): return int((s:=str(n))[:(t:=(len(s)+1)//2)]==s[:-t-1:-1]) # Chai Wah Wu, Jun 23 2022

Formula

a(n) = if A004086(n) = n then 1 else 0. - Reinhard Zumkeller, Apr 08 2011
a(n) = A000007(A064834(n)). - Reinhard Zumkeller, Sep 18 2013

A057890 In base 2, either a palindrome or becomes a palindrome if trailing 0's are omitted.

Original entry on oeis.org

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 17, 18, 20, 21, 24, 27, 28, 30, 31, 32, 33, 34, 36, 40, 42, 45, 48, 51, 54, 56, 60, 62, 63, 64, 65, 66, 68, 72, 73, 80, 84, 85, 90, 93, 96, 99, 102, 107, 108, 112, 119, 120, 124, 126, 127, 128, 129, 130, 132, 136, 144, 146
Offset: 1

Views

Author

Marc LeBrun, Sep 25 2000

Keywords

Comments

Symmetric bit strings (bit-reverse palindromes), including as many leading as trailing zeros.
Fixed points of A057889, complement of A057891
n such that A000265(n) is in A006995. - Robert Israel, Jun 07 2016

Examples

			10 is included, since 01010 is a palindrome, but 11 is not because 1011 is not.
		

Crossrefs

Programs

  • Haskell
    a057890 n = a057890_list !! (n-1)
    a057890_list = 0 : filter ((== 1) . a178225 . a000265) [1..]
    -- Reinhard Zumkeller, Oct 21 2011
    
  • 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 *)
  • 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
  • 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
    

Formula

A030101(A030101(n)) = A030101(n). - David W. Wilson, Jun 09 2009, Jun 18 2009
A178225(A000265(a(n))) = 1. - Reinhard Zumkeller, Oct 21 2011
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

A048701 List of binary palindromes of even length (written in base 10).

Original entry on oeis.org

0, 3, 9, 15, 33, 45, 51, 63, 129, 153, 165, 189, 195, 219, 231, 255, 513, 561, 585, 633, 645, 693, 717, 765, 771, 819, 843, 891, 903, 951, 975, 1023, 2049, 2145, 2193, 2289, 2313, 2409, 2457, 2553, 2565, 2661, 2709, 2805, 2829, 2925, 2973, 3069, 3075, 3171, 3219, 3315
Offset: 0

Views

Author

Antti Karttunen, Mar 07 1999

Keywords

Comments

A178225(a(n)) = 1. - Reinhard Zumkeller, Oct 21 2011
a(n) is divisible by 3 and it is always an odd number for n > 0. Therefore a(n) is in A016945 for n > 0. - Altug Alkan, Dec 04 2015

Crossrefs

See also A048702 = this sequence divided by 3, A048700 = binary palindromes of odd length, A006995 = all binary palindromes, A048703 = quaternary (base 4) palindromes of even length.
For first differences see A265026, A265027.

Programs

  • Haskell
    a048701 n = foldr (\d v -> 2 * v + d) 0 (reverse bs ++ bs) where
       bs = a030308_row (n)
    -- Reinhard Zumkeller, Feb 19 2003, Oct 21 2011
    
  • Mathematica
    Prepend[Select[Range@ 3315, Reverse@ # == # && EvenQ@ Length@ # &@ IntegerDigits[#, 2] &], 0] (* Michael De Vlieger, Dec 04 2015 *)
  • PARI
    a048701(n) = my(f); f = length(binary(n)) - 1; 2^(f+1)*n + sum(i=0, f, bittest(n, i) * 2^(f-i)); \\ Altug Alkan, Dec 03 2015
    
  • Python
    def A048701(n):
        s = bin(n)[2:]
        return int(s+s[::-1],2) # Chai Wah Wu, Feb 26 2021

Formula

a(n) = (2^(floor_log_2(n)+1))*n + Sum_{i=0..floor_log_2(n)} '(bit_i(n, i)*(2^(floor_log_2(n)-i)))'.

Extensions

Offset corrected by Reinhard Zumkeller, Oct 21 2011
Offset changed back to 0 by Andrey Zabolotskiy, Dec 26 2022

A154809 Numbers whose binary expansion is not palindromic.

Original entry on oeis.org

2, 4, 6, 8, 10, 11, 12, 13, 14, 16, 18, 19, 20, 22, 23, 24, 25, 26, 28, 29, 30, 32, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, 48, 49, 50, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 64, 66, 67, 68, 69, 70, 71, 72, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 86, 87, 88
Offset: 1

Views

Author

Omar E. Pol, Jan 24 2009

Keywords

Comments

Complement of A006995.
The (a(n)-n+1)-th binary palindrome equals the greatest binary palindrome <= a(n). The corresponding formula identity is: A006995(a(n)-n+1)=A206913(a(n)). - Hieronymus Fischer, Mar 18 2012
A145799(a(n)) < a(n). - Reinhard Zumkeller, Sep 24 2015

Examples

			a(1)=2, since 2 = 10_2 is not binary palindromic.
		

Crossrefs

Programs

  • Haskell
    a154809 n = a154809_list !! (n-1)
    a154809_list = filter ((== 0) . a178225) [0..]
    
  • Magma
    [n: n in [0..600] | not (Intseq(n, 2) eq Reverse(Intseq(n, 2)))]; // Vincenzo Librandi, Jul 05 2015
    
  • Maple
    ispali:= proc(n) local L;
    L:= convert(n,base,2);
    ListTools:-Reverse(L)=L
    end proc:
    remove(ispali, [$1..1000]); # Robert Israel, Jul 05 2015
  • Mathematica
    palQ[n_Integer, base_Integer]:=Module[{idn=IntegerDigits[n, base]}, idn==Reverse[idn]]; Select[Range[1000], ! palQ[#, 2] &] (* Vincenzo Librandi, Jul 05 2015 *)
  • PARI
    isok(n) = binary(n) != Vecrev(binary(n)); \\ Michel Marcus, Jul 05 2015
    
  • Python
    def A154809(n):
        def f(x): return n+(x>>(l:=x.bit_length())-(k:=l+1>>1))-(int(bin(x)[k+1:1:-1],2)>(x&(1<Chai Wah Wu, Jul 24 2024

Formula

A030101(n) != n. - David W. Wilson, Jun 09 2009
A178225(a(n)) = 0. - Reinhard Zumkeller, Oct 21 2011
From Hieronymus Fischer, Feb 19 2012 and Mar 18 2012: (Start)
Inversion formula: If d is any number from this sequence, then the index number n for which a(n)=d can be calculated by n=d+1-A206915(A206913(d)).
Explicitly: Let p=A206913(d), m=floor(log_2(p)) and p>2, then: a(n)=d+1+(((5-(-1)^m)/2) + sum(k=1...floor(m/2)|(floor(p/2^k) mod 2)/2^k))*2^floor(m/2).
Example 1: d=1000, A206913(d)=975, A206915(975)=62, hence n=1001-62=939.
Example 2: d=10^6, A206913(d)=999471, A206915(999471)=2000, hence n=1000001-2000=998001.
Recursion formulas:
a(n+1)=a(n)+1+A178225(a(n)+1)
Also:
Case 1: a(n+1)=a(n)+2, if A206914(a(n))=a(n)+1;
Case 2: a(n+1)=a(n)+1, else.
Also:
Case 1: a(n+1)=a(n)+1, if A206914(a(n))>a(n)+1;
Case 2: a(n+1)=a(n)+2, else.
Iterative calculation formula:
Let f(0):=n+1, f(j):=n-1+A206915(A206913(f(j-1)) for j>0; then a(n)=f(j), if f(j)=f(j-1). The number of necessary steps is typically <4 and is limited by O(log_2(n)).
Example 3: n=1000, f(0)=1001, f(1)=1061, f(2)=1064=f(3), hence a(1000)=1064.
Example 4: n=10^6, f(0)=10^6+1, f(1)=1001999, f(2)=1002001=f(3), hence a(10^6)=1002001.
Formula identity:
a(n) = n-1 + A206915(A206913(a(n))).
(End)

Extensions

Extended by Ray Chandler, Mar 14 2010

A206915 The index (in A006995) of the greatest binary palindrome <= n; also the 'lower inverse' of A006995.

Original entry on oeis.org

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

Views

Author

Hieronymus Fischer, Feb 15 2012

Keywords

Comments

The greatest m such that A006995(m)<= n;
The number of binary palindromes <= n;
n is palindromic iff a(n)=A206916(n);
a(n) is the number of the binary palindrome A206913(n);
if n is a binary palindrome, then A006995(a(n))=n, so a(n) is 'inverse' with respect to A006995.
Partial sums of the binary palindromic characteristic function A178225.

Examples

			a(1)=2 since 2 is the index number of the greatest binary palindrome <= 1;
a(5)=4 since there are only 4 binary palindromes (namely 0,1,3 and 5) which are less than or equal to 5;
a(10)=6 since A006995(6)=9<=10, but A006995(7)=15>10, and so that, 6 is the index number of greatest binary palindrome <= 10;
		

Crossrefs

Programs

  • Mathematica
    A178225[n_]:=Boole[PalindromeQ[IntegerDigits[n,2]]];
    Accumulate[Array[A178225,100,0]] (* Paolo Xausa, Oct 15 2023 *)
  • Python
    def A206915(n):
        l = n.bit_length()
        k = l+1>>1
        return (n>>l-k)-(int(bin(n)[k+1:1:-1] or '0',2)>(n&(1<Chai Wah Wu, Jul 24 2024

Formula

a(n) = max(m | A006995(m) <= n);
a(A006995(n)) = n;
A006995(a(n)) <= n, equality holds true iff n is a binary palindrome;
Let p = A206913(n), m = floor(log_2(p)) and p>2, then:
a(n) = (((5-(-1)^m)/2) + sum_{k=1..floor(m/2)} (floor(p/2^k) mod 2)/2^k)) * 2^floor(m/2).
a(n) = (1/2)*((6-(-1)^m)*2^floor(m/2) - 1 - sum_{k=1..floor(m/2)} (-1)^floor(p/2^k) * 2^(floor(m/2)-k))).
a(n) = (5-(-1)^m) * 2^floor(m/2)/2 - 3*sum_{k=2..floor(m/2)} (floor(p/2^k) * 2^floor(m/2)/2^k) + (floor(p/2) * 2^floor(m/2)/2 - 2*floor((p/2) * 2^floor(m/2)) * floor((m-1)/m+1/2).
Partial sums S(n) = sum_{k=0..n} a(k):
S(n) = (n+1)*a(n) - A206920(a(n)).
G.f.: g(x) = (1+x+x^3+sum_{j>=1} x^(3*2^j)*(f_j(x)+f_j(1/x)))/(1-x), where the f_j(x) are defined as follows:
f_1(x) = x, and for j>1,
f_j(x) = x^3*product_{k=1..floor((j-1)/2)} (1+x^b(j,k)), 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).

A206923 Number of bisections of the n-th binary palindrome bit pattern until the result is not palindromic.

Original entry on oeis.org

1, 1, 2, 1, 3, 1, 3, 1, 2, 1, 4, 1, 2, 1, 4, 1, 2, 1, 1, 1, 1, 1, 4, 1, 2, 1, 1, 1, 1, 1, 4, 1, 2, 1, 1, 1, 3, 1, 1, 1, 1, 1, 2, 1, 1, 1, 5, 1, 2, 1, 1, 1, 3, 1, 1, 1, 1, 1, 2, 1, 1, 1, 5, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 2, 1
Offset: 1

Views

Author

Hieronymus Fischer, Mar 12 2012

Keywords

Comments

Let k=1, p(1)=A006995(n) and m(1)=number of bits in p(1); if p(k) is a binary palindrome > 1 then iterate k=k+1, m(k)=floor((m(k-1)+1)/2), p(k)=leftmost m(k) bits of p(k-1); else set a(n)=k endif.

Examples

			a(1)=a(2)=1, since A006995(1)=0 and A006995(2)=1;
a(5)=3, since A006995(5)=7=111_2 and so the iteration is 11==>11==>1;
a(9)=2, since A006995(9)=21=10101_2 and so the iteration is 10101==>101;
a(13)=2, since A006995(13)=45=101101_2 and so the iteration is 101101==>101;
a(15)=4, since A006995(15)=63=111111_2 and so the iteration is 111111==>111==>11==>1;
a(37)=3, since A006995(37)=341=101010101_2 and so the iteration is 101010101==>10101==>101;
		

Crossrefs

Programs

  • C
    /* quasi-C program fragment, omitting formal details, n>1 */
    p=n;
    p1=n+1;
    k=0;
    while (A178225(p)==1) && (p != p1)
    {
      p1=p;
      k++;
      m=int(log(p)/log(2));
      p=int(p/2^int((m+1)/2));
    }
    return k;

Formula

Recursion: define f(x)=floor(A006995(x)/2^floor(floor(log_2(A006995(x))+1)/2)), for x=1,2,3,...
Case 1: a(n)=1+a(A206915(f(n))), if f(n) is a binary palindrome;
Case 2: a(n)=1, else.
Formally: a(n)=if (A178225(f(n))==1) then a(A206915(f(n)))+1 else 1.

A057891 In base 2, neither a palindrome nor becomes a palindrome if trailing 0's are omitted.

Original entry on oeis.org

11, 13, 19, 22, 23, 25, 26, 29, 35, 37, 38, 39, 41, 43, 44, 46, 47, 49, 50, 52, 53, 55, 57, 58, 59, 61, 67, 69, 70, 71, 74, 75, 76, 77, 78, 79, 81, 82, 83, 86, 87, 88, 89, 91, 92, 94, 95, 97, 98, 100, 101, 103, 104, 105, 106, 109, 110, 111, 113, 114, 115, 116, 117, 118
Offset: 1

Views

Author

Marc LeBrun, Sep 25 2000

Keywords

Comments

These could be called "asymmetric bit strings".
Fixed pairs of A057889, complement of A057890.
If these numbers are converted to their binary polynomial, one of the roots of that polynomial will have absolute values other than 1 or 0. For example 11 = 2^3 + 2^1 + 2^0, the absolute values of the roots of x^3 + x + 1 are 0.682328... and 1.21061... which are not 1 or 0, so 11 is in the sequence. The first number with this property which is not a term is A057890(53) = 107. - Benedict W. J. Irwin, Sep 07 2017 and Andrey Zabolotskiy, Oct 13 2017

Examples

			11 is included because 1011 is asymmetrical, but 12 is not because 001100 is a palindrome.
		

Crossrefs

Cf. A061917, A006995. Complement of A057890.

Programs

  • Haskell
    a057891 n = a057891_list !! (n-1)
    a057891_list = filter ((== 0) . a178225 . a000265) [1..]
    -- Reinhard Zumkeller, Oct 21 2011

Formula

A030101(A030101(n)) != A030101(n). - David Wilson, Jun 09 2009, Jun 18 2009
A178225(A000265(a(n))) = 0. - Reinhard Zumkeller, Oct 21 2011

Extensions

Edited by N. J. A. Sloane, Jun 09 2009 at the suggestion of Ray Chandler
A-numbers in formula corrected by R. J. Mathar, Jun 18 2009
Showing 1-10 of 18 results. Next