OFFSET
0,5
COMMENTS
Informally: In binary representation of n, move the most significant 1-bit to the position of the most significant 0-bit ("the leftmost free hole"), and remove it altogether if there are no such holes, i.e., if n is one of the terms of A000225. When the subsets of nonnegative integers are associated with the binary expansion of n in the usual way (bit-k is 1 if number k is present in the set, and 0 stands for an empty set) then a(n) corresponds to the set obtained by "squashing" the set which corresponds to n. See Kubo & Vakil paper, page 240, 8.1 Compression revisited.
LINKS
Antti Karttunen, Table of n, a(n) for n = 0..8191
T. Kubo and R. Vakil, On Conway's recursive sequence, Discr. Math. 152 (1996), 225-252.
FORMULA
EXAMPLE
For n=13, "1101" in binary, we remove the most significant bit to get "101", where the most significant nonleading 0 is then filled with that 1, to get "111", which is 7's binary representation, thus a(13) = 7.
For n=15, "1111" in binary, we remove the most significant bit to get "111" (= 7), and as there is no most significant nonleading 0 present, the result is just that, and a(15) = 7.
For n=21, "10101" in binary, removing the most significant bit and moving it to the position of next zero results "1101", thus a(21) = 13.
PROG
(Python)
from sympy import catalan
def a063250(n):
if n<2: return 0
b=bin(n)[2:]
s=0
while b.count("0")!=0:
N=int(b[-1] + b[:-1], 2)
s+=1
b=bin(N)[2:]
return s
def a053644(n): return 0 if n==0 else 2**(len(bin(n)[2:]) - 1)
def a036987(n): return catalan(n)%2
def a(n): return n - a053644(n) if a036987(n)==1 else n - a053644(n) + 2**(a063250(n) - 1) # Indranil Ghosh, May 25 2017
(PARI) a(n) = my(s=bitnegimply(n>>1, n)); n - if(n, 1<<logint(n, 2)) + if(s, 1<<logint(s, 2)); \\ Kevin Ryde, Jun 15 2023
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Antti Karttunen, Jan 13 2016
STATUS
approved