The characteristic polynomial of a real symmetric $n\times n$ matrix $H$ has $n$ real roots, counted with multiplicity.
Therefore the discriminant $D(H)$ of this polynomial is zero or positive.
It is zero if and only if there is a degenerate eigenvalue.


Thus $D(H)$ is a non-negative (homogeneous) polynomial in the $\frac12n(n+1)$ entries of $H$.
Some non-negative polynomials can be written as a sum of squares and I am interested in whether $D(H)$ can.
There is a concrete question at the end, but any insights into the general case are also welcome.


The size of the problem grows very quickly with dimension, so I will only look at $n=2$ (which I do understand) and $n=3$ (which I am yet to understand).


2D
--


In two dimensions it is pretty easy to write down the polynomial and its discriminant and see by eye that
$$
D(H)
=
(h\_{11}-h\_{22})^2
+
4h\_{12}^2,
$$
which is indeed a sum of two squares.


Having a degenerate eigenvalue is a polynomial condition: it happens if and only if $D(H)=0$.
The discriminant is a second order polynomial, but writing it as a sum of squares leads to far simpler algebraic condition: $h\_{11}-h\_{22}=0$ and $h\_{12}=0$.
Simple algebraic conditions for degeneracy are the goal here, but I thought the question would be of some interest in itself.


3D
--


In three dimensions the discriminant is pretty big:
$$
D(H)
=
h\_{22}^2h\_{33}^4-2h\_{11}h\_{22}h\_{33}^4+4h\_{12}^2h\_{33}^4+h\_{11}^2h\_{33}^4-2h\_{22}h\_{23}^2h\_{33}^3+2h\_{11}h\_{23}^2h\_{33}^3-8h\_{12}h\_{13}h\_{23}h\_{33}^3-2h\_{22}^3h\_{33}^3+2h\_{11}h\_{22}^2h\_{33}^3+2h\_{13}^2h\_{22}h\_{33}^3-8h\_{12}^2h\_{22}h\_{33}^3+2h\_{11}^2h\_{22}h\_{33}^3-2h\_{11}h\_{13}^2h\_{33}^3-8h\_{11}h\_{12}^2h\_{33}^3-2h\_{11}^3h\_{33}^3+h\_{23}^4h\_{33}^2+8h\_{22}^2h\_{23}^2h\_{33}^2-10h\_{11}h\_{22}h\_{23}^2h\_{33}^2+2h\_{13}^2h\_{23}^2h\_{33}^2+20h\_{12}^2h\_{23}^2h\_{33}^2+2h\_{11}^2h\_{23}^2h\_{33}^2+12h\_{12}h\_{13}h\_{22}h\_{23}h\_{33}^2+12h\_{11}h\_{12}h\_{13}h\_{23}h\_{33}^2+h\_{22}^4h\_{33}^2+2h\_{11}h\_{22}^3h\_{33}^2+2h\_{13}^2h\_{22}^2h\_{33}^2+2h\_{12}^2h\_{22}^2h\_{33}^2-6h\_{11}^2h\_{22}^2h\_{33}^2-10h\_{11}h\_{13}^2h\_{22}h\_{33}^2+20h\_{11}h\_{12}^2h\_{22}h\_{33}^2+2h\_{11}^3h\_{22}h\_{33}^2+h\_{13}^4h\_{33}^2+20h\_{12}^2h\_{13}^2h\_{33}^2+8h\_{11}^2h\_{13}^2h\_{33}^2-8h\_{12}^4h\_{33}^2+2h\_{11}^2h\_{12}^2h\_{33}^2+h\_{11}^4h\_{33}^2-10h\_{22}h\_{23}^4h\_{33}+8h\_{11}h\_{23}^4h\_{33}-36h\_{12}h\_{13}h\_{23}^3h\_{33}-2h\_{22}^3h\_{23}^2h\_{33}-10h\_{11}h\_{22}^2h\_{23}^2h\_{33}-2h\_{13}^2h\_{22}h\_{23}^2h\_{33}-2h\_{12}^2h\_{22}h\_{23}^2h\_{33}+20h\_{11}^2h\_{22}h\_{23}^2h\_{33}-2h\_{11}h\_{13}^2h\_{23}^2h\_{33}-38h\_{11}h\_{12}^2h\_{23}^2h\_{33}-8h\_{11}^3h\_{23}^2h\_{33}+12h\_{12}h\_{13}h\_{22}^2h\_{23}h\_{33}-48h\_{11}h\_{12}h\_{13}h\_{22}h\_{23}h\_{33}-36h\_{12}h\_{13}^3h\_{23}h\_{33}+72h\_{12}^3h\_{13}h\_{23}h\_{33}+12h\_{11}^2h\_{12}h\_{13}h\_{23}h\_{33}-2h\_{11}h\_{22}^4h\_{33}-8h\_{13}^2h\_{22}^3h\_{33}+2h\_{12}^2h\_{22}^3h\_{33}+2h\_{11}^2h\_{22}^3h\_{33}+20h\_{11}h\_{13}^2h\_{22}^2h\_{33}-10h\_{11}h\_{12}^2h\_{22}^2h\_{33}+2h\_{11}^3h\_{22}^2h\_{33}+8h\_{13}^4h\_{22}h\_{33}-38h\_{12}^2h\_{13}^2h\_{22}h\_{33}-10h\_{11}^2h\_{13}^2h\_{22}h\_{33}+8h\_{12}^4h\_{22}h\_{33}-10h\_{11}^2h\_{12}^2h\_{22}h\_{33}-2h\_{11}^4h\_{22}h\_{33}-10h\_{11}h\_{13}^4h\_{33}-2h\_{11}h\_{12}^2h\_{13}^2h\_{33}-2h\_{11}^3h\_{13}^2h\_{33}+8h\_{11}h\_{12}^4h\_{33}+2h\_{11}^3h\_{12}^2h\_{33}+4h\_{23}^6+h\_{22}^2h\_{23}^4+8h\_{11}h\_{22}h\_{23}^4+12h\_{13}^2h\_{23}^4+12h\_{12}^2h\_{23}^4-8h\_{11}^2h\_{23}^4-36h\_{12}h\_{13}h\_{22}h\_{23}^3+72h\_{11}h\_{12}h\_{13}h\_{23}^3+2h\_{11}h\_{22}^3h\_{23}^2+20h\_{13}^2h\_{22}^2h\_{23}^2+2h\_{12}^2h\_{22}^2h\_{23}^2+2h\_{11}^2h\_{22}^2h\_{23}^2-38h\_{11}h\_{13}^2h\_{22}h\_{23}^2-2h\_{11}h\_{12}^2h\_{22}h\_{23}^2-8h\_{11}^3h\_{22}h\_{23}^2+12h\_{13}^4h\_{23}^2-84h\_{12}^2h\_{13}^2h\_{23}^2+20h\_{11}^2h\_{13}^2h\_{23}^2+12h\_{12}^4h\_{23}^2+20h\_{11}^2h\_{12}^2h\_{23}^2+4h\_{11}^4h\_{23}^2-8h\_{12}h\_{13}h\_{22}^3h\_{23}+12h\_{11}h\_{12}h\_{13}h\_{22}^2h\_{23}+72h\_{12}h\_{13}^3h\_{22}h\_{23}-36h\_{12}^3h\_{13}h\_{22}h\_{23}+12h\_{11}^2h\_{12}h\_{13}h\_{22}h\_{23}-36h\_{11}h\_{12}h\_{13}^3h\_{23}-36h\_{11}h\_{12}^3h\_{13}h\_{23}-8h\_{11}^3h\_{12}h\_{13}h\_{23}+4h\_{13}^2h\_{22}^4+h\_{11}^2h\_{22}^4-8h\_{11}h\_{13}^2h\_{22}^3-2h\_{11}h\_{12}^2h\_{22}^3-2h\_{11}^3h\_{22}^3-8h\_{13}^4h\_{22}^2+20h\_{12}^2h\_{13}^2h\_{22}^2+2h\_{11}^2h\_{13}^2h\_{22}^2+h\_{12}^4h\_{22}^2+8h\_{11}^2h\_{12}^2h\_{22}^2+h\_{11}^4h\_{22}^2+8h\_{11}h\_{13}^4h\_{22}-2h\_{11}h\_{12}^2h\_{13}^2h\_{22}+2h\_{11}^3h\_{13}^2h\_{22}-10h\_{11}h\_{12}^4h\_{22}-2h\_{11}^3h\_{12}^2h\_{22}+4h\_{13}^6+12h\_{12}^2h\_{13}^4+h\_{11}^2h\_{13}^4+12h\_{12}^4h\_{13}^2+2h\_{11}^2h\_{12}^2h\_{13}^2+4h\_{12}^6+h\_{11}^2h\_{12}^4
.
$$
(I got this by Maxima.)
This is indeed a non-negative homogeneous polynomial of degree six in six variables, but it is too big for me to see any structure by eye and I cannot tell whether it is a sum of squares.


In the diagonal case $h\_{12}=h\_{13}=h\_{23}=0$ the discriminant has a simpler expression:
$$
D(H)
=
(h\_{11}-h\_{22})^2
(h\_{22}-h\_{33})^2
(h\_{11}-h\_{33})^2.
$$
This form is not at all surprising, as it should be a sixth degree polynomial vanishing if and only if two diagonal entries coincide.


My concrete question is:
**Is this $D(H)$ of the case $n=3$ a sum of squares (without assuming it is diagonal)?**
If yes, what are the squared polynomials and how unique are they?


I have understood that there are computational tools for finding a sum of squares decomposition, but I have yet to find one that I could run with the software I have.
And I assume this particular polynomial has structure which simplifies matters: for example, the polynomial is invariant under orthogonal changes of basis and the non-negativity has a geometric meaning.
One can indeed diagonalize the matrix, but I cannot see a way to use this to understand what the polynomial is in terms of the original basis.
The 2D case and the diagonal 3D case suggest that being a sum of squares is a reasonable guess.



Discriminant of characteristic polynomial as sum of squares
The answer for a general $n$ is positive: the discriminant is a sum of squares of polynomials in the entries of $H$. The first formula was given by Ilyushechkin and involves $n!$ squares. This number was improved by Domokos into
$$\binom{2n-1}{n-1}-\binom{2n-3}{n-1}.$$
See Exercise #113 on my [page.](http://perso.ens-lyon.fr/serre/DPF/exobis.pdf)


**Details** of Ilyushechkin's solution. Consider the scalar product $\langle A,B\rangle={\rm Tr}(AB)$ over ${\bf Sym}\_n({\mathbb R})$. It extends as a scalar product over the exterior algebra. Then the discriminant equals
$$\|I\_n\wedge H\wedge\cdots\wedge H^{n-1}\|^2,$$
which is a sum of squares of polynomials.


