Solution (source code)

= Solution

First suppose $A=P+N$, with $P$ a real <positive semidefinite matrix> and $N$ a symmetric <nonnegative matrix>. Factor $P=B^TB$, and write $v(z)=(z_1^2,\ldots,z_n^2)^T$. Then
$$
p(z)=\|Bv(z)\|^2+\sum_i N_{ii}(z_i^2)^2+\sum_{i<j}2N_{ij}(z_iz_j)^2.
$$
Each term is a square multiplied by a nonnegative scalar, so $p$ is a <sum of squares polynomial>.

Conversely, suppose $p=\sum_\ell q_\ell^2$. Because $p$ is a degree-four <homogeneous polynomial>, the <homogeneous sum of squares representation> allows every $q_\ell$ to be quadratic and homogeneous. Explicitly, higher-degree parts cannot cancel in a sum of squares; constant parts vanish because $p(0)=0$, and the degree-two part $\sum_\ell(q_\ell^{(1)})^2$ forces all linear parts to vanish. Write
$$
q_\ell(z)=\sum_i a_{\ell i}z_i^2+\sum_{i<j}b_{\ell ij}z_iz_j.
$$
Since $p$ is invariant under every coordinate sign change, <sign averaging of a sum of squares> over independent <Rademacher random variables> gives
$$
p(z)=\sum_\ell\left(\sum_i a_{\ell i}z_i^2\right)^2
+\sum_{i<j}\left(\sum_\ell b_{\ell ij}^2\right)z_i^2z_j^2.
$$
The cross terms vanish because their sign products contain an <odd> power of at least one independent sign. Set
$$
P=\sum_\ell a_\ell a_\ell^T,\qquad N_{ii}=0,\qquad N_{ij}=N_{ji}=\frac12\sum_\ell b_{\ell ij}^2\quad(i<j).
$$
Then $P$ is a <positive semidefinite matrix> and $N$ is a symmetric <nonnegative matrix>. Comparing the coefficients of $z_i^4$ and $z_i^2z_j^2$ gives $A=P+N$. This proves the <sum of squares criterion for a biquadratic form>.