login
Permutation of natural numbers induced by looking up the position of fraction A270418(n)/A270419(n) from the full Stern-Brocot tree A007305(n+1)/A047679(n-1).
5

%I #11 Mar 08 2020 08:38:56

%S 1,3,7,15,31,63,127,2,511,1023,2047,4095,8191,16383,32767,65535,

%T 131071,262143,524287,1048575,2097151,4194303,8388607,6,33554431,

%U 67108863,4,268435455,536870911,1073741823,2147483647,128,8589934591,17179869183,34359738367,68719476735,137438953471,274877906943,549755813887,14

%N Permutation of natural numbers induced by looking up the position of fraction A270418(n)/A270419(n) from the full Stern-Brocot tree A007305(n+1)/A047679(n-1).

%H Antti Karttunen, <a href="/A273672/b273672.txt">Table of n, a(n) for n = 1..1024</a>

%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>

%o (Scheme)

%o (define (A273672 n) (SBtree_index (A270418 n) (A270419 n)))

%o (define (SBtree_index m n) (let loop ((m m) (n n) (z 1)) (cond ((= m n) z) ((< m n) (loop m (- n m) (+ z z))) (else (loop (- m n) n (+ z z 1))))))

%o (PARI)

%o A065620(n, c=1) = sum(i=0, logint(n+!n, 2), if(bittest(n, i), (-1)^c++<<i)); \\ From A065620

%o SBtree_index(r) = { my(m=numerator(r),n=denominator(r),z=1); while(m!=n, if(m<n, n-=m; z<<=1, m-=n; z<<=1; z++)); (z); };

%o A273672(n) = { n=factor(n); n[, 2] = apply(A065620, n[, 2]); SBtree_index(factorback(n)); }; \\ _Antti Karttunen_, Mar 07 2020, based also on _M. F. Hasler_'s code in A270418 and A270419

%Y Inverse: A273671.

%Y Cf. A270418, A270419.

%Y Cf. also A007305, A047679.

%K nonn

%O 1,2

%A _Antti Karttunen_, May 27 2016