<s>[INST] Give a general formula for the following sequence I have a sequence where the terms are $1,0,-1,-1,0,1,1,0,-1,-1...$. Can someone help me find a general formula in terms of $n$ for this sequence?
 [/INST] We write the $n^{th}$ term of the sequence as $a_n$, then
$\displaystyle a_n = \begin{cases} 1 &\textrm{ if } n \equiv 1 \pmod 6 \\ 0 &\textrm{ if } n \equiv 2 \pmod 6 \\ -1 &\textrm{ if } n \equiv 3 \pmod 6 \\ -1 &\textrm{ if } n \equiv 4 \pmod 6 \\ 0 &\textrm{ if } n \equiv 5 \pmod 6 \\ 1 &\textrm{ if } n \equiv 0 \pmod 6 \end{cases}$
Consider the generating function of $a_n$, $\displaystyle f(x) = \sum\limits_{n=1}^{\infty} a_n x^n$
Then, $\displaystyle f(x) = \sum\limits_{n=0}^{\infty} (x^{6n+1}-x^{6n+3}-x^{6n+4}+x^{6n+6}) = \frac{x-x^3-x^4+x^6}{1-x^6} $
$\displaystyle = -1+ \frac{1}{1-x+x^2}$
Now, the roots of $1-x+x^2$ are $\alpha = \cos \frac{\pi}{3} + i\sin\frac{\pi}{3}$ and $\beta = \cos \frac{\pi}{3} - i\sin\frac{\pi}{3}$
Thus, $\displaystyle \frac{1}{1-x+x^2} = \frac{1}{\alpha - \beta}\left(\frac{1}{x-\alpha} - \frac{1}{x-\beta}\right) = \frac{2}{\sqrt{3}}\Im \left(\frac{\alpha}{1-\alpha x}\right) $
$\displaystyle = \sum\limits_{n=0}^{\infty} \frac{2}{\sqrt{3}}\sin \frac{(n+1)\pi}{3}x^n$
Thus, $\displaystyle a_n = \frac{2}{\sqrt{3}}\sin \frac{(n+1)\pi}{3}$
</s>