Even reduction

using DynamicPolynomials
@polyvar x
(x,)

We would like to find the minimum value of the following polynomial:

poly = x^4 - 2x^2

using SumOfSquares

We define the custom action as follows:

struct OnSign <: Symmetry.OnMonomials end
using PermutationGroups
import SymbolicWedderburn
SymbolicWedderburn.coeff_type(::OnSign) = Float64
function SymbolicWedderburn.action(::OnSign, p::Permutation, mono::AbstractMonomial)
    if isone(p) || iseven(DynamicPolynomials.degree(mono))
        return 1 * mono
    else
        @assert p.perm == perm"(1,2)"
        return -1 * mono
    end
end
G = PermGroup([perm"(1,2)"])
Permutation group on 1 generator generated by
 (1,2)

We can exploit the symmetry as follows:

import Clarabel
solver = Clarabel.Optimizer
model = Model(solver)
@variable(model, t)
@objective(model, Max, t)
pattern = Symmetry.Pattern(G, OnSign())
con_ref = @constraint(model, poly - t in SOSCone(), symmetry = pattern)
optimize!(model)
value(t)
-0.9999999977220708

We indeed find -1, let's verify that symmetry was exploited:

gram_matrix(con_ref)
BlockDiagonalGramMatrix with 2 blocks:
[1] Block with row/column basis:
     Simple basis:
  FixedBasis([1.0·1 + 0.0·x + 0.0·x², 0.0·1 + 0.0·x + 1.0·x²])
    And entries in a 2×2 SymMatrix{Float64}:
      0.9999999977220708  -1.000000000898501
     -1.000000000898501    1.0
[2] Block with row/column basis:
     Simple basis:
  FixedBasis([0.0·1 + 1.0·x + 0.0·x²])
    And entries in a 1×1 SymMatrix{Float64}:
     1.7970022023157515e-9

This page was generated using Literate.jl.