diff --git a/src/Bridges/Variable/kernel.jl b/src/Bridges/Variable/kernel.jl index cf438f7a4..231a83bfb 100644 --- a/src/Bridges/Variable/kernel.jl +++ b/src/Bridges/Variable/kernel.jl @@ -20,7 +20,11 @@ function MOI.Bridges.Variable.bridge_constrained_variable( gram, vars, con = SOS.add_gram_matrix(model, M, gram_basis, T) push!(variables, vars) push!(constraints, con) - MA.operate!(SA.UnsafeAddMul(*), acc, gram, weight) + if isone(weight) + MA.operate!(SA.UnsafeAdd(), acc, SA.QuadraticForm(gram)) + else + MA.operate!(SA.UnsafeAddMul(*), acc, gram, weight) + end end MA.operate!(SA.canonical, SA.coeffs(acc)) return KernelBridge{T,M}( diff --git a/src/Certificate/ideal.jl b/src/Certificate/ideal.jl index 20bc096d3..920358ac4 100644 --- a/src/Certificate/ideal.jl +++ b/src/Certificate/ideal.jl @@ -29,12 +29,20 @@ function _combine_with_gram( ) end for (gram, weight) in zip(gram_bases, weights) - MA.operate!( - SA.UnsafeAddMul(*), - p, - GramMatrix{_NonZero}((_, _) -> _NonZero(), gram), - weight, - ) + if isone(weight) + MA.operate!( + SA.UnsafeAdd(), + p, + SA.QuadraticForm(GramMatrix{_NonZero}((_, _) -> _NonZero(), gram)), + ) + else + MA.operate!( + SA.UnsafeAddMul(*), + p, + GramMatrix{_NonZero}((_, _) -> _NonZero(), gram), + weight, + ) + end end MA.operate!(SA.canonical, SA.coeffs(p)) return MB.SubBasis{B}(keys(SA.coeffs(p)))