Expression for a 0, -1, 0, 1 pattern? I'm trying to think of a way to create the sequence 0, -1, 0, 1,... with an expression of the type (-1)something * k for k = 1, 2, 3,....
Any ideas? I've sat over this for too long and I know it's not that hard :/
 A: $$a(k)=\frac{(-1)^\frac{k}{2}+(-1)^\frac{-k}{2}}{2}$$
A: If you're okay with using complex numbers you can use the following theorem:

Any sequence $s_n$ of complex numbers of period $k$ can be expressed as a sum of the form
  $$s_n=\sum_{k}\alpha_k\zeta_k^n$$ 
  where the $\alpha_k$ are (potentially complex) coefficients and the $\zeta_k$ are the $k^{th}$ roots of unity - that is, the solutions to $\zeta_k^k=1$ in the complex plane.

In the case of $k=2$ - that is, when your sequence alternates two numbers, the two second roots of unit are $1$ and $(-1)$, so your sequence can be expressed as $\alpha_1 + \alpha_2(-1)^n$. Here, the period of your sequence is $4$, and the fourth roots of unity are $1,\,i,\,-1$ and $-i$. In particular, your sequence can be written as (starting at $n=0$)
$$s_n=\frac{(-i)^n-i^n}{2i.}$$
It should be noted that this is can also be written as $\sin(-n\pi/2)$, which follows from the expansion $\sin(x)=\frac{e^{ix}-e^{-ix}}{2i}$ and that $e^{i\pi/2}=i$.

If you're really committed to using only real numbers and integer powers, you actually can accomplish this, though it's not necessarily something I'd call a good idea, and is going to be more of a fun exercise than anything useful. In particular, note that $\frac{n(n-1)}2$ is even when $n\equiv 0,1$ mod $4$ and odd otherwise. Thus, your sequence can be expressed as:
$$\frac{-1}2(1-(-1)^n)(-1)^{n(n-1)/2}$$
where the first term causes it to alternate between $0$ and something other than zero, and the second term causes longer alternations between $-1$ and $1$. The disadvantage of this method is that it is completely opaque - if you give this expression to someone, they probably won't immediately see what it is.
A: I am giving this formula as a combination of two $1,1,-1,-1,1,1,\ldots$ sequences with an offset:
$$\begin{align*}
b_n &= (-1)^{\lceil n/2\rceil}& &b_1,b_2,b_3,b_4,\ldots = -1,-1,1,1,\ldots\\
c_n &= (-1)^{\lfloor n/2\rfloor}&&c_1,c_2,c_3,c_4,\ldots = 1,-1, -1, 1,\ldots
\end{align*}$$
And $a_n$ is just the average of $b_n$ and $c_n$,
$$a_n = \frac{b_n+c_n}2 = \frac{(-1)^{\lceil n/2\rceil}+(-1)^{\lfloor n/2\rfloor}}2\\
a_1,a_2,a_3,a_4,\ldots = 0,-1,0,1,\ldots$$
This does not involve complex numbers.
A: Written as the real part of a matrix representation of a complex number $$Re\left[e^{i\frac{k\pi}{2}}\right] = Re\left[\left(e^{i\frac{\pi}{2}}\right)^k\right] =  \left({\left[\begin{array}{rr}0&1\\-1&0\end{array}\right]^k}\right)_{\{1,1\}}$$ For practical considerations it can be implemented with 2 bit binary numbers written in $$\text{two complement}\cases{11,&-1\\00,&0\\01,&1} \text{or one complement}\cases{10,&-1\\00,&0\\11,&0\\01,&1}$$ so would be possible to squeeze a matrix into an 8-bit byte and use logic and bit-masking for evaluation and we can also save calculations by letting it work on a vector instead: $$\left(\left[\begin{array}{rr}0&1\\-1&0\end{array}\right]^k\left[\begin{array}{r}0\\1\end{array}\right]\right)_{\{1\}}$$ Maybe that is a bit too obscure, but at least it's something not contained in previous answers and would also generalize well to other sequences as matrix representation theory can handle any group.
