Write the general term of the periodic sequence $1$, $-1$, $-1$, $1$, $-1$, $-1$, $1$, ..., as $(-1)^{g(n)}$ or other closed form How to put mathematically sequence that changes sign like:
$n = 0\quad f = 1$
$n = 1 \quad f = -1$
$n = 2 \quad f = -1$
$n = 3 \quad f = 1$
$n = 4 \quad f = -1$
$n = 5 \quad f = -1$
$n = 6 \quad f = 1$
.....
In the form of (-1)^(something) or similar analytical expression.
 A: This formula works:
$$f(n)=-\frac13+\frac43\cos\left(\frac{2\pi}3n\right)$$
Here's a graph of what that looks like.
Since the sum of any three consecutive values is $-1$, it satisfies this recurrence relation:
$$f(x+2)=-f(x+1)-f(x)-1$$
It also satisfies the recurrence relation $f(x+3)=f(x)$, though that's less interesting.
(Geometrically, think of a circle of radius $4/3$ centered on the point $(-1/3,0)$. This circle passes through the three equidistant points $(1,0)$, $(-1,2/\sqrt3)$, and $(-1,-2/\sqrt3)$ (they form the corners of an equilateral triangle inscribed in the circle). The function $f$ alternately takes the $x$-coordinate of each of these points.)
A: \begin{align}
a_1 &=  1 \\
a_2 &= -1 \\
a_n &= a_{n-1}a_{n-2}
\end{align}
Using a product recurrence relation, we have
$$
a_n = a_2^{F_{n-1}}a_1^{F_{n-2}}
$$
Where $F_k$ is the $k$'th Fibonacci number. Given a closed form for $F_k$, we can simplify $a_n$.
$$
F_k = \frac{(1 + \sqrt{5})^k - (1 - \sqrt{5})^k}{2^k\sqrt{5}}
$$
$$
a_n = (-1)^{F_{n-1}} = (-1)^{\frac{(1 + \sqrt{5})^{n-1} - (1 - \sqrt{5})^{n-1}}{2^{n-1}\sqrt{5}}}
$$
This was solved so that the starting index of the sequence was $1$. If you want to start at $0$, we simply shift the index by $+1$.
$$
a_n = (-1)^{F_{n}} = (-1)^{\frac{(1 + \sqrt{5})^{n} - (1 - \sqrt{5})^{n}}{2^{n}\sqrt{5}}}
$$

Using Euler's Formula, we can get a far more (or less) elegant solution:
$$
a_n = (-1)^{F_n} = \cos(\pi F_n) + i\sin(\pi F_n) = e^{i\pi F_n}
$$
A: $$
{1 \over 3}\left[4\cos\left({2n\pi \over 3}\right) - 1\right]\,,\qquad
n = 0,1,2,\ldots
$$
A: Another possibility (closer to the $(-1)^k$ that you claim to have played with) is:
$$
(-1)^{1+\left\lfloor\frac{2(k-1)}{3}\right\rfloor}
$$
(and I won't be surprised if I managed to get one of the shifts wrong).
A: Here's a negative result: $f(n)$ cannot be written in the form
$$ f(n) = (-1)^{g(n)} $$
where $g$ is a polynomial function.
The relevant condition on $g$ is that its values form the period 3 sequence
$$ g(n) \equiv 0, 1, 1, 0, 1, 1, \ldots \pmod{2} $$
The difference sequence of a sequence is defined by $\Delta h(n) = h(n+1) - h(n)$. We can compute the differences of $g$:
$$ \Delta g(n) \equiv 1, 0, 1, 1, 0, 1, \ldots \pmod{2} $$
$$ \Delta^2 g(n) \equiv 1, 1, 0, 1, 1, 0, \ldots \pmod{2} $$
$$ \Delta^3 g(n) \equiv 0, 1, 1, 0, 1, 1, \ldots \pmod{2} $$
and so forth. If $g$ were a polynomial function, then by taking enough differences we would arrive at the zero sequence; but that clearly cannot happen.
A: with $r = -\frac12 + \frac{\sqrt{3}}{2} i$
$$a_k = \frac{2(r^k + \overline{r^k} ) -1}{3} $$
should work.
I'm sorry for posting a wrong answer before.
A: The sign changes every 3 steps. So basically you've got a + if $n = 0$ and then $n = 3$ and $n = 6$ etc. Therefore it's an alternating sequence given as such: $a_n = 1$ if $n$ mod $3 = 0 $ and $-1$ otherwise.
Edit: The answer using the floor function was wrong as pointed by Erick Wong.
Here is another way to write down the general term of the sequence : 
$$a_n = (-1)^{\mathbb{1}_{n \ mod   \ 3 \ \neq \ 0}}.$$
A: The function $\lceil x \rceil - \lfloor x \rfloor$ is $1$ except for integers, where it vanishes. If we scale it to miss only $3$-integers and put as exponent onto $-1$:
$$
(-1)^{\lceil n/3 \rceil - \lfloor n/3 \rfloor}
$$
or similarly, but with the floor function only:
$$
(-1)^{\lfloor -n/3 \rfloor + \lfloor n/3 \rfloor}
$$
we get your desired sequence for $n=0$, $1$, $2\ldots$
A: $$\ (-1)^{n^2\,\rm mod\,3}\ $$
A: If you allow yourself other roots of unity, you can use the discrete fourier transform.
I presume you want the sequence to have period $3$. So, we use the cube root of unity $\zeta = \frac{-1 + i \sqrt{3}}{2}$. The DFT $\hat{f}$ is given by
$$ \hat{f}(n) = \sum_{k=0}^2 f(k) \zeta^{kn} $$
which we can tabulate as


*

*$\hat{f}(0) = -1$

*$\hat{f}(1) = 2$

*$\hat{f}(2) = 2$


Then, we can recover $f$ by
$$ f(n) = \frac{1}{3} \sum_{k=0}^2 \hat{f}(k) \zeta^{-kn} $$
which works out to
$$ f(n) = \frac{1}{3} \left(-1 + 2 \zeta^n + 2 \zeta^{-n} \right) $$
which can be expressed in a variety of forms; e.g. since $\zeta = \exp(2 \pi i / 3)$, we have
$$ \cos\left( \frac{2 \pi n}{3} \right) = \frac{\zeta^n + \zeta^{-n}}{2} $$
and thus
$$ f(n) = \frac{1}{3} \left( -1 + 4 \cos\left( \frac{2 \pi n}{3} \right) \right) $$
More generally, you could solve this by picking any three linearly independent functions with period $3$, then solving a system of equations to recover what coefficients you need on them to construct $f$; the DFT is just a direct way to obtain such a solution when the three functions are $1$, $\zeta$, and $\zeta^2$.
A: A meta-answer: if you already have the sequence $0,1,1,0,1,1\ldots$, then you may take the power of $-1,$ but you actually don't need exponentiation at all (similarly for other periodical sequences):
\begin{align}
a_n &=1 - 2(n^2 \bmod 3)\\
&=1 - 2n^2 + 6\lfloor n^2/3\rfloor\\
&=1 - 2\cdot \lvert (n-1) {\bmod} 3 -1\rvert\\
&= 1 - 2(\lceil n/3 \rceil - \lfloor n/3 \rfloor) \\
&= 1- 2\cdot \mathbf{1}_{\{n: \, 3\not\mid n\}}\\
&=\ldots
\end{align}
which I think is neater. Also:
$$
a_n= (-1)^{2k+1 \bmod 3}
$$
