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.

A108918 Reversed binary words in reversed lexicographic order.

Original entry on oeis.org

1, 3, 2, 5, 7, 6, 4, 9, 11, 10, 13, 15, 14, 12, 8, 17, 19, 18, 21, 23, 22, 20, 25, 27, 26, 29, 31, 30, 28, 24, 16, 33, 35, 34, 37, 39, 38, 36, 41, 43, 42, 45, 47, 46, 44, 40, 49, 51, 50, 53, 55, 54, 52, 57, 59, 58, 61, 63, 62, 60, 56, 48, 32, 65
Offset: 1

Views

Author

Joerg Arndt, Jul 20 2005

Keywords

Comments

The lexicographic order of the subsets of the 4-element set is:
1... {0}
11.. {0, 1}
111. {0, 1, 2}
1111 {0, 1, 2, 3}
11.1 {0, 1, 3}
1.1. {0, 2}
1.11 {0, 2, 3}
1..1 {0, 3}
.1.. {1}
.11. {1, 2}
.111 {1, 2, 3}
.1.1 {1, 3}
..1. {2}
..11 {2, 3}
...1 {3}
The strings of dots and ones interpreted as binary words give this sequence:
...1 1
..11 3
..1. 2
.1.1 5
.111 7
.11. 6
.1.. 4
1..1 9
1.11 11
1.1. 10
11.1 13
1111 15
111. 14
11.. 12
1... 8
The index of the lowest set bit of a(n) is A082850(n) - 1. - Joerg Arndt, Apr 06 2011
The sequence is a permutation of the positive integers. - Joerg Arndt, Jan 31 2012
This is the output of the depth-first search with postordering in the binomial tree described in A129760 where the children of every node are visited in the ascending order of their values. Descending order cannot be used because 0 has infinite number of children; using preordering instead of postordering gives the natural numbers in their standard order. - Andrey Zabolotskiy, Sep 06 2019

References

  • Donald E. Knuth, The Art of Computer Programming, Volume 4A, section 7.2.1.3 exercise 19 (binomial tree traversed in post-order).

Crossrefs

The sequence of lowest bits is A079559. The sequence of fixed points (i.e. a(n)=n) is A079471. The inverse permutation is A118319.
The corresponding Gray code is described in A217262.

Programs

  • Mathematica
    n=6; Reverse[ SortBy[ Range[2^n - 1], PadRight[ Flatten[ Position[ IntegerDigits[#, 2, n], 1] ], n] &]] (* Birkas Gyorgy, Jul 09 2012 *)
  • PARI
    a(n) = my(s); forstep(k=logint(n,2),0,-1, if(bittest(n,k), n++;s=k)); n-(1<Kevin Ryde, Mar 31 2020
    
  • Python
    def a(n):
        s = 0
        for k in range(n.bit_length()-1, -1, -1):
            if n & (1 << k): n += 1; s = k
        return n - (1 << s)
    print([a(n) for n in range(1, 65)]) # Michael S. Branicky, Aug 15 2022 after Kevin Ryde

Formula

a(2^(m+1)-1) = 2^m; a(2^m+k) = a(k+1) + 2^m for 0 <= k < 2^m-1. - Andrey Zabolotskiy, Oct 10 2019