TITLE: Only 12 polynomials exist with given properties
QUESTION [44 upvotes]: Prove that there are only 12 polynomials that have

all real roots, and
whose coefficients are all $-1$ or $1$.

(zero coefficients are not allowed, and constant polynomials do not count.)

Two of them are obviously $x-1$ and $x+1$.
I tried applying Viete's theorems, but could not get anything useful.

REPLY [22 votes]: I already accepted @Rolf Hoyer s excellent answer, this is just its simplification, too large for comment, but using the same notation, for the sake of clarity.

$A = \sum_{i=1}^n \alpha_i =\alpha_1 + \alpha_2 + \ldots + \alpha_n$
$B = \sum_{1 \le i<j\le n} \alpha_i\alpha_j = \alpha_1\alpha_2 + \alpha_1\alpha_3 + \ldots + \alpha_{n-1}\alpha_n$
$Z = \prod_{i=1}^n \alpha_i =\alpha_1\alpha_2\ldots\alpha_n$

Since polynomials have coefficients are $-1$ or $1$, than $A$, $B$, and $Z$ must be $-1$ or $1$.
The idea is to express $\sum_{i=1}^n \alpha_i^2$ in terms of $A$ and $B$:
$$\sum_{i=1}^n \alpha_i^2 =\alpha_1^2 + \alpha_2^2 + \ldots + \alpha_n^2 = (\sum_{i=1}^n \alpha_i)^2 - 2*\sum_{1 \le i<j\le n} \alpha_i\alpha_j$$
$$= A^2 - 2B = 1 - 2B = 3$$
Last two steps are based on $A^2 = 1$, and $B$ must be $-1$ since otherwise $\sum_{i=1}^n \alpha_i^2 =1 - 2B$ is negative.
Now, let us apply AM-GM inequality on $\alpha_1^2, \alpha_2^2, \ldots, \alpha_n^2$:
$$3=\sum_{i=1}^n \alpha_i^2 =\alpha_1^2 + \alpha_2^2 + \ldots + \alpha_n^2 \ge  n \sqrt[n]{\prod_{i=1}^n \alpha_i^2} = n \sqrt[n] {Z^2} = n \sqrt[n] 1 = n$$
This means $n \le 3$, in other words, polynomials must be of degree 1, 2, or 3, and those were 12 already found by others in the comments to the original question above. They are:
$$x+1$$
$$x-1$$
$$x^2+x-1$$
$$x^2-x-1$$
$$x^3-x^2-x+1$$
$$x^3+x^2-x-1$$
$$-(x+1)$$
$$-(x-1)$$
$$-(x^2+x-1)$$
$$-(x^2-x-1)$$
$$-(x^3-x^2-x+1)$$
$$-(x^3+x^2-x-1)$$