TL;DR
The paper introduces a Macaulay2 package that efficiently decomposes polynomials into sums of squares using advanced methods, supporting various optimization techniques and external solvers.
Contribution
It presents a new Macaulay2 package with capabilities for sums-of-squares decomposition, integrating modern algorithms and solver support.
Findings
Supports external semidefinite programming solvers
Includes a data type for sums-of-squares polynomials
Enables optimization over algebraic varieties
Abstract
The Macaulay2 package SumsOfSquares decomposes polynomials as sums of squares. It is based on methods to rationalize sum-of-squares decompositions due to Parrilo and Peyrl. The package features a data type for sums-of-squares polynomials, support for external semidefinite programming solvers, and optimization over varieties.
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Code & Models
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Sums of squares in Macaulay2
Diego Cifuentes
Massachusetts Institute of Technology
Cambridge, MA, USA
,
Thomas Kahle
Otto-von-Guericke University
Magdeburg, Germany
and
Pablo A. Parrilo
Massachusetts Institute of Technology
Cambridge, MA, USA
Abstract.
The Macaulay2 package SumsOfSquares decomposes polynomials as sums of squares. It is based on methods to rationalize sum-of-squares decompositions due to Parrilo and Peyrl. The package features a data type for sums-of-squares polynomials, support for external semidefinite programming solvers, and optimization over varieties.
1. Introduction
Let or be the rational or real numbers and be the polynomial ring. An element is nonnegative if for all , and is a sum of squares (SOS) if there are polynomials and positive scalars such that . The scalars are not necessary when the field is . Clearly, a sum of squares is nonnegative, but not every nonnegative polynomial is a sum of squares. Hilbert showed that the nonnegative polynomials of degree in variables are sums of squares if and only if: ; or ; or and . For an introduction to the area we recommend [9, 2].
The SumsOfSquares package contains methods to compute sums-of-squares in Macaulay2 [6]. A particular focus is on trying to find rational sums-of-squares decompositions of polynomials with rational coefficients (whenever they exist).
Consider the basic problem of deciding whether a polynomial is a sum of squares. Let of degree , and a vector whose entries are the monomials of degree . The following fundamental result holds:
[TABLE]
where is the cone of symmetric positive semidefinite matrices; see [2, §3.1]. This reduces the problem to finding a Gram matrix as above, which can be done efficiently with semidefinite programming (SDP).
The method solveSOS performs the computation above. We use it here to verify that is a sum of squares:
i1 : R = QQ[x,y]; i2 : f = 2x^4+5y^4-2x^2y^2+2x^3y; i3 : sol = solveSOS f; Executing CSDP Status: SDP solved, primal-dual feasible
The “Status” line indicates that a Gram matrix was found, so is indeed a sum of squares. In the example above the package called an external program to serve as semidefinite programming solver. The default solver is the open source program CSDP [3], which is included in Macaulay2. The output of solveSOS is an object of type SDPResult. It contains, in particular, the Gram matrix and the monomial vector .
i4 : (Q,v) = ( sol#GramMatrix, sol#Monomials ) o4 = ( | 2 1 -83/40 |, | x2 | ) | 1 43/20 0 | | xy | | -83/40 0 5 | | y2 |
The result of the semidefinite programming solver is a floating point approximation of the Gram matrix. The SumsOfSquares package attempts to find a close enough rational Gram matrix by rounding its entries [8]. If this rounding procedure fails to find a feasible rational matrix, the method returns the floating point solution. The procedure is guaranteed to work when the floating point Gram matrix lies in the interior of . See Appendix A for more details about rational rounding.
The method sosPoly extracts the sum-of-squares decomposition from the returned SDPResult. This is done via an LDL factorization (a variant of Cholesky factorization) of the Gram matrix. For the function from above we get three squares:
i5 : s = sosPoly sol 83 2 2 2 43 20 2 2 231773 2 2 o5 = (5)(- ---x + y ) + (--)(--x + x*y) + (------)(x ) 200 20 43 344000
The output above is an object of type SOSPoly. An object of this type stores the coefficients and polynomials (or generators) such that . We can extract the coefficients and generators as follows:
i5 : coefficients s o5 = {5, 43/20, 231773/344000} i6 : gens s o6 = {-83/200x^2 + y^2, 20/43x^2 + x*y, x^2}
The method solveSOS can also compute sums-of-squares decompositions in quotient rings. This can be useful to prove nonnegativity of a polynomial on a variety. We take an example from [7]. Consider proving that is nonnegative on the circle defined by . To do this, we check if is a sum of squares in the quotient ring . For such a computation, an even degree bound must be given by the user, as otherwise it is not obvious how to choose the monomial vector . In the following example we use as the degree bound.
i1 : R = QQ[x,y]/ideal(x^2 + y^2 - 1); i2 : f = 10-x^2-y; d = 1; i3 : sosPoly solveSOS (f, 2*d, TraceObj=>true) Executing CSDP Status: SDP solved, primal-dual feasible 1 2 35 2 o3 = (9)(- -- y + 1) + (--)(y) 18 36
In the computation above the option TraceObj=>true was used to reduce the number of squares in the SOS decomposition (see Section 6).
2. Sums of squares in ideals
Let be an ideal. Given an even bound , consider the problem of finding a nonzero sum-of-squares polynomial of degree in the ideal . If one of the generators of has degree , then the problem is trivial. But otherwise the problem can be hard. The method sosInIdeal can be used to solve it. One of the main motivations for this problem is that it reveals information about the real radical of the ideal , i.e., the vanishing ideal of the real zeros of . Indeed, if then each of the factors must lie in the real radical of .
Given generators of the ideal , we may solve this problem by looking for some polynomial multipliers such that is a sum of squares. The method sosInIdeal can find these multipliers. The input is a matrix containing the generators, and the degree bound . We illustrate this for the ideal
i1 : R = QQ[x,y,z]; d = 1; i2 : h = matrix {{x^2-4x+2y^2, 2z^2-y^2+2}}; i3 : (sol,mult) = sosInIdeal (h, 2d); i4 : sosPoly sol 395 1 2 395 2 o4 = (---)(- - x + 1) + (---)(z) 2 2 2 i5 : h * mult == sosPoly sol o5 = true
Another way to approach this problem is to construct the quotient and then write as a sum of squares. In this case the input to sosInIdeal is simply the quotient ring .
i6 : S = R/ideal h; i7 : sosPoly sosInIdeal (S, 2*d); 1031833 1 2 1031833 2 o7 = (-------)(- - x + 1) + (-------)(z) 2048 2 2048
In both cases we obtained a multiple of the sum-of-squares polynomial . This computation reveals that lie in the real radical of . Indeed, we have .
3. SOS decompositions of ternary forms
Hilbert showed that any nonnegative form can be decomposed as a quotient of sums of squares. We can obtain this decomposition by iteratively calling sosInIdeal. Specifically, one can first find a multiplier such that is a sum of squares. Since is also nonnegative, we can then search for a multiplier such that is a sum of squares, and so on. The main observation is that the necessary degree of is lower than that of [5]. Hence this procedure terminates, and we can write
[TABLE]
As an illustration, we write the Motzkin polynomial as a quotient of sums of squares. We first use the function library, which contains a small library of interesting nonnegative forms.
i1 : R = QQ[x,y,z] i2 : f = library ("Motzkin", {x,y,z}) 4 2 2 4 2 2 2 6 o2 = x y + x y - 3x y z + z
We now apply the function sosdecTernary, which implements the iterative algorithm from above.
i3 : (Nums,Dens) = sosdecTernary f; Executing CSDP i4 : num = first Nums 2267 2 2 4 2 2003 1013 3 990 3 2 2 o4 = (----)(x y - z ) + (----)(- ----x y - ----xy + xy*z ) + ... 64 64 2003 2003 i5 : den = first Dens 2267 2 1079 2 33 2 o5 = (----)(z) + (----)(x) + (--)(y) 64 64 2
The result consists of two sums of squares, the second being the denominator. We can check the computation as follows.
i6 : f*value(den) == value(num) o6 = true
4. Parametric SOS problems
The SumsOfSquares package can also solve parametric problems. Assume now that is a polynomial function, that depends affinely on some parameters . The command solveSOS can be used to search for values of the parameters such that the polynomial is a sum of squares. In the following example, we change two coefficients of the Robinson polynomial so that it becomes a sum of squares.
i1 : R = QQ[x,y,z][s,t]; i2 : g = library("Robinson", {x,y,z}) + sx^6 + ty^6; i3 : sol = solveSOS g; Executing CSDP Status: SDP solved, primal-dual feasible i4 : sol#Parameters o4 = | 34 | | 34 |
In the code above, the ring construction (first line) indicates that should be treated as parameters. The values obtained were .
It is also possible find the values of the parameters that optimize a given linear function. This allows us to find lower bounds for a polynomial function , by finding the largest such that is a sum of squares. Here we apply this method to the dehomogenized Motzkin polynomial.
i1 : R = QQ[x,z][t]; i2 : f = library ("Motzkin", {x,1,z}); i3 : sol = solveSOS (f-t, -t, RoundTol=>12); Executing CSDP Status: SDP solved, primal-dual feasible i4 : sol#Parameters o4 = | -729/4096 |
Alternatively, the method lowerBound can be called with input . The method internally declares a new parameter and optimizes .
i1 : R = QQ[x,z]; i2 : f = library ("Motzkin", {x,1,z}); i3 : (t,sol) = lowerBound (f, RoundTol=>12); Executing CSDP Status: SDP solved, primal-dual feasible i4 : t o4 = - 729/4096
5. Polynomial optimization
In applications one often needs to find lower bounds for polynomials subject to some polynomial constraints. More precisely, consider the problem
[TABLE]
where are polynomials. The SumsOfSquares package provides two ways to compute a lower bound for such a problem. The most elegant approach is to construct the associated quotient ring, and then call lowerBound. This will look for the largest such that is a sum of squares (in the quotient ring). A degree bound must be given by the user.
i1 : R = QQ[x,y]/ideal(x^2 - x, y^2 - y); i2 : f = x - y; d = 1; i3 : (t,sol) = lowerBound(f,2*d); Executing CSDP Status: SDP solved, primal-dual feasible i4 : t o4 = -1 i5 : f - t == sosPoly sol o5 = true
Calling lowerBound as above is conceptually simple, but requires knowledge of a Gröbner basis, which is computed when constructing the quotient ring. If no Gröbner basis is available there is an alternative way to call lowerBound with just the equations as the input. The method will then look for polynomial multipliers such that is a sum of squares. This may result in larger semidefinite programs and weaker bounds.
i1 : R = QQ[x,y]; i2 : f = x - y; d = 1; i3 : h = matrix{{x^2 - x, y^2 - y}}; i4 : (t,sol,mult) = lowerBound (f, h, 2d); Executing CSDP Status: SDP solved, primal-dual feasible i5 : t o5 = -1 i6 : f - t + hmult == sosPoly sol o6 = true
Lower bounds for polynomial optimization problems critically depend on the degree bound chosen. While higher degree bounds lead to better bounds, the computational complexity escalates quite rapidly. Nonetheless, low degree SOS lower bounds often perform very well in applications. In some cases, the minimizer might also be recovered from the SDPResult with the method recoverSolution.
i7 : recoverSolution sol o7 = {x => 1.77345e-9, y => 1}
6. Optional arguments
SDP Solver
The optional argument Solver is available for many package methods and a particular semidefinite programming solver can be picked by setting it. These solvers are interfaced via the auxiliary Macaulay2 package SemidefiniteProgramming [4]. The package provides interfaces to the open source solvers CSDP [3] and SDPA [10], and the commercial solver MOSEK [1]. There is also a built-in solver in the Macaulay2 language. In our experience CSDP and MOSEK give the best results. CSDP is provided as part of Macaulay2 and configured as the default.
Rounding tolerance
The method lowerBound has the optional argument RoundTol, which specifies the precision of the rational rounding. Smaller values of RoundTol lead to rational matrices with smaller denominators but farther from the numerical solution. The rational rounding may be skipped by setting it to infinity.
Trace objective
The option TraceObj tells the semidefinite programming solver to minimize the trace of the Gram matrix. This is a known heuristic to reduce the number of squares in the SOS decomposition.
Appendix A Rational rounding
Sums-of-squares problems are solved numerically using an semidefinite programming solver, and afterwards the package attempts to round the floating point solution to rational numbers. We briefly describe the rounding procedure, which was proposed in [8].
Let and consider the affine space , where is a given monomial vector. A Gram matrix is an element of . The semidefinite programming solver returns a numerical matrix , an “approximate” Gram matrix, which may not lie exactly on . The rounding problem consists in finding a nearby Gram matrix with rational entries.
The procedure from [8] consists of two steps. First, the entries of are rounded to a rational matrix . Then is obtained as the orthogonal projection of onto . The image of the projection is rational, lies in , but need not be positive semidefinite. We may ensure that if the numerical matrix is in the interior of and sufficiently close to . More precisely, assume that , the smallest eigenvalue of , is greater than the distance . Then setting the rounding tolerance smaller than guarantees that ; see [8, Prop. 8].
Acknowledgment
The authors would like to thank Bernd Sturmfels and the Max-Planck-Institute für Mathematik in den Naturwissenschaften in Leipzig for hosting the Macaulay2 workshop in May 2018. We thank Ilir Dema, Nidhi Kainsa and Anton Leykin, who contributed to the code. The package code contains parts of a proof-of-concept implementation of the methods in [8], originally written by Pablo Parrilo and Helfried Peyrl. Parts of this work were done while Diego Cifuentes visited the Max-Planck-Institute MiS, and while the first two authors visited ICERM supported by NSF grant No. DMS-1439786. Thomas Kahle is supported by the German Research Foundation under grant 314838170, GRK 2297 MathCoRe. Pablo Parrilo is supported in part by the National Science Foundation through NSF Grant CCF-1565235.
The reference list from the paper itself. Each links out to its DOI / PubMed record.
- 1[1] MOSEK Ap S, Mosek command line tools , https://docs.mosek.com/8.1/cmdtools.pdf , 2017.
- 2[2] Grigoriy Blekherman, Pablo A Parrilo, and Rekha R Thomas, Semidefinite optimization and convex algebraic geometry , SIAM, 2012.
- 3[3] Brian Borchers, CSDP, a C library for semidefinite programming , Optimization methods and Software 11 (1999), no. 1-4, 613–623.
- 4[4] Diego Cifuentes, Thomas Kahle, Pablo A. Parrilo, and Helfried Peyrl, Semidefinite Programming , A Macaulay 2 package available at https://github.com/Macaulay 2/M 2/tree/master/M 2/Macaulay 2/packages .
- 5[5] Etienne de Klerk and Dmitrii V Pasechnik, Products of positive forms, linear matrix inequalities, and Hilbert 17th problem for ternary forms , European Journal of Operational Research 157 (2004), no. 1, 39–45.
- 6[6] Daniel R. Grayson and Michael E. Stillman, Macaulay 2, a software system for research in algebraic geometry , Available at http://www 2.macaulay 2.com/Macaulay 2/ .
- 7[7] Pablo A Parrilo, Exploiting algebraic structure in sum of squares programs , Positive polynomials in control, Springer, 2005, pp. 181–194.
- 8[8] Helfried Peyrl and Pablo A Parrilo, Computing sum of squares decompositions with rational coefficients , Theoretical Computer Science 409 (2008), no. 2, 269–281.
