$\cos(\pi/7)$ is a root of $8x^3-4x^2-4x+1=0$. How is the polynomial generated? According to Wolfram MathWorld, $\cos(\frac{\pi}{7})$ is a root of $8x^3-4x^2-4x+1=0$. Similarly, $\cos(\frac{2\pi}{7})$ is a root of $8x^3+4x^2-4x-1=0$. What's the procedure to generate these polynomials? I understand you can solve the cubic equations and check the cosines are indeed roots. My question is how does one arrive at those polynomials in the first place?
 A: $z_1:=\cos(2\pi/7)$ is the real part of $z_2:=\exp(i2\pi/7)$.  Of course $z_2$ is a zero of $z^7-1$.  Factoring this, and checking which factor to use, $z_2$ is a zero of
$$z^6+z^5+z^4+z^2+z+1.
\tag{2}$$
and $z_2\ne 0$, so $z_2$ is a zero of
$$
z^3+z^2+z+1+z^{-1}+z^{-2}+z^{-3}
\tag{3}$$
Now $\overline{z_2}$ is $1/z_2$.  Then from $(3)$ compute: $z_3=z_2+1/z_2$ is a zero of
$$
z^3+z^2-2z-1
$$
Finally, $z_1 = z_3/2$ is a zero of
$$
8z^3+4z^2-4z-1
$$

Can you do the other one using the same method?
A: By DeMoivre's theorem,
$$(\cos x+i\sin x)^7=\cos7x+i\sin7x\quad\quad(*)$$
With $x=\frac\pi7$, the right hand side of $(*)$ reduces to $-1$. Expand the binomial on the left hand side and match up the real and imaginary parts (the latter of which is $0$), leaving us with
$$\cos^7x-21\cos^5x\sin^2x+35\cos^3x\sin^4x-7\cos x\sin^6x=-1$$
Rewrite each instance of $\sin^2x$ as $1-\cos^2x$ and simplify the result; you should end up with
$$64\cos^7x-112\cos^5x+56\cos^3x-7\cos x+1=0$$
the left hand side of which can be factorized as
$$(1+\cos x)(8\cos^3x-4\cos^2x-4\cos x+1)^2=0$$
but $\cos\frac\pi7\neq-1$,
$$8\cos^3\frac\pi7-4\cos^2\frac\pi7-4\cos\frac\pi7+1=0$$
Similarly, with $x=\frac{2\pi}7$, the right hand side of $(*)$ reduces to $1$, and so on.
