Discriminant of characteristic polynomial as sum of squares

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.

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.

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.

The answer is Yes in any dimension by a result of Ilyushechkin in Mat. Zametki, 51, 16-23, 1992.

We know that $$H$$ is symmetric, and therefore, diagonalizable, as $$H = Q^TDQ$$ for some orthogonal matrix $$Q$$. Moreover, $$D$$ and $$Q$$ have the same eigenvalues, and thus the same characteristic polynomials. Perhaps this can be used?