<s>[INST] $\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?
 [/INST] 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.
</s>