What is a mathematical expression for the sequence $\{1,1,-1,-1,1,1,-1,-1,\dots\}$?

Starting with $n=0$, these all work. $$\begin{align} a_n&=(-1)^{n(n-1)/2}\\ a_n&=(-1)^{\left\lfloor\frac{n}{2}\right\rfloor}\\ a_n&=\cos(n\pi/2)+\sin(n\pi/2)\\ a_n&=\sqrt{2}\cdot\sin\big((2n+1)\tfrac{\pi}4\big) \end{align}$$

If I'm being honest, being able to come up with these things for me comes from having seen them before. But in each case you can think about the pattern of even/odd exponents for $-1$ or the periodicity mod 4 if you were trying to build these having no prior knowledge.

$\color{blue}{Update}:$ And modified from this post so it starts $a_0=1$, $$\begin{align} a_n&=\sqrt{2}\cdot\cos\big((2n-1)\tfrac{\pi}4\big) \end{align}$$


The sequence $a_0=1$, $a_1=1$, $a_2=-1$, $a_3=-1$, $a_4=1$ and so on satisfies the recursion $$ a_0=1,\quad a_1=1,\qquad a_{n+2}=-a_n $$ so its characteristic equation is $t^2+1=0$. Thus the general solution is of the form $$ xi^n+y(-i)^n $$ The initial conditions tell that $x+y=1$ and $xi-yi=1$, thus $$ \begin{cases} x+y=1\\[4px] x-y=-i \end{cases} $$ that gives $$ x=\frac{1-i}{2},\quad y=\frac{1+i}{2} $$ Since $i=\cos\frac{\pi}{2}+i\sin\frac{\pi}{2}$, we can write \begin{align} a_n &=\frac{1}{2}\bigl( (1-i)(\cos\tfrac{n\pi}{2}+i\sin\tfrac{n\pi}{2})+ (1+i)(\cos\tfrac{n\pi}{2}-i\sin\tfrac{n\pi}{2}) \bigr)\\[6px] &=\cos\frac{n\pi}{2}+\sin\frac{n\pi}{2} \end{align}


A rather exotic formula uses tribonacci numbers $T_n$,

$$a_n = -(-1)^{T_n} = 1,1,-1,-1,1,1,-1,-1,\dots$$

where,

$$T_n=\sum_{k=0}^n\sum_{j=0}^{n-k}\tbinom{n-k}{j}\tbinom{j}{k-j}=1, 1, \color{blue}{2, 4}, 7, 13, \color{blue}{24, 44}, 81, 149, \color{blue}{274, 504},\dots$$

and we define $T_0=1$.

P.S. The above has period $4$. For other periods which uses the Fibonacci numbers etc, see this post.


You can simply interpolate$(1,1,-1,-1)$, and then use $x=n\bmod4$:

$$a_n=\frac{2}{3}(n\bmod4)^3-5(n\bmod4)^2+\frac{31}{3}(n\bmod4)-5$$