Can someone help me prove the following identity?
$$
\mathop{\mathrm{Tr}}\left(\prod\_{j=0}^{n-1}\begin{pmatrix} 
2\cos\frac{2j\pi}{n} & -m \\
1 & 0
\end{pmatrix}\right)=
\begin{cases}
2 & \text{if } n=1\pmod{2}\\
2m^{\frac{n}{2}} & \text{if } n=0\pmod{4}\\
-2m^{\frac{n}{2}}-4 & \text{if } n=2\pmod{4}\\
\end{cases},
$$


For the 1st equality, since the product of $2\cos\frac{2j\pi}{n}$'s is 2 when $n$ is odd, we only need to prove that the trace is a constant polynomial in $m$. However, because of the cosine term, the approach of polynomial analysis given in [my previous post](https://mathoverflow.net/questions/213246/product-of-a-finite-number-of-matrices-related-to-roots-of-unity) does not seem to work here. 


Situations are the same for the 2nd and 3rd equalities.



Trace of a Product of Finitely Many Matrices with Cosine Entry
I believe this can be evaluated by expanding cos as a sum of exponentials.


Let $\zeta=\exp(2i\pi/n)$. Consider the set $X$ of $n$-tuples $x\_0,\dots,x\_{n-1}\in\{+,-,1,-m\}$
where for each $j$ we require $x\_j=1$ if and only if $x\_{j-1}=-m$. Subscripts are modulo $n$.


Define $w\_j(+)=\zeta^j$ and $w\_j(-)=\zeta^{-j}$ and $w\_j(1)=1$ and $w\_j(-m)=-m$.
Expanding $2\cos\frac{2j\pi}{n}=w\_j(+)+w\_j(-)$ gives the desired trace as $\sum\_{x\in X}w(x)$ where $w(x)=\prod\_{j=0}^{n-1}w\_j(x\_j)$.


Cyclicly permuting by moving the end element to the start has the effect of multiplying $w(x)$ by $\zeta^{N\_+(x)-N\_-(x)}$ where $N\_+$ and $N\_-$ are the number of $+$'s and $-$'s.
The total weight from sequences with $N\_+(x)-N\_-(x)\not\in\{-n,0,n\}$ is therefore zero.


Now we need another group action.
Given $x\in X$ that is not all $+$'s, for each maximal run of $+$'s, move the $-$ or $-m,1$ after the run to the beginning. Each replacement multiplies $w(x)$ by $\zeta^{2k}$ where $k$ is the length of the run, so this procedure gives a sequence $x'$ with $w(x')=w(x)\zeta^{2N\_+(x)}$.
This shows that the total contribution from all sequences with $(N\_+(x),N\_-(x))=(a,b)$ is zero whenever $a\not\in\{0,n/2,n\}$.
A similar argument applies when $b\not\in\{0,n/2,n\}$.


The only non-constant terms not accounted for are those containing no $+$'s or $-$'s, i.e. $1,-m,1,-m,\dots,1,-m$ and $-m,1,-m,\dots,1,-m,1$ for even $n$,
which contribute the $2(-m)^{n/2}$.


