Hypercube
Given a Sum-of-Squares constraint on an algebraic set:
\[g_1(x) = , \ldots, g_m(x) = 0 \Rightarrow p(x) \ge 0.\]
We can either use the certificate:
\[p(x) = s(x) + \lambda_1(x) g_1(x) + \cdots + \lambda_m(x) g_m(x), s_0(x) \text{ is SOS},\]
or
\[p(x) \equiv s(x) \pmod{\la g_1(x), \ldots, g_m(x) \ra}, s_0(x) \text{ is SOS}.\]
the second one leads to a simpler SDP but needs to compute a Gr\"obner basis:
- SemialgebraicSets implements Buchberger's algorithm.
- The
@setmacro recognizes variable fix, e.g.,x = 1and provides shortcut. - If you know a \alert{better} way to take modulo, better create your \alert{own} type of algebraic set!
We illustrate this in this example.
using DynamicPolynomials
@polyvar x[1:3]
p = sum(x)^2
using SumOfSquares
S = algebraicset([xi^2 - 1 for xi in x])Algebraic Set defined by 3 equalities
-1//1 + x[1]^2 = 0
-1//1 + x[2]^2 = 0
-1//1 + x[3]^2 = 0
We will now search for the minimum of x over S using Sum of Squares Programming. We first need to pick an SDP solver, see here for a list of the available choices.
import CSDP
solver = optimizer_with_attributes(CSDP.Optimizer, MOI.Silent() => true)
function min_algebraic(S)
model = SOSModel(solver)
@variable(model, α)
@objective(model, Max, α)
@constraint(model, c, p >= α, domain = S)
optimize!(model)
@show termination_status(model)
@show objective_value(model)
end
min_algebraic(S)-7.375641208895445e-10Note that the minimum is in fact 1. Indeed, since each variables is odd (it is either -1 or 1) and there is an odd number of variables, their sum is odd. Therefore it cannot be zero!
This constraint uses the equalities truncated at degree two. The Gröbner basis flag therefore remains false after the solve.
SemialgebraicSets.is_gröbner_basis(S.I)falseThe generators already form a Gröbner basis: their leading monomials xi^2 are pairwise coprime so all S-polynomials reduce to zero. SumOfSquares does not compute Gröbner bases implicitly by default as it may be expensive in general but here, it is cheap so we can compute it explicitly:
SemialgebraicSets.compute_gröbner_basis!(S.I)
SemialgebraicSets.is_gröbner_basis(S.I)trueThe constraint now uses the remainders modulo the Gröbner basis instead of the truncation of the equalities:
min_algebraic(S)-4.1458531052640524e-10Since xi^2 = 1, the remainder of a monomial is obtained by reducing each exponent modulo two. Instead of relying on the generic multivariate division of rem for a polynomial ideal, the following custom domain implements this reduction directly. The defining equalities have integer coefficients.
import MutableArithmetics as MA
const MP = MultivariatePolynomials
const SS = SemialgebraicSets
struct HypercubeIdeal{V} <: SS.AbstractPolynomialIdeal
variables::Vector{V}
end
struct HypercubeSet{V} <: SS.AbstractAlgebraicSet
ideal::HypercubeIdeal{V}
end
MP.coefficient_type(::Type{<:Union{HypercubeSet,HypercubeIdeal}}) = Int
MP.variables(set::HypercubeSet) = MP.variables(set.ideal)
MP.variables(ideal::HypercubeIdeal) = ideal.variables
Base.similar(set::HypercubeSet, ::Type) = set
SS.ideal(set::HypercubeSet) = set.ideal
function MA.promote_operation(::typeof(SS.ideal), ::Type{HypercubeSet{V}}) where {V}
return HypercubeIdeal{V}
end
MP.similar_type(S::Type{<:HypercubeSet}, ::Type) = S
function Base.rem(p, set::HypercubeIdeal)
return MP.polynomial(map(MP.terms(p)) do term
mono = MP.monomial(term)
new_mono = one(mono)
for (var, exp) in powers(mono)
if var in set.variables
exp = rem(exp, 2)
end
new_mono *= var^exp
end
MP.coefficient(term) * new_mono
end)
end
H = HypercubeSet(HypercubeIdeal(x))
min_algebraic(H)-4.1458531052640524e-10Let's now try to find the correct lower bound:
function min_algebraic_rational(S, d)
model = SOSModel(solver)
@variable(model, q, SOSPoly(MP.monomials(x, 0:d)))
deno = q + 1
@constraint(model, c, deno * p >= deno, domain = S)
optimize!(model)
@show termination_status(model)
endmin_algebraic_rational (generic function with 1 method)With d = 0, it's the same as previously
min_algebraic_rational(H, 0)INFEASIBLE::TerminationStatusCode = 2But with d = 1, we can find the correct lower bound
min_algebraic_rational(H, 1)OPTIMAL::TerminationStatusCode = 1This page was generated using Literate.jl.