[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
login
Search: a047679 -id:a047679
     Sort: relevance | references | number | modified | created      Format: long | short | data
Permutation of the positive integers: this permutation transforms the enumeration system of positive irreducible fractions A007305/A047679 (Stern-Brocot) into the enumeration system A162909/A162910 (Bird), and vice versa.
+20
15
1, 2, 3, 5, 4, 7, 6, 10, 11, 8, 9, 14, 15, 12, 13, 21, 20, 23, 22, 17, 16, 19, 18, 29, 28, 31, 30, 25, 24, 27, 26, 42, 43, 40, 41, 46, 47, 44, 45, 34, 35, 32, 33, 38, 39, 36, 37, 58, 59, 56, 57, 62
OFFSET
1,2
COMMENTS
As A117120 the permutation is self-inverse. Except for fixed points 1, 2, 3 it consists completely of 2-cycles: (4,5), (6,7), (8,10), (9,11), (12,14), (13,15), (16,21), (17,20), ..., (24,29), ..., (32,42), ... .
FORMULA
a(1) = 1, a(2) = 2, a(3) = 3. For n >= 2, m = floor(log_2(n)). If m even, then a(2*n) = 2*a(n) and a(2*n+1) = 2*a(n)+1. If m odd, then a(2*n) = 2*a(n)+1 and a(2*n+1) = 2*a(n).
From Yosu Yurramendi, Mar 23 2017: (Start)
A258996(a(n)) = a(A258996(n)) for n > 0;
A117120(a(n)) = a(A117120(n)) for n > 0;
A092569(a(n)) = a(A092569(n)) for n > 0;
A063946(a(n)) = a(A063946(n)) for n > 0;
A054429(a(n)) = a(A054429(n)) = A165199(n) for n > 0;
A065190(a(n)) = a(A065190(n)) for n > 0. (End)
PROG
(R)
a <- 1:3
maxn <- 50 # by choice
#
for(n in 2:maxn){
m <- floor(log2(n))
if(m%%2 == 0) {
a[2*n ] <- 2*a[n]
a[2*n+1] <- 2*a[n]+1 }
else {
a[2*n ] <- 2*a[n]+1
a[2*n+1] <- 2*a[n] }
}
#
a
# Yosu Yurramendi, Jun 09 2015
(R)
# Given n, compute a(n) by taking into account the binary representation of n
maxblock <- 7 # by choice
a <- 1:3
for(n in 4:2^maxblock){
ones <- which(as.integer(intToBits(n)) == 1)
nbit <- as.integer(intToBits(n))[1:tail(ones, n = 1)]
anbit <- nbit
ifelse(floor(log2(n)) %% 2 == 0,
anbit[seq(1, length(anbit)-1, 2)] <- 1 - anbit[seq(1, length(anbit)-1, 2)],
anbit[seq(2, length(anbit) - 1, 2)] <- 1 - anbit[seq(2, length(anbit)-1, 2)])
a <- c(a, sum(anbit*2^(0:(length(anbit)-1))))
}
a
# Yosu Yurramendi, May 29 2021
CROSSREFS
Cf. A117120.
KEYWORD
nonn
AUTHOR
Yosu Yurramendi, Jun 09 2015
STATUS
approved
Permutation of natural numbers: a(n) = A270436(A007305(n+1)) * A270437(A047679(n-1)).
+20
8
1, 8, 2, 27, 54, 24, 3, 64, 250, 375, 192, 108, 135, 40, 4, 125, 686, 96, 1029, 1372, 160, 1715, 500, 320, 875, 16000, 448, 189, 3456, 56, 5, 216, 1458, 3993, 3000, 5324, 10985, 8640, 2916, 3645, 12096, 281216, 9317, 7000, 170368, 5103, 1080, 750, 3087, 352, 3430, 3773, 416, 4116, 1125, 576, 1500, 1625, 704, 270, 297, 72, 6, 343
OFFSET
1,2
COMMENTS
Permutation of natural numbers induced by looking up the position of A007305(n+1)/A047679(n-1) [each fraction in the full Stern-Brocot tree] in the set of positive rationals as ordered by A270418(n)/A270419(n).
FORMULA
a(n) = A270436(A007305(n+1)) * A270437(A047679(n-1)).
PROG
(Scheme) (define (A273671 n) (* (A270436 (A007305 (+ 1 n))) (A270437 (A047679 (- n 1)))))
CROSSREFS
KEYWORD
nonn,look
AUTHOR
Antti Karttunen, May 27 2016
STATUS
approved
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).
+20
5
1, 3, 7, 15, 31, 63, 127, 2, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 6, 33554431, 67108863, 4, 268435455, 536870911, 1073741823, 2147483647, 128, 8589934591, 17179869183, 34359738367, 68719476735, 137438953471, 274877906943, 549755813887, 14
OFFSET
1,2
PROG
(Scheme)
(define (A273672 n) (SBtree_index (A270418 n) (A270419 n)))
(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))))))
(PARI)
A065620(n, c=1) = sum(i=0, logint(n+!n, 2), if(bittest(n, i), (-1)^c++<<i)); \\ From A065620
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); };
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
CROSSREFS
Inverse: A273671.
Cf. also A007305, A047679.
KEYWORD
nonn
AUTHOR
Antti Karttunen, May 27 2016
STATUS
approved
a(n) is the integer (reduced squarefree) under the square root obtained when the inverse of Minkowski's question mark function is applied to the n-th ratio A007305(n+1)/A047679(n-1) in the full Stern-Brocot tree and zero when it results a rational value.
+20
4
0, 0, 0, 5, 5, 0, 0, 0, 2, 2, 0, 5, 5, 0, 0, 2, 3, 0, 3, 3, 0, 3, 2, 0, 2, 2, 0, 5, 5, 0, 0, 5, 13, 17, 2, 17, 37, 5, 13, 13, 5, 37, 17, 2, 17, 13, 5, 2, 3, 0, 3, 3, 0, 3, 2, 0, 2, 2, 0, 5, 5, 0, 0, 3, 17, 3, 37, 21, 13, 10, 37, 3, 401, 6, 13, 10, 401, 0, 17, 17, 0, 401, 10, 13, 6, 401, 3, 37
OFFSET
1,4
COMMENTS
Note: the underlying function N2Q (see the Maple code) maps natural numbers 1, 2, 3, 4, 5, ..., through all the positive rationals 1/1, 1/2, 2/1, 1/3, 2/3, 3/2, 3/1, 1/4, ... bijectively to the union of positive rationals and quadratic surds.
In his "On Numbers and Games", Conway denotes Minkowski's question mark function with x enclosed in a box.
REFERENCES
J. H. Conway, On Numbers and Games, 2nd ed. Natick, MA: A. K. Peters, pp. 82-86 (First ed.), 2000.
EXAMPLE
The first few values for this mapping are
N2Q(1) = Inverse_of_MinkowskisQMark(1) = 1,
N2Q(2) = Inverse_of_MinkowskisQMark(1/2) = 1/2,
N2Q(3) = Inverse_of_MinkowskisQMark(2) = 2,
N2Q(4) = Inverse_of_MinkowskisQMark(1/3) = (3-sqrt(5))/2,
N2Q(5) = Inverse_of_MinkowskisQMark(2/3) = (sqrt(5)-1)/2,
N2Q(6) = Inverse_of_MinkowskisQMark(3/2) = 3/2,
N2Q(7) = Inverse_of_MinkowskisQMark(3) = 3,
N2Q(8) = Inverse_of_MinkowskisQMark(1/4) = 1/3,
N2Q(9) = Inverse_of_MinkowskisQMark(2/5) = sqrt(2)-1,
N2Q(10) = Inverse_of_MinkowskisQMark(3/5) = 2-sqrt(2).
MAPLE
[seq(find_sqrt(N2Q(j)), j=1..512)];
N2Q := n -> Inverse_of_MinkowskisQMark(A007305(m+1)/A047679(m-1));
Inverse_of_MinkowskisQMark := proc(r) local x, y, b, d, k, s, i, q; x := numer(r); y := denom(r); if(1 = y) then RETURN(x/y); fi; if(2 = y) then RETURN(x/y); fi; b := []; d := []; k := 0; s := 0; i := 0; while(x <> 0) do q := floor(x/y); if(i > 0) then b := [op(b), q]; d := [op(d), x]; fi; x := 2*(x-(q*y)); if(member(x, d, 'k') and (k > 1) and (b[k] <> b[k-1]) and (q <> floor(x/y))) then s := eval_periodic_confrac_tail(list2runcounts(b[k..nops(b)])); b := b[1..(k-1)]; break; fi; i := i+1; od; if(0 = k) then b := b[1..(nops(b)-1)]; b := [op(b), b[nops(b)]]; fi; RETURN(factor(eval_confrac([floor(r), op(list2runcounts([0, op(b)]))], s))); end;
eval_confrac := proc(c, z) local x, i; x := z; for i in reverse(c) do x := (`if`((0=x), x, (1/x)))+i; od; RETURN(x); end;
eval_periodic_confrac_tail := proc(c) local x, i, u, r; x := (eval_confrac(c, u) - u) = 0; r := [solve(x, u)]; RETURN(max(r[1], r[2])); end; # Note: I am not sure if the larger root is always the correct one for the inverse of Minkowski's question mark function. However, whichever root we take, it does not change this sequence, as the integer under the square root is same in both cases. - Antti Karttunen, Aug 26 2006
list2runcounts := proc(b) local a, p, y, c; if(0 = nops(b)) then RETURN([]); fi; a := []; c := 0; p := b[1]; for y in b do if(y <> p) then a := [op(a), c]; c := 0; p := y; fi; c := c+1; od; RETURN([op(a), c]); end;
find_sqrt := proc(x) local n, i, y; n := nops(x); if(n < 2) then RETURN(0); fi; if((2 = n) and (`^` = op(0, x)) and (1/2 = op(2, x))) then RETURN(op(1, x)); else for i from 0 to n do y := find_sqrt(op(i, x)); if(y <> 0) then RETURN(y); fi; od; RETURN(0); fi; end; # This returns an integer under the square-root expression in Maple.
CROSSREFS
a(n) = A065936(A065935(n)). Positions of sqrt(n) in this mapping: A065939.
KEYWORD
nonn
AUTHOR
Antti Karttunen, Dec 07 2001
EXTENSIONS
Description clarified by Antti Karttunen, Aug 26 2006
STATUS
approved
Left(0)/right(1) turning sequence needed to traverse the Stern-Brocot tree (A007305, A047679) from the root down to e (A001113).
+20
4
1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
OFFSET
1
COMMENTS
The sequence has the following regular pattern: 1 0{0} 1 0 1{2} 0 1 0{4} 1 0 1{6} 0 1 0{8} ... where {r} indicates that the preceding term is repeated r times.
Run lengths of this sequence (A003417) are the coefficients of the continued fraction for e.
The positions of zeros and ones are given by A358510 and A358511, respectively. - Paolo Xausa, Nov 20 2022
REFERENCES
R. L. Graham, D. E. Knuth and O. Patashnik, Concrete Mathematics, 2nd Edition, Addison-Wesley, 1989, p. 115-123.
LINKS
Michael De Vlieger, 2^11 X 2^11 bitmap of a(n), n = 1..2^22, where white represents 0 and black represents 1.
Michael De Vlieger, Binary tree of a(n), n = 1..2^14-1, where dark blue represents 0 and red represents 1.
FORMULA
The sequence begins with
floor(e / 1) = A003417(1) ones, followed by
floor(1 / (e mod 1)) = A003417(2) zeros, followed by
floor((e mod 1) / (1 mod (e mod 1))) = A003417(3) ones, followed by
floor((1 mod (e mod 1)) / ((e mod 1) mod (1 mod (e mod 1)))) = A003417(4) zeros
...
From Paolo Xausa, Nov 20 2022: (Start)
a(A358510(n)) = 0.
a(A358511(n)) = 1.
Limit_{n->oo} (1/n)*Sum_{i=1..n} a(i) = 1/2. (End)
EXAMPLE
In the initial portion of the Stern-Brocot tree shown below, the arrows indicate the traversing route.
1/1
|
.----------------->-----. Right (1)
| |
1/2 2/1
| |
.-----------. .-------->--. Right (1)
| | | |
1/3 2/3 3/2 3/1
| | | |
.-----. .-----. .-----. .-<---. Left (0)
| | | | | | | |
1/4 2/5 3/5 3/4 4/3 5/3 5/2 4/1
...
The first terms of the sequence are therefore 1, 1, 0.
MATHEMATICA
(* Generate up to 2^22 terms of this sequence from the 2^11 X 2^11 bitmap *)
With[{rows = 12}, ImageData[Import["https://oeis.org/A342991/a342991.png"]][[1 ;; rows]] /. {0. -> 1, 1. -> 0} // Flatten] (* Michael De Vlieger, Nov 04 2022 *)
A342991[i_]:=Flatten[Array[{1, PadRight[{}, 4#], 1, 0, PadRight[{}, 2+4#, 1], 0}&, i, 0]]; (* Each iteration adds six runs of values *)
A342991[10] (* Paolo Xausa, Nov 20 2022 *)
PROG
(Python)
from itertools import count, islice
def A342991_gen(): # generator of terms
a = 0
yield from (1, 1)
for n in count(2):
q, r = divmod(n, 3)
yield from (a, )*(1 if r else q<<1)
a = 1-a
A342991_list = list(islice(A342991_gen(), 40)) # Chai Wah Wu, Nov 04 2022
(PARI)
A342991(iter) = concat(vector(iter, i, concat([1, vector((i-1)<<2), 1, 0, vector(2+(i-1)<<2, x, 1), 0]))); \\ Each iteration adds six runs of values
A342991(10) \\ Paolo Xausa, Nov 24 2022
(PARI) a(n) = my(r, s=sqrtint(n-1, &r)); bitand(s + (r<s-1 || r==s), 1); \\ Kevin Ryde, Nov 24 2022
KEYWORD
nonn,easy
AUTHOR
Paolo Xausa, Jul 21 2021
STATUS
approved
Obtained by reading first the numerator then the denominator of fractions in full Stern-Brocot tree (A007305/A047679).
+20
3
0, 1, 1, 0, 1, 1, 1, 2, 2, 1, 1, 3, 2, 3, 3, 2, 3, 1, 1, 4, 2, 5, 3, 5, 3, 4, 4, 3, 5, 3, 5, 2, 4, 1, 1, 5, 2, 7, 3, 8, 3, 7, 4, 7, 5, 8, 5, 7, 4, 5, 5, 4, 7, 5, 8, 5, 7, 4, 7, 3, 8, 3, 7, 2, 5, 1, 1, 6, 2, 9, 3, 11, 3, 10, 4, 11, 5, 13, 5, 12, 4, 9, 5, 9, 7, 12, 8, 13, 7, 11, 7, 10, 8, 11, 7, 9, 5, 6, 6, 5
OFFSET
0,8
COMMENTS
When presented in this way, every row (e.g. row 3, 1 3 2 3 3 2 3 1) is a palindrome. - Joshua Zucker, May 11 2006
MAPLE
F:= proc(n) option remember; local t;
t:= L -> [[L[1], [L[1][1]+L[2][1], L[1][2]+L[2][2]], L[2]],
[L[2], [L[2][1]+L[3][1], L[2][2]+L[3][2]], L[3]]][];
if n=0 then [[[ ], [0, 1], [ ]], [[ ], [1, 0], [ ]]]
elif n=1 then [[[0, 1], [1, 1], [1, 0]]]
else map(t, F(n-1))
fi
end:
aa:= n-> map(x-> x[], [seq(map(x-> x[2], F(j))[], j=0..n)])[]:
aa(7); # aa(n) gives the first 2^(n+1)+2 terms
# Alois P. Heinz, Jan 13 2011
MATHEMATICA
sbt[n_] := Module[{R, L, Y, w, u},
R = {{1, 0}, {1, 1}};
L = {{1, 1}, {0, 1}};
Y = {{1, 0}, {0, 1}};
w[b_] := Fold[#1.If[#2 == 0, L, R]&, Y, b];
u[a_] := {a[[2, 1]] + a[[2, 2]], a[[1, 1]] + a[[1, 2]]};
Map[u, Map[w, Tuples[{0, 1}, n]]]];
Join[{0, 1, 1, 0}, Table[sbt[n], {n, 0, 5}]] // Flatten (* Jean-François Alcover, Sep 06 2022, after Peter Luschny in A007305 *)
CROSSREFS
KEYWORD
nonn,look,easy
AUTHOR
N. J. A. Sloane, Sep 08 2000
EXTENSIONS
More terms from Joshua Zucker, May 11 2006
STATUS
approved
The exponent of 2 in the fractions of the whole ]0, inf[ Stern-Brocot tree (A007305/A047679) [1/1, 1/2, 2/1, 1/3, 2/3, 3/2, 3/1, 1/4, 2/5, 3/5, 3/4, 4/3, 5/3, 5/2, 4/1, ...].
+20
3
0, -1, 1, 0, 1, -1, 0, -2, 1, 0, -2, 2, 0, -1, 2, 0, 1, -3, 0, 2, -3, 0, 2, -2, 0, 3, -2, 0, 3, -1, 0, -1, 1, 0, -1, 2, 0, -2, 2, 0, -2, 3, 0, -1, 3, 0, -1, 1, 0, -3, 1, 0, -3, 2, 0, -2, 2, 0, -2, 1, 0, -1, 1, 0, 1, -1, 0, 2, -1, 0, 2, -1, 0, 3, -1, 0, 3, -4, 0, 1, -4, 0, 1, -1, 0, 2, -1, 0, 2, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -2, 0, 1, -2, 0, 1, -1
OFFSET
1,8
MAPLE
[seq(exp_of_2(SternBrocotTreeNum(j)/SternBrocotTreeDen(j)), j=1..128)];
CROSSREFS
KEYWORD
sign
AUTHOR
Antti Karttunen, Nov 22 2001
STATUS
approved
Simple self-inverse permutation of natural numbers: List each block of 2^n numbers (from 2^n to 2^(n+1) - 1) in reverse order.
+10
213
1, 3, 2, 7, 6, 5, 4, 15, 14, 13, 12, 11, 10, 9, 8, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 127, 126, 125, 124, 123, 122, 121
OFFSET
1,2
COMMENTS
a(n) gives the position of the inverse of the n-th term in the full Stern-Brocot tree: A007305(a(n)+2) = A047679(n) and A047679(a(n)) = A007305(n+2). - Reinhard Zumkeller, Dec 22 2008
From Gary W. Adamson, Jun 21 2012: (Start)
The mapping and conversion rules are as follows:
By rows, we have ...
1;
3, 2;
7, 6, 5, 4;
15, 14, 13, 12, 11, 10, 9, 8;
... onto which we are to map one-half of the Stern-Brocot infinite Farey Tree:
1/2
1/3, 2/3
1/4, 2/5, 3/5, 3/4
1/5, 2/7, 3/8, 3/7, 4/7, 5/8, 5/7, 4/5
...
The conversion rules are: Convert the decimal to binary, adding a duplicate of the rightmost binary term to its right. For example, 10 = 1010, which becomes 10100. Then, from the left, record the number of runs = [1,1,1,2], the continued fraction representation of 5/8. Check: 10 decimal corresponds to 5/8 as shown in the overlaid mapping. Take decimal 9 = 1001 which becomes 10011, with a continued fraction representation of [1,2,2] = 5/7. Check: 9 decimal corresponds to 5/7 in the Farey Tree map. (End)
From Indranil Ghosh, Jan 19 2017: (Start)
a(n) is the value generated when n is converted into its Elias gamma code, the 1's and 0's are interchanged and the resultant is converted back to its decimal value for all values of n > 1. For n = 1, A054429(n) = 1 but after converting 1 to Elias gamma code, interchanging the 1's and 0's and converting it back to decimal, the result produced is 0.
For example, let n = 10. The Elias gamma code for 10 is '1110010'. After interchanging the 1's and 0's it becomes "0001101" and 1101_2 = 13_10. So a(10) = 13. (End)
From Yosu Yurramendi, Mar 09 2017 (similar to Zumkeller's comment): (Start)
A002487(a(n)) = A002487(n+1), A002487(a(n)+1) = A002487(n), n > 0.
A162909(a(n)) = A162910(n), A162910(a(n)) = A162909(n), n > 0.
A162911(a(n)) = A162912(n), A162912(a(n)) = A162911(n), n > 0.
A071766(a(n)) = A245326(n), A245326(a(n)) = A071766(n), n > 0.
A229742(a(n)) = A245325(n), A245325(a(n)) = A229742(n), n > 0.
A020651(a(n)) = A245327(n), A245327(a(n)) = A020651(n), n > 0.
A020650(a(n)) = A245328(n), A245328(a(n)) = A020650(n), n > 0. (End)
From Yosu Yurramendi, Mar 29 2017: (Start)
A063946(a(n)) = a(A063946(n)) = A117120(n), n > 0.
A065190(a(n)) = a(A065190(n)) = A092569(n), n > 0.
A258746(a(n)) = a(A258746(n)) = A165199(n), n > 0.
A258996(a(n)) = a(A258996(n)), n > 0.
A117120(a(n)) = a(A117120(n)), n > 0.
A092569(a(n)) = a(A092569(n)), n > 0. (End)
FORMULA
a(n) = ReflectBinTreePermutation(n).
a(n) = if n=1 then 1 else 2*a(floor(n/2)) + 1 - n mod 2. - Reinhard Zumkeller, Feb 18 2003
G.f.: 1/(1-x) * ((x-2x^2)/(1-x) + Sum_{k>=0} 3*2^k*x^2^k). - Ralf Stephan, Sep 15 2003
A000120(a(n)) = A000120(A059894(n)) = A023416(n) + 1. - Ralf Stephan, Oct 05 2003
A115310(n, 1) = a(n). - Reinhard Zumkeller, Jan 20 2006
a(1) = 1, a(2^(m+1) + k) = a(2^m+k) + 2^(m+1),
a(2^(m+1) + 2^m+k) = a(2^m+k) + 2^m, m >= 0, 0 <= k < 2^m. - Yosu Yurramendi, Apr 06 2017
a(n) = A117120(A063946(n)) = A063946(A117120(n)) = A092569(A065190(n)) = A065190(A092569(n)), n > 0. - Yosu Yurramendi, Apr 10 2017
MAPLE
A054429 := n -> 3*2^ilog2(n) - n - 1:
seq(A054429(n), n = 1..70); # [Updated by Peter Luschny, Apr 24 2024]
MATHEMATICA
Flatten[Table[Range[2^(n+1)-1, 2^n, -1], {n, 0, 6}]] (* Harvey P. Dale, Dec 17 2013 *)
PROG
(Haskell)
a054429 n = a054429_list !! (n-1)
a054429_list = f [1..] where
f xs@(x:_) = reverse us ++ f vs where (us, vs) = splitAt x xs
-- Reinhard Zumkeller, Jun 01 2015, Feb 21 2014
(PARI) A054429(n)= 3<<#binary(n\2)-n-1 \\ M. F. Hasler, Aug 18 2014
(R)
maxblock <- 10 # by choice
a <- NULL
for(m in 0:maxblock) a <- c(a, rev(2^m:(2^(m+1)-1)))
a
# Yosu Yurramendi, Mar 10 2017
(Python)
from itertools import count, islice
def A054429_gen(): # generator of terms
return (m for n in count(0) for m in range((1<<n+1)-1, (1<<n)-1, -1))
A054429_list = list(islice(A054429_gen(), 30)) # Chai Wah Wu, Jul 27 2023
CROSSREFS
See also A054424, A054430.
{A000027, A054429, A059893, A059894} form a 4-group.
This is Guy Steele's sequence GS(6, 5) (see A135416).
KEYWORD
nonn,easy,look
STATUS
approved
Reverse the order of all but the most significant bit in binary expansion of n: if n = 1ab..yz then a(n) = 1zy..ba.
+10
114
1, 2, 3, 4, 6, 5, 7, 8, 12, 10, 14, 9, 13, 11, 15, 16, 24, 20, 28, 18, 26, 22, 30, 17, 25, 21, 29, 19, 27, 23, 31, 32, 48, 40, 56, 36, 52, 44, 60, 34, 50, 42, 58, 38, 54, 46, 62, 33, 49, 41, 57, 37, 53, 45, 61, 35, 51, 43, 59, 39, 55, 47, 63, 64, 96, 80, 112, 72, 104, 88, 120
OFFSET
1,2
COMMENTS
A self-inverse permutation of the natural numbers.
a(n)=n if and only if A081242(n) is a palindrome. - Clark Kimberling, Mar 12 2003
a(n) is the position in B of the reversal of the n-th term of B, where B is the left-to-right binary enumeration sequence (A081242 with the empty word attached as first term). - Clark Kimberling, Mar 12 2003
From Antti Karttunen, Oct 28 2001: (Start)
When certain Stern-Brocot tree-related permutations are conjugated with this permutation, they induce a permutation on Z (folded to N), which is an infinite siteswap permutation (see, e.g., figure 7 in the Buhler and Graham paper, which is permutation A065174). We get:
A065260(n) = a(A057115(a(n))),
A065266(n) = a(A065264(a(n))),
A065272(n) = a(A065270(a(n))),
A065278(n) = a(A065276(a(n))),
A065284(n) = a(A065282(a(n))),
A065290(n) = a(A065288(a(n))). (End)
Every nonnegative integer has a unique representation c(1) + c(2)*2 + c(3)*2^2 + c(4)*2^3 + ..., where every c(i) is 0 or 1. Taking tuples of coefficients in lexical order (i.e., 0, 1; 01,11; 001,011,101,111; ...) yields A059893. - Clark Kimberling, Mar 15 2015
From Ed Pegg Jr, Sep 09 2015: (Start)
The reduced rationals can be ordered either as the Calkin-Wilf tree A002487(n)/A002487(n+1) or the Stern-Brocot tree A007305(n+2)/A047679(n). The present sequence gives the order of matching rationals in the other sequence.
For reference, the Calkin-Wilf tree is 1, 1/2, 2, 1/3, 3/2, 2/3, 3, 1/4, 4/3, 3/5, 5/2, 2/5, 5/3, 3/4, 4, 1/5, 5/4, 4/7, 7/3, 3/8, 8/5, 5/7, 7/2, 2/7, 7/5, 5/8, 8/3, 3/7, 7/4, 4/5, ..., which is A002487(n)/A002487(n+1).
The Stern-Brocot tree is 1, 1/2, 2, 1/3, 2/3, 3/2, 3, 1/4, 2/5, 3/5, 3/4, 4/3, 5/3, 5/2, 4, 1/5, 2/7, 3/8, 3/7, 4/7, 5/8, 5/7, 4/5, 5/4, 7/5, 8/5, 7/4, 7/3, 8/3, 7/2, ..., which is A007305(n+2)/A047679(n).
There is a great little OEIS-is-useful story here. I had code for the position of fractions in the Calkin-Wilf tree. The best I had for positions of fractions in the Stern-Brocot tree was the paper "Locating terms in the Stern-Brocot tree" by Bruce Bates, Martin Bunder, Keith Tognetti. The method was opaque to me, so I used my Calkin-Wilf code on the Stern-Brocot fractions, and got A059893. And thus the problem was solved. (End)
LINKS
Alois P. Heinz, Table of n, a(n) for n = 1..8191 (first 1023 terms from T. D. Noe)
Bruce Bates, Martin Bunder, and Keith Tognetti, Locating terms in the Stern-Brocot tree, European Journal of Combinatorics 31.3 (2010): 1020-1033.
Joe Buhler and R. L. Graham, Juggling Drops and Descents, Amer. Math. Monthly, 101, (no. 6) 1994, 507-519.
Dana G. Korssjoen, Biyao Li, Stefan Steinerberger, Raghavendra Tripathi, and Ruimin Zhang, Finding structure in sequences of real numbers via graph theory: a problem list, arXiv:2012.04625, 2020-2021.
Wikipedia, Calkin-Wilf Tree.
Wikipedia, Stern-Brocot tree.
FORMULA
a(n) = A030109(n) + A053644(n). If 2*2^k <= n < 3*2^k then a(n) = 2*a(n-2^k); if 3*2^k <= n < 4*2^k then a(n) = 1 + a(n-2^k) starting with a(1)=1. - Henry Bottomley, Sep 13 2001
EXAMPLE
a(11) = a(1011) = 1110 = 14.
With empty word e prefixed, A081242 becomes (e,1,2,11,21,12,22,111,211,121,221,112,...); (reversal of term #9) = (term #12); i.e., a(9)=12 and a(12)=9. - Clark Kimberling, Mar 12 2003
From Philippe Deléham, Jun 02 2015: (Start)
This sequence regarded as a triangle with rows of lengths 1, 2, 4, 8, 16, ...:
1;
2, 3;
4, 6, 5, 7;
8, 12, 10, 14, 9, 13, 11, 15;
16, 24, 20, 28, 18, 26, 22, 30, 17, 25, 21, 29, 19, 27, 23, 31;
32, 48, 40, 56, 36, 52, 44, ...
Row sums = A010036. (End)
MAPLE
# Implements Bottomley's formula
A059893 := proc(n) option remember; local k; if(1 = n) then RETURN(1); fi; k := floor_log_2(n)-1; if(2 = floor(n/(2^k))) then RETURN(2*A059893(n-(2^k))); else RETURN(1+A059893(n-(2^k))); fi; end;
floor_log_2 := proc(n) local nn, i; nn := n; for i from -1 to n do if(0 = nn) then RETURN(i); fi; nn := floor(nn/2); od; end;
# second Maple program:
a:= proc(n) local i, m, r; m, r:= n, 0;
for i from 0 while m>1 do r:= 2*r +irem(m, 2, 'm') od;
r +2^i
end:
seq(a(n), n=1..100); # Alois P. Heinz, Feb 28 2015
MATHEMATICA
A059893 = Reap[ For[n=1, n <= 100, n++, a=1; b=n; While[b > 1, a = 2*a + 2*FractionalPart[b/2]; b=Floor[b/2]]; Sow[a]]][[2, 1]] (* Jean-François Alcover, Jul 16 2012, after Harry J. Smith *)
ro[n_]:=Module[{idn=IntegerDigits[n, 2]}, FromDigits[Join[{First[idn]}, Reverse[ Rest[idn]]], 2]]; Array[ro, 80] (* Harvey P. Dale, Oct 24 2012 *)
PROG
(PARI) a(n) = my(b=binary(n)); fromdigits(concat(b[1], Vecrev(vector(#b-1, k, b[k+1]))), 2); \\ Michel Marcus, Sep 29 2021
(Haskell)
a059893 = foldl (\v b -> v * 2 + b) 1 . init . a030308_row
-- Reinhard Zumkeller, May 01 2013
(Scheme, with memoization-macro definec)
(definec (A059893 n) (if (<= n 1) n (let* ((k (- (A000523 n) 1)) (r (A059893 (- n (A000079 k))))) (if (= 2 (floor->exact (/ n (A000079 k)))) (* 2 r) (+ 1 r)))))
;; Antti Karttunen, May 16 2015
(R)
maxrow <- 6 # by choice
a <- 1
for(m in 0:maxrow) for(k in 0:(2^m-1)) {
a[2^(m+1)+ k] <- 2*a[2^m+k]
a[2^(m+1)+2^m+k] <- 2*a[2^m+k] + 1
}
a
# Yosu Yurramendi, Mar 20 2017
(R)
maxblock <- 7 # by choice
a <- 1
for(n in 2:2^maxblock){
ones <- which(as.integer(intToBits(n)) == 1)
nbit <- as.integer(intToBits(n))[1:tail(ones, n = 1)]
anbit <- nbit
anbit[1:(length(anbit) - 1)] <- anbit[rev(1:(length(anbit)-1))]
a <- c(a, sum(anbit*2^(0:(length(anbit) - 1))))
}
a
# Yosu Yurramendi, Apr 25 2021
(Python)
def a(n): return int('1' + bin(n)[3:][::-1], 2)
print([a(n) for n in range(1, 101)]) # Indranil Ghosh, Mar 21 2017
CROSSREFS
{A000027, A054429, A059893, A059894} form a 4-group.
The set of permutations {A059893, A080541, A080542} generates an infinite dihedral group.
In other bases: A351702 (balanced ternary), A343150 (Zeckendorf), A343152 (lazy Fibonacci).
KEYWORD
easy,nonn,base,nice,look
AUTHOR
Marc LeBrun, Feb 06 2001
STATUS
approved
Denominators of Farey tree fractions (i.e., the Stern-Brocot subtree in the range [0,1]).
(Formerly M0437)
+10
95
1, 1, 2, 3, 3, 4, 5, 5, 4, 5, 7, 8, 7, 7, 8, 7, 5, 6, 9, 11, 10, 11, 13, 12, 9, 9, 12, 13, 11, 10, 11, 9, 6, 7, 11, 14, 13, 15, 18, 17, 13, 14, 19, 21, 18, 17, 19, 16, 11, 11, 16, 19, 17, 18, 21, 19, 14, 13, 17, 18, 15, 13, 14, 11, 7, 8, 13, 17, 16, 19, 23, 22, 17, 19, 26, 29, 25, 24
OFFSET
0,3
COMMENTS
Also number of odd entries in n-th row of triangle of Stirling numbers of the second kind (A008277). - Benoit Cloitre, Feb 28 2004
Apparently (except for the first term) the number of odd entries in the alternated diagonals of Pascal's triangle at 45 degrees slope. - Javier Torres (adaycalledzero(AT)hotmail.com), Jul 26 2009
The Kn3 and Kn4 triangle sums, see A180662 for their definitions, of Sierpiński's triangle A047999 equal a(n+1). - Johannes W. Meijer, Jun 05 2011
From Yosu Yurramendi, Jun 23 2014: (Start)
If the terms (n>1) are written as an array:
2,
3, 3,
4, 5, 5, 4,
5, 7, 8, 7, 7, 8, 7, 5,
6, 9, 11, 10, 11, 13, 12, 9, 9, 12, 13, 11, 10, 11, 9, 6,
7, 11, 14, 13, 15, 18, 17, 13, 14, 19, 21, 18, 17, 19, 16, 11, 11, 16, 19,17,18,
then the sum of the k-th row is 2*3^(k-2), each column is an arithmetic progression. The differences of the arithmetic progressions give the sequence itself (a(2^(m+1)+1+k) - a(2^m+1+k) = a(k+1), m >= 1, 1 <= k <= 2^m), because a(n) = A002487(2*n-1) and A002487 has these properties. A071585 also has these properties. Each row is a palindrome: a(2^(m+1)+1-k) = a(2^m+k), m >= 0, 1 <= k <= 2^m.
If the terms (n>0) are written in this way:
1,
2, 3,
3, 4, 5, 5,
4, 5, 7, 8, 7, 7, 8, 7,
5, 6, 9, 11, 10, 11, 13, 12, 9, 9, 12, 13, 11, 10, 11, 9,
6, 7, 11, 14, 13, 15, 18, 17, 13, 14, 19, 21, 18, 17, 19, 16, 11, 11, 16, 19,
each column is an arithmetic progression and the steps also give the sequence itself (a(2^(m+1)+k) - a(2^m+k) = a(k), m >= 0, 0 <= k < 2^m). Moreover, by removing the first term of each column:
a(2^(m+1)+k) = A049448(2^m+k+1), m >= 0, 0 <= k < 2^m.
(End)
k > 1 occurs in this sequence phi(k) = A000010(k) times. - Franklin T. Adams-Watters, May 25 2015
Except for the initial 1, this is the odd bisection of A002487. The even bisection of A002487 is A002487 itself. - Franklin T. Adams-Watters, May 25 2015
For all m >= 0, max_{k=1..2^m} a(2^m+k) = A000045(m+3) (Fibonacci sequence). - Yosu Yurramendi, Jun 05 2016
For all n >= 2, max(m: a(2^m+k) = n, 1<=k<=2^m) = n-2. - Yosu Yurramendi, Jun 05 2016
a(2^m+1) = m+2, m >= 0; a(2^m+2) = 2m+1, m>=1; min_{m>=0, k=1..2^m} a(2^m+k) = m+2; min_{m>=2, k=2..2^m-1} a(2^m+k) = 2m+1. - Yosu Yurramendi, Jun 06 2016
a(2^(m+2) + 2^(m+1) - k) - a(2^(m+1) + 2^m-k) = 2*a(k+1), m >= 0, 0 <= k <= 2^m. - Yosu Yurramendi, Jun 09 2016
If the initial 1 is omitted, this is the number of nonzero entries in row n of the generalized Pascal triangle P_2, see A282714 [Leroy et al., 2017]. - N. J. A. Sloane, Mar 02 2017
Apparently, this sequence was introduced by Johann Gustav Hermes in 1894. His paper gives a strong connection between this sequence and the so-called "Gaussian brackets" ("Gauss'schen Klammer"). For an independent discussion about Gaussian brackets, see the relevant MathWorld article and the article by Herzberger (1943). Srinivasan (1958) gave another, more modern, explanation of the connection between this sequence and the Gaussian brackets. (Parenthetically, J. G. Hermes is the mathematician who completed or constructed the regular polygon with 65537 sides.) - Petros Hadjicostas, Sep 18 2019
REFERENCES
P. Bachmann, Niedere Zahlentheorie (1902, 1910), reprinted Chelsea, NY, 1968, vol. 2, p. 61.
L. E. Dickson, History of the Theory of Numbers. Carnegie Institute Public. 256, Washington, DC, Vol. 1, 1919; Vol. 2, 1920; Vol. 3, 1923, see vol. 1, p. 158.
J. C. Lagarias, Number Theory and Dynamical Systems, pp. 35-72 of S. A. Burr, ed., The Unreasonable Effectiveness of Number Theory, Proc. Sympos. Appl. Math., 46 (1992). Amer. Math. Soc.
N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).
LINKS
Suayb S. Arslan, Asymptotically MDS Array BP-XOR Codes, arXiv:1709.07949 [cs.IT], 2017.
Alexander Bogomolny, Stern-Brocot tree.
M. Herzberger, Gaussian optics and Gaussian brackets, Journal of the Optical Society of America 33(12) (1943), 651-655. [This paper gives a clear description of Gaussian brackets that are related to this sequence as explained by Hermes (1894).]
Jennifer Lansing, On the Stern sequence and a related sequence, Ph.D. dissertation in Mathematics, University of Illinois at Urbana-Champaign, 2014. [This doctoral dissertation discusses the so-called Stern sequence on which Hermes' papers are based (according to Srinivasan (1958)).]
Julien Leroy, Michel Rigo, and Manon Stipulanti, Counting the number of non-zero coefficients in rows of generalized Pascal triangles, Discrete Mathematics 340 (2017), 862-881.
Julien Leroy, Michel Rigo, and Manon Stipulanti, Counting subword occurrences in base-b expansions, Integers (2018) 18A, Article #A13.
G. Melançon, Lyndon factorization of sturmian words, Discr. Math. 210 (2000), 137-149.
N. J. A. Sloane, Stern-Brocot or Farey Tree.
M. S. Srinivasan, The enumeration of positive rational numbers, Proc. Indian Acad. Sci. Sect. A 47 (1958), 12-24.
M. Stern, Über eine zahlentheoretische Function, Journal für die reine und angewandte Mathematik 55 (1858), 193-220. [According to Srinivasan (1958), Hermes's (1894) paper, where this sequence is introduced, is based on Stern's sequence.]
Manon Stipulanti, Convergence of Pascal-Like Triangles in Parry-Bertrand Numeration Systems, arXiv:1801.03287 [math.CO], 2018.
Javier Torres Suarez, Number theory - geometric connection (part 2) (YouTube video that mentions this sequence - link sent by Pacha Nambi, Aug 26 2009).
Eric Weisstein's World of Mathematics, Gaussian brackets; they are related to this sequence.
Wikipedia, Johann Gustav Hermes. [He is the person who introduced this sequence and the person who completed or constructed a regular polygon with 65537 sides.]
FORMULA
Recurrence: a(0) to a(8) are 1, 1, 2, 3, 3, 4, 5, 5, 4; thereafter a(n) = a(n-2^p) + a(2^(p+1)-n+1), where 2^p < n <= 2^(p+1). [J. Hermes, Math. Ann., 1894; quoted by Dickson, Vol. 1, p. 158] - N. J. A. Sloane, Mar 24 2019
a(4*n) = -a(n)+2*a(2*n); a(4*n+1) = -a(n)+a(2*n)+a(2*n+1); a(4*n+2)=a(n)-a(2*n)+2*a(2*n+1); a(4*n+3) = 4*a(n)-4*a(2*n)+3*a(2*n+1). Thus a(n) is a 2-regular sequence. - Jeffrey Shallit, Dec 26 2024
For n > 0, a(n) = A002487(n-1) + A002487(n) = A002487(2*n-1).
a(0) = 1; a(n) = Sum_{k=0..n-1} C(n-1+k, n-1-k) mod 2, n > 0. - Benoit Cloitre, Jun 20 2003
a(n+1) = Sum_{k=0..n} binomial(2*n-k, k) mod 2; a(n) = 0^n + Sum_{k=0..n-1} binomial(2(n-1)-k, k) mod 2. - Paul Barry, Dec 11 2004
a(n) = Sum_{k=0..n} C(n+k,2*k) mod 2. - Paul Barry, Jun 12 2006
a(0) = a(1) = 1; a(n) = a(A003602(n-1)) + a(A003602(n)), n > 1. - Alessandro De Luca, May 08 2014
a(n) = A007305(n+(2^m-1)), m=A029837(n), n=1,2,3,... . - Yosu Yurramendi, Jul 04 2014
a(n) = A007305(2^(m+1)-n) - A007305(2^m-n), m >= (A029837(n)+1), n=1,2,3,... - Yosu Yurramendi, Jul 05 2014
a(2^m) = m+1, a(2^m+1) = m+2 for m >= 0. - Yosu Yurramendi, Jan 01 2015
a(n+2) = A007305(n+2) + A047679(n) n >= 0. - Yosu Yurramendi, Mar 30 2016
a(2^m+2^r+k) = a(2^r+k)(m-r+1) - a(k), m >= 2, 0 <= r <= m-1, 0 <= k < 2^r. Example: a(73) = a(2^6+2^3+1) = a(2^3+1)*(6-3+1) - a(1) = 5*4 - 1 = 19 . - Yosu Yurramendi, Jul 19 2016
From Antti Karttunen, Mar 21 2017 & Apr 12 2017: (Start)
For n > 0, a(n) = A001222(A277324(n-1)) = A001222(A260443(n-1)*A260443(n)).
The following decompositions hold for all n > 0:
a(n) = A277328(n-1) + A284009(n-1).
a(n) = A283986(n) + A283988(n) = A283987(n) + 2*A283988(n).
a(n) = 2*A284265(n-1) + A284266(n-1).
a(n) = A284267(n-1) + A284268(n-1).
a(n) = A284565(n-1) + A284566(n-1).
a(n) = A285106(n-1) + A285108(n-1) = A285107(n-1) + 2*A285108(n-1). (End)
a(A059893(n)) = a(n+1) for n > 0. - Yosu Yurramendi, May 30 2017
a(n) = A287731(n) + A287732(n) for n > 0. - I. V. Serov, Jun 09 2017
a(n) = A287896(n) + A288002(n) for n > 1.
a(n) = A287896(n-1) + A002487(n-1) - A288002(n-1) for n > 1.
a(n) = a(n-1) + A002487(n-1) - 2*A288002(n-1) for n > 1. - I. V. Serov, Jun 14 2017
From Yosu Yurramendi, May 14 2019: (Start)
For m >= 0, M >= m, 0 <= k < 2^m,
a((2^(m+1) + A119608(2^m+k+1))*2^(M-m) - A000035(2^m+k)) =
a((2^(m+2) - A119608(2^m+k+1))*2^(M-m) - A000035(2^m+k)-1) =
a(2^(M+2) - (2^m+k)) = a(2^(M+1) + (2^m+k) + 1) =
a(2^m+k+1)*(M-m) + a(2^(m+1)+2^m+k+1). (End)
a(k) = sqrt(A007305(2^(m+1)+k)*A047679(2^(m+1)+k-2) - A007305(2^m+k)*A047679(2^m+k-2)), m >= 0, 0 <= k < 2^m. - Yosu Yurramendi, Jun 09 2019
G.f.: 1 + x * (1 + x) * Product_{k>=0} (1 + x^(2^k) + x^(2^(k+1))). - Ilya Gutkovskiy, Jul 19 2019
Conjecture: a(n) = a(n-1) + b(n-1) - 2*(a(n-1) mod b(n-1)) for n > 1 with a(0) = a(1) = 1 where b(n) = a(n) - b(n-1) for n > 1 with b(1) = 1. - Mikhail Kurkov, Mar 13 2022
EXAMPLE
[ 0/1; 1/1; ] 1/2; 1/3, 2/3; 1/4, 2/5, 3/5, 3/4; 1/5, 2/7, 3/8, 3/7, 4/7, 5/8, 5/7, 4/5; ...
MAPLE
A007306 := proc(n): if n=0 then 1 else A002487(2*n-1) fi: end: A002487 := proc(m) option remember: local a, b, n; a := 1; b := 0; n := m; while n>0 do if type(n, odd) then b := a + b else a := a + b end if; n := floor(n/2); end do; b; end proc: seq(A007306(n), n=0..77); # Johannes W. Meijer, Jun 05 2011
MATHEMATICA
a[0] = 1; a[n_] := Sum[ Mod[ Binomial[n+k-1, 2k] , 2], {k, 0, n}]; Table[a[n], {n, 0, 77}] (* Jean-François Alcover, Dec 16 2011, after Paul Barry *)
a[0] = 0; a[1] = 1;
Flatten[{1, Table[a[2*n] = a[n]; a[2*n + 1] = a[n] + a[n + 1], {n, 0, 50}]}] (* Horst H. Manninger, Jun 09 2021 *)
PROG
(PARI) {a(n) = if( n<1, n==0, n--; sum( k=0, n, binomial( n+k, n-k)%2))};
(PARI) {a(n) = my(m); if( n<2, n>=0, m = 2^length( binary( n-1)); a(n - m/2) + a(m-n+1))}; /* Michael Somos, May 30 2005 */
(Sage)
@CachedFunction
def a(n):
return a((odd_part(n-1)+1)/2)+a((odd_part(n)+1)/2) if n>1 else 1
[a(n) for n in (0..77)] # after Alessandro De Luca, Peter Luschny, May 20 2014
(Sage)
def A007306(n):
if n == 0: return 1
M = [1, 1]
for b in (n-1).bits():
M[b] = M[0] + M[1]
return M[1]
print([A007306(n) for n in (0..77)]) # Peter Luschny, Nov 28 2017
(R)
maxrow <- 6 # by choice
a <- c(1, 2)
for(m in 0:maxrow) for(k in 1:2^m){
a[2^(m+1)+k ] <- a[2^m+k] + a[k]
a[2^(m+1)-k+1] <- a[2^m+k]
}
a
# Yosu Yurramendi, Jan 05 2015
(R)
# Given n, compute directly a(n)
# by taking into account the binary representation of n-1
# aa <- function(n){
b <- as.numeric(intToBits(n))
l <- sum(b)
m <- which(b == 1)-1
d <- 1
if(l > 1) for(j in 1:(l-1)) d[j] <- m[j+1]-m[j]+1
f <- c(1, m[1]+2) # In A002487: f <- c(0, 1)
if(l > 1) for(j in 3:(l+1)) f[j] <- d[j-2]*f[j-1]-f[j-2]
return(f[l+1])
}
# a(0) = 1, a(1) = 1, a(n) = aa(n-1) n > 1
#
# Example
n <- 73
aa(n-1)
#
# Yosu Yurramendi, Dec 15 2016
(Scheme) (define (A007306 n) (if (zero? n) 1 (A002487 (+ n n -1)))) ;; Code for A002487 given in that entry. - Antti Karttunen, Mar 21 2017
(Python)
from sympy import binomial
def a(n):
return 1 if n<1 else sum(binomial(n + k - 1, 2*k) % 2 for k in range(n + 1))
print([a(n) for n in range(101)]) # Indranil Ghosh, Mar 22 2017
(Python)
from functools import reduce
def A007306(n): return sum(reduce(lambda x, y:(x[0], sum(x)) if int(y) else (sum(x), x[1]), bin((n<<1)-1)[-1:2:-1], (1, 0))) if n else 1 # Chai Wah Wu, May 18 2023
(Magma) [1] cat [&+[Binomial(n+k, 2*k) mod 2: k in [0..n]]: n in [0..80]]; // Vincenzo Librandi, Jun 10 2019
KEYWORD
nonn,frac,tabf,nice
EXTENSIONS
Formula fixed and extended by Franklin T. Adams-Watters, Jul 07 2009
Incorrect Maple program removed by Johannes W. Meijer, Jun 05 2011
STATUS
approved

Search completed in 0.040 seconds