A240388 A sequence related to the Stern sequence s(n) (A002487), defined by w(n) = s(3n)/2.
0, 1, 1, 2, 1, 2, 2, 4, 1, 4, 2, 3, 2, 5, 4, 6, 1, 6, 4, 5, 2, 3, 3, 7, 2, 9, 5, 7, 4, 9, 6, 8, 1, 8, 6, 9, 4, 7, 5, 9, 2, 7, 3, 4, 3, 8, 7, 11, 2, 13, 9, 12, 5, 8, 7, 15, 4, 17, 9, 11, 6, 13, 8, 10, 1, 10, 8, 13, 6, 11, 9, 17, 4, 15, 7, 8, 5, 12, 9, 13, 2, 11, 7, 8, 3, 4, 4, 10, 3, 14, 8, 12, 7, 16, 11, 15, 2, 17, 13, 20, 9, 16, 12, 22, 5, 18, 8, 10, 7, 18, 15, 23, 4, 25, 17, 22, 9, 14, 11, 23, 6, 25, 13, 15, 8, 17, 10, 12, 1
Offset: 0
Examples
w(7) = w(8-1) = w(3)+2w(1) = 2+2 = 4. w(11) = w(8+3) = w(4+1)+w(2+1)-w(1)=w(5)+w(3)-w(1) = 2+2-1 = 3. Comment from _N. J. A. Sloane_, Jul 01 2014: (Start) May be arranged as a triangle: 0 1 1 2 1 2 2 4 1 4 2 3 2 5 4 6 1 6 4 5 2 3 3 7 2 9 5 7 4 9 6 8 1 8 6 9 4 7 5 9 2 7 3 ... (End)
Links
- Alois P. Heinz, Table of n, a(n) for n = 0..16384
- Jennifer Lansing, On the Stern sequence and a related sequence, Joint Mathematics Meetings, Baltimore, 2014.
- Jennifer Lansing, Dissertation: On the Stern sequence and a related sequence, PhD dissertation, University of Illinois, 2014.
- Jennifer Lansing, Largest Values for the Stern Sequence, J. Integer Seqs., 17 (2014), #14.7.5.
Crossrefs
Cf. A002487.
Programs
-
Maple
A240388 := proc(n) option remember; local nloc; if n <=1 then n; elif n = 3 then 2; elif type(n,'even') then procname(n/2) ; elif modp(n,8) = 1 then nloc := (n-1)/8 ; procname(4*nloc+1)+2*procname(nloc) ; elif modp(n,8) = 7 then nloc := (n+1)/8 ; procname(4*nloc-1)+2*procname(nloc) ; elif modp(n,8) = 3 then nloc := (n-3)/8 ; procname(4*nloc+1)+procname(2*nloc+1)-procname(nloc) ; else nloc := (n+3)/8 ; procname(4*nloc-1)+procname(2*nloc-1)-procname(nloc) ; end if; end proc: # R. J. Mathar, Jul 05 2014 # second Maple program: b:= proc(n) option remember; `if`(n<2, n, (q-> b(q)+(n-2*q)*b(n-q))(iquo(n, 2))) end: a:= n-> b(3*n)/2: seq(a(n), n=0..128); # Alois P. Heinz, Jun 20 2022
-
Mathematica
Clear[s]; s[0] = 0; s[1] = 1; s[n_?EvenQ] := s[n] = s[n/2]; s[n_?OddQ] := s[n] = s[(n + 1)/2] + s[(n - 1)/2] (* For the Stern sequence *) Clear[w]; w[n_] = 1/2 s[3 n]
-
PARI
a(n)=my(a=1, b=0); n*=3; while(n>0, if(n%2, b+=a, a+=b); n>>=1); b/2 \\ Charles R Greathouse IV, May 27 2014
-
Python
from functools import reduce def A240388(n): return sum(reduce(lambda x,y:(x[0],x[0]+x[1]) if int(y) else (x[0]+x[1],x[1]),bin(3*n)[-1:2:-1],(1,0)))//2 # Chai Wah Wu, Jun 20 2022
Formula
w(0)=0, w(1)=1, and w(3)=2. For n >= 1, w(n) satisfies the recurrences w(2n)=w(n), w(8n +/- 1)=w(4n +/- 1) + 2w(n), w(8n +/- 3)=w(4n +/- 1) + w(2n +/- 1) -w(n).
a(n) = A002487(3*n) / 2. - Joerg Arndt, Jun 20 2022
Comments