4. Given $a_{n}=\cos ^{n} \frac{\pi}{9}+\cos ^{n} \frac{5 \pi}{9}+\cos ^{n} \frac{7 \pi}{9}$ $\left(n \in \mathbf{N}_{+}\right)$. Then the recurrence relation of the sequence $\left\{a_{n}\right\}$ is $\qquad$ .
4. $a_{n+3}=\frac{3}{4} a_{n+1}+\frac{1}{8} a_{n}, a_{1}=0, a_{2}=\frac{3}{2}, a_{3}=\frac{3}{8}$.

Let $x_{1}=\cos \frac{\pi}{9}, x_{2}=\cos \frac{5 \pi}{9}, x_{3}=\cos \frac{7 \pi}{9}$.
It is easy to see that $x_{1}+x_{2}+x_{3}=0$,
$$
x_{1} x_{2}+x_{2} x_{3}+x_{3} x_{1}=-\frac{3}{4}, x_{1} x_{2} x_{3}=\frac{1}{8} \text {. }
$$

Therefore, $x_{1}, x_{2}, x_{3}$ are the three roots of the equation $x^{3}-\frac{3}{4} x-\frac{1}{8}=0$.
Thus, $x_{i}^{3}=\frac{3}{4} x_{i}+\frac{1}{8}(i=1,2,3)$.
Hence, $a_{1}=x_{1}+x_{2}+x_{3}=0$,
$$
\begin{array}{l}
a_{2}=x_{1}^{2}+x_{2}^{2}+x_{3}^{2} \\
=\left(x_{1}+x_{2}+x_{3}\right)^{2}-2\left(x_{1} x_{2}+x_{2} x_{3}+x_{3} x_{1}\right)=\frac{3}{2} \text {, } \\
a_{3}=x_{1}^{3}+x_{2}^{3}+x_{3}^{3} \\
=\left(x_{1}+x_{2}+x_{3}\right)\left(x_{1}^{2}+x_{2}^{2}+x_{3}^{2}-x_{1} x_{2}-\right. \\
\left.x_{2} x_{3}-x_{3} x_{1}\right)+3 x_{1} x_{2} x_{3} \\
=\frac{3}{8} \text {, } \\
a_{n+3}=x_{1}^{n+3}+x_{2}^{n+3}+x_{3}^{n+3} \\
=x_{1}^{n}\left(\frac{3}{4} x_{1}+\frac{1}{8}\right)+x_{2}^{n}\left(\frac{3}{4} x_{2}+\frac{1}{8}\right)+x_{3}^{n}\left(\frac{3}{4} x_{3}+\frac{1}{8}\right) \\
=\frac{3}{4}\left(x_{1}^{n+1}+x_{2}^{n+1}+x_{3}^{n+1}\right)+\frac{1}{8}\left(x_{1}^{n}+x_{2}^{n}+x_{3}^{n}\right) \\
=\frac{3}{4} a_{n+1}+\frac{1}{8} a_{n} \text {. } \\
\end{array}
$$