# What software can I use to express a polynomial as a sum of squares?

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.

• Take a look at this. SOSTOOLS essentially automates the process. There was once a Macaulay2 package that took care of the symbolic part. Does this look like what you want to do? – Rodrigo de Azevedo Sep 18 '19 at 6:16
• PARI/GP wasn't cool enough ? – Roddy MacPhee Sep 18 '19 at 13:00