A020944 a(2n+1) = |a(2n) - a(2n-1)|, a(2n) = a(n) + a(n-1), a(0) = -1.
-1, 1, 0, 1, 1, 0, 1, 1, 2, 1, 1, 0, 1, 1, 2, 1, 3, 2, 3, 1, 2, 1, 1, 0, 1, 1, 2, 1, 3, 2, 3, 1, 4, 3, 5, 2, 5, 3, 4, 1, 3, 2, 3, 1, 2, 1, 1, 0, 1, 1, 2, 1, 3, 2, 3, 1, 4, 3, 5, 2, 5, 3, 4, 1, 5, 4, 7, 3, 8, 5, 7, 2, 7, 5, 8, 3, 7, 4, 5, 1, 4, 3, 5, 2, 5, 3, 4, 1, 3, 2, 3, 1, 2, 1, 1, 0, 1, 1, 2, 1, 3, 2, 3, 1, 4, 3
Offset: 0
Examples
G.f. = -1 + x + x^3 + x^4 + x^6 + x^7 + 2*x^8 + x^9 + x^10 + x^12 + x^13 + 2*x^14 + ...
Links
- Seiichi Manyama, Table of n, a(n) for n = 0..12287
- Roland Bacher, Twisting the Stern sequence, arXiv:1005.5627v1 [math.CO], 2010.
- Michael Coons, On Some Conjectures concerning Stern's Sequence and its Twist, arXiv:1008.0193v3 [math.NT], 2010.
Programs
-
Haskell
a020944 n = a020944_list !! n a020944_list = -1 : f [1,0] where f (x:y:xs) = x : f (y:xs ++ [x,x+y]) -- Same list generator function as for a020951_list, cf. A020951. -- Reinhard Zumkeller, Mar 13 2013
-
Mathematica
a[ n_] := Which[ n < 2, Boole[n == 1] - Boole[n == 0], OddQ[n], Abs[a[n - 1] - a[n - 2]], True, a[n/2] + a[n/2 - 1]]; (* Michael Somos, Jul 25 2018 *)
-
PARI
{a(n) = if( n<2,(n==1) - (n==0), n%2, abs( a(n-1) - a(n-2) ), a(n/2) + a(n/2 - 1) )}; /* Michael Somos, Jan 08 2011 */
-
PARI
{a(n) = my(A, m); if( n<0, 0, m = 1; A = -1 + O(x); while( m <= n, m*=2; A = 2*x + (1 + x + x^2) * subst( A, x, x^2 ) ); polcoeff( A, n ) )}; /* Michael Somos, Jan 08 2011 */
Formula
G.f. A(x) satisfies: A(x) = 2*x + (1 + x + x^2) * A(x^2). - Michael Somos, Jan 08 2011
Extensions
More terms from Henry Bottomley, May 16 2001
Added a(0) from Michael Somos, Jan 08 2011
Comments