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.

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$.
