A007877 Period 4 zigzag sequence: repeat [0,1,2,1].
0, 1, 2, 1, 0, 1, 2, 1, 0, 1, 2, 1, 0, 1, 2, 1, 0, 1, 2, 1, 0, 1, 2, 1, 0, 1, 2, 1, 0, 1, 2, 1, 0, 1, 2, 1, 0, 1, 2, 1, 0, 1, 2, 1, 0, 1, 2, 1, 0, 1, 2, 1, 0, 1, 2, 1, 0, 1, 2, 1, 0, 1, 2, 1, 0, 1, 2, 1, 0, 1, 2, 1, 0, 1, 2, 1, 0, 1, 2, 1, 0, 1, 2, 1, 0
Offset: 0
Links
- P. Liu, Efficient recognition of integer sequences, Master's Essay, University of Waterloo, Dec. 1994. (Annotated scanned copy)
- Index entries for sequences related to Chebyshev polynomials.
- Index entries for linear recurrences with constant coefficients, signature (1,-1,1).
Crossrefs
Programs
-
Magma
&cat [[0,1,2,1]^^25]; // Vincenzo Librandi, Dec 27 2015
-
Maple
A007877:=n->sqrt(n^2 mod 8); seq(A007877(n), n=0..100); # Wesley Ivan Hurt, Jan 01 2014
-
Mathematica
f[n_] := Mod[n, 4] - Mod[n^3, 4] + Mod[n^2, 4] (* Or *) f[n_] := Mod[n, 2] + 2 Floor[Mod[n + 1, 4]/3] (* Or *) f[n_] := Switch[Mod[n, 4], 0, 0, 1, 1, 2, 2, 3, 1]; Array[f, 105, 0] (* Robert G. Wilson v, Aug 08 2011 *) Table[Sqrt[Mod[n^2,8]], {n,0,100}] (* Wesley Ivan Hurt, Jan 01 2014 *) LinearRecurrence[{1, -1, 1}, {0, 1, 2}, 80] (* Vincenzo Librandi, Dec 27 2015 *) PadRight[{},100,{0,1,2,1}] (* Harvey P. Dale, Oct 24 2023 *)
-
PARI
a(n)=[0,1,2,1][1+n%4] \\ Jaume Oliver Lafont, Mar 27 2009
-
PARI
concat(0, Vec(x*(1+x)/(1-x+x^2-x^3) + O(x^100))) \\ Altug Alkan, Dec 29 2015
-
Python
def A007877(n): return (0,1,2,1)[n&3] # Chai Wah Wu, Jan 26 2023
Formula
Multiplicative with a(p^e) = 2 if p = 2 and e = 0; 0 if p = 2 and e > 0; 1 if p > 2. - David W. Wilson, Aug 01 2001
a(n) = -Sum_{k=0..n} (-1)^C(k+2, 2) (Offset -1). - Paul Barry, Jul 07 2003
a(n) = 1 - cos(n*Pi/2); a(n) = a(n-1) - a(n-2) + a(n-3) for n>2. - Lee Reeves (leereeves(AT)fastmail.fm), May 10 2004
a(n) = -a(n-2) + 2, n >= 2, a(0) = 0, a(1) = 1.
G.f.: x*(1+x)/((1-x)*(1+x^2)) = x*(1+x)/(1-x+x^2-x^3).
a(n) = 1 - T(n, 0) = 1 - A056594(n) with Chebyshev's polynomials T(n, x) of the first kind. Note that T(n, 0) = S(n, 0).
a(n) = b(n) + b(n-1), n >= 1, with b(n) := A021913(n+1) the partial sums of S(n,0) = U(n,0) = A056594(n) (Chebyshev's polynomials evaluated at x=0).
a(n) = 1 + (1/2){(-1)^[(n-1)/2] - (-1)^[n/2]}. - Ralf Stephan, Jun 09 2005
Non-reduced g.f.: x*(1+x)^2/(1-x^4). - Jaume Oliver Lafont, Mar 27 2009
a(n+1) = (S(n, sqrt(2)))^2, n >= 0, with the Chebyshev S-polynomials A049310. See the W. Lang link under A181878. - Wolfdieter Lang, Dec 15 2010
Dirichlet g.f. (1 + 1/2^s - 2/4^s)*zeta(s). - R. J. Mathar, Feb 24 2011
a(n) = (n mod 4) - (n^3 mod 4) + (n^2 mod 4). - Gary Detlefs, Apr 17 2011
a(n) = (n mod 2) + 2*floor(((n+1) mod 4)/3). - Gary Detlefs, Jul 19 2011
a(n) = sqrt(n^2 mod 8). - Wesley Ivan Hurt, Jan 01 2014
a(n) = (n AND 4*k+2)-(n AND 4*k+1) + 2*floor(((n+2) mod 4)/3), for any k. - Gary Detlefs, Jun 08 2014
a(n) = Sum_{i=1..n} (-1)^floor((i-1)/2). - Wesley Ivan Hurt, Dec 26 2015
a(n) = a(n-4) for n >= 4. - Wesley Ivan Hurt, Sep 07 2022
a(n) = n - 2*floor(n/4) - 2*floor((n+1)/4). - Ridouane Oudra, Jan 22 2024
E.g.f.: exp(x) - cos(x). - Stefano Spezia, Aug 04 2025
Extensions
Chebyshev comments from Wolfdieter Lang, Sep 10 2004
Comments