I have a 169 term degree 8 homogeneous polynomial in 14 variables that I believe can be expressed as a sum of 8 squares. I discovered the other day that methods exist for expressing a polynomial as a sum of squares, but I'm wondering if there is any software available that can do this calculation. Does MATLAB, Mathematica, or Sage have this capability?
I saw this MATLAB library called SOSTOOLS that solves optimization problems having to do with polynomial sums of squares, but I can't tell if it has methods that do what I'm trying to do.
Here's the math behind the method. Let $x$ be a vector of $s$ polynomials that form a basis of the space of polynomials you're working in. Then any polynomial $P$ can be expressed in the form $P=x^tMx$ for some matrix $M$. Let $L$ be the set of all matrices satisfying $x^tLx=0$. Then $\{x^t(M+l)x|l\in L\}$ is the set of all representations of $P$ in this form. If $M+l$ is positive semidefinite with rank $r$, then we can find an $r\times s$ matrix $Q$ satisfying $Q^tQ=M+l$. Then we get $P=(Qx)^t(Qx)$, so we have expressed $P$ as a sum of $r$ squares. $L$ can be parameterized linearly, so this is some sort of linear optimization problem I guess.
In my case, we can let $x$ be the vector of all monomials of degree 4 in my 14 variables. Then we are trying to find positive semidefinite $M+l$ with rank 8.
I don't know about performance for polynomials of that size, but first thing I would try is to solve the SDP directly.
Since the question was about software, I will show what I wrote using Sage, but I'll omit the math behind it, as that can be found in many other places. I wrote the SDP into SDPA format to run CSDP on it.
First, some utility functions.
sos.py:Now, the construction of the SDP:
Example:
As you can see I used some methods to run csdp, but all they do is call csdp on the command line and read back the result, so I've omitted the definitions.