OFFSET
0,3
COMMENTS
LINKS
FORMULA
a(0) = 0, a(1) = 1, and for n > 1, if A065620(n) < 0, a(n) = A065621(1+a(-(A065620(n)))), otherwise a(n) = A048724(a(A065620(n)-1)).
Equally:
a(0) = 0, a(1) = 1, and for n > 1, if A010060(n) = 0, a(n) = A065621(1+a(A246159(n))), otherwise a(n) = A048724(a(A246160(n)-1)). [Note how A246159 is an inverse function for A048724, while A246160 is an inverse function for A065621].
As a composition of related permutations:
PROG
(Scheme, with memoizing-macro definec, two equivalent definitions)
(definec (A245812 n) (cond ((<= n 1) n) ((negative? (A065620 n)) (A065621 (+ 1 (A245812 (- (A065620 n)))))) (else (A048724 (A245812 (- (A065620 n) 1))))))
(definec (A245812 n) (cond ((<= n 1) n) ((zero? (A010060 n)) (A065621 (+ 1 (A245812 (A246159 n))))) (else (A048724 (A245812 (- (A246160 n) 1))))))
(PARI)
a048724(n) = bitxor(n, 2*n);
a065620(n) = if(n<3, n, if(n%2, -2*a065620((n - 1)/2) + 1, 2*a065620(n/2)));
a065621(n) = bitxor(n, 2*(n - bitand(n, -n)));
a(n) = x=a065620(n); if(n<2, n, if(x<0, a065621(1 + a(-x)), a048724(a(x - 1))));
for(n=0, 100, print1(a(n), ", ")) \\ Indranil Ghosh, Jun 07 2017
(Python)
def a048724(n): return n^(2*n)
def a065620(n): return n if n<3 else 2*a065620(n//2) if n%2==0 else -2*a065620((n - 1)//2) + 1
def a065621(n): return n^(2*(n - (n & -n)))
def a(n):
x=a065620(n)
return n if n<2 else a065621(1 + a(-x)) if x<0 else a048724(a(x - 1))
print([a(n) for n in range(101)]) # Indranil Ghosh, Jun 07 2017
CROSSREFS
KEYWORD
nonn
AUTHOR
Antti Karttunen, Aug 20 2014
STATUS
approved