From 919ded681c1ed6a11dc3b7893a28133dceaceaaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Wed, 1 Dec 2021 08:06:53 -0500 Subject: [PATCH] Certificate API: get -> function (#229) * Certificate API: get -> function * Update certificate example --- docs/src/tutorials/Extension/certificate.jl | 18 ++--- src/Bridges/Constraint/sos_polynomial.jl | 9 ++- .../sos_polynomial_in_semialgebraic_set.jl | 14 ++-- src/Certificate/Certificate.jl | 68 +++++++++---------- src/Certificate/Sparsity/ideal.jl | 16 ++--- src/Certificate/Sparsity/monomial.jl | 10 +-- src/Certificate/Sparsity/preorder.jl | 24 +++---- src/Certificate/Symmetry/block_diag.jl | 2 +- src/Certificate/Symmetry/wedderburn.jl | 12 ++-- src/Certificate/newton_polytope.jl | 2 +- src/constraint.jl | 2 +- test/certificate.jl | 22 +++--- 12 files changed, 97 insertions(+), 102 deletions(-) diff --git a/docs/src/tutorials/Extension/certificate.jl b/docs/src/tutorials/Extension/certificate.jl index 5299b1ecc..bb576f49e 100644 --- a/docs/src/tutorials/Extension/certificate.jl +++ b/docs/src/tutorials/Extension/certificate.jl @@ -51,13 +51,13 @@ struct Schmüdgen{IC <: SOSC.AbstractIdealCertificate, CT <: SOS.SOSLikeCone, BT maxdegree::Int end -SOSC.get(certificate::Schmüdgen, ::SOSC.Cone) = certificate.cone +SOSC.cone(certificate::Schmüdgen) = certificate.cone -function SOSC.get(::Schmüdgen, ::SOSC.PreprocessedDomain, domain::BasicSemialgebraicSet, p) +function SOSC.preprocessed_domain(::Schmüdgen, domain::BasicSemialgebraicSet, p) return SOSC.DomainWithVariables(domain, variables(p)) end -function SOSC.get(::Schmüdgen, ::SOSC.PreorderIndices, domain::SOSC.DomainWithVariables) +function SOSC.preorder_indices(::Schmüdgen, domain::SOSC.DomainWithVariables) n = length(domain.domain.p) if n >= Sys.WORD_SIZE error("There are $(2^n - 1) products in Schmüdgen's certificate, they cannot even be indexed with `$Int`.") @@ -65,23 +65,23 @@ function SOSC.get(::Schmüdgen, ::SOSC.PreorderIndices, domain::SOSC.DomainWithV return map(SOSC.PreorderIndex, 1:(2^n-1)) end -function SOSC.get(certificate::Schmüdgen, ::SOSC.MultiplierBasis, index::SOSC.PreorderIndex, domain::SOSC.DomainWithVariables) - q = SOSC.get(certificate, SOSC.Generator(), index, domain) +function SOSC.multiplier_basis(certificate::Schmüdgen, index::SOSC.PreorderIndex, domain::SOSC.DomainWithVariables) + q = SOSC.generator(certificate, index, domain) vars = sort!([domain.variables..., variables(q)...], rev = true) unique!(vars) return SOSC.maxdegree_gram_basis(certificate.basis, vars, SOSC.multiplier_maxdegree(certificate.maxdegree, q)) end -function SOSC.get(::Type{Schmüdgen{IC, CT, BT}}, ::SOSC.MultiplierBasisType) where {IC, CT, BT} +function SOSC.multiplier_basis_type(::Type{Schmüdgen{IC, CT, BT}}) where {IC, CT, BT} return BT end -function SOSC.get(::Schmüdgen, ::SOSC.Generator, index::SOSC.PreorderIndex, domain::SOSC.DomainWithVariables) +function SOSC.generator(::Schmüdgen, index::SOSC.PreorderIndex, domain::SOSC.DomainWithVariables) I = [i for i in eachindex(domain.domain.p) if !iszero(index.value & (1 << (i - 1)))] return prod([domain.domain.p[i] for i in eachindex(domain.domain.p) if !iszero(index.value & (1 << (i - 1)))]) end -SOSC.get(certificate::Schmüdgen, ::SOSC.IdealCertificate) = certificate.ideal_certificate -SOSC.get(::Type{<:Schmüdgen{IC}}, ::SOSC.IdealCertificate) where {IC} = IC +SOSC.ideal_certificate(certificate::Schmüdgen) = certificate.ideal_certificate +SOSC.ideal_certificate(::Type{<:Schmüdgen{IC}}) where {IC} = IC SOS.matrix_cone_type(::Type{<:Schmüdgen{IC, CT}}) where {IC, CT} = SOS.matrix_cone_type(CT) diff --git a/src/Bridges/Constraint/sos_polynomial.jl b/src/Bridges/Constraint/sos_polynomial.jl index f88b96a84..2f256826f 100644 --- a/src/Bridges/Constraint/sos_polynomial.jl +++ b/src/Bridges/Constraint/sos_polynomial.jl @@ -39,8 +39,8 @@ function MOI.Bridges.Constraint.bridge_constraint( # `Float64` when used with JuMP and the coefficient type is often `Int` if # `set.domain.V` is `FullSpace` or `FixedPolynomialsSet`. # FIXME convert needed because the coefficient type of `r` is `Any` otherwise if `domain` is `AlgebraicSet` - r = SOS.Certificate.get(s.certificate, SOS.Certificate.ReducedPolynomial(), p, MP.changecoefficienttype(s.domain, T)) - gram_basis = SOS.Certificate.get(s.certificate, SOS.Certificate.GramBasis(), r) + r = SOS.Certificate.reduced_polynomial(s.certificate, p, MP.changecoefficienttype(s.domain, T)) + gram_basis = SOS.Certificate.gram_basis(s.certificate, r) g, Q, cQ = SOS.add_gram_matrix(model, MCT, gram_basis, T) # MOI does not modify the coefficients of the functions so we can modify `r`. # without altering `f`. @@ -73,7 +73,7 @@ function MOIB.Constraint.concrete_bridge_type( MCT = SOS.matrix_cone_type(CT) UMCT = union_constraint_types(MCT) UMST = union_set_types(MCT) - GB = SOS.Certificate.get(CT, SOS.Certificate.GramBasisType()) + GB = SOS.Certificate.gram_basis_type(CT) ZB = SOS.Certificate.zero_basis_type(CT) return SOSPolynomialBridge{T, G, DT, UMCT, UMST, MCT, GB, ZB, CT, MT, MVT} end @@ -150,8 +150,7 @@ function MOI.get(model::MOI.ModelLike, attr::MOI.ConstraintDual, function reduced(mono) p = MP.polynomial(mono, T) domain = MP.changecoefficienttype(bridge.domain, T) - return SOS.Certificate.get( - bridge.certificate, SOS.Certificate.ReducedPolynomial(), p, domain) + return SOS.Certificate.reduced_polynomial(bridge.certificate, p, domain) end return [dot(reduced(mono), μ) for mono in bridge.monomials] end diff --git a/src/Bridges/Constraint/sos_polynomial_in_semialgebraic_set.jl b/src/Bridges/Constraint/sos_polynomial_in_semialgebraic_set.jl index 8c0af7145..e498cd366 100644 --- a/src/Bridges/Constraint/sos_polynomial_in_semialgebraic_set.jl +++ b/src/Bridges/Constraint/sos_polynomial_in_semialgebraic_set.jl @@ -1,5 +1,5 @@ function lagrangian_multiplier(model::MOI.ModelLike, certificate, index, preprocessed, T::Type) - basis = Certificate.get(certificate, Certificate.MultiplierBasis(), index, preprocessed) + basis = Certificate.multiplier_basis(certificate, index, preprocessed) MCT = SOS.matrix_cone_type(typeof(certificate)) return SOS.add_gram_matrix(model, MCT, basis, T)..., basis end @@ -33,8 +33,8 @@ function MOI.Bridges.Constraint.bridge_constraint( λ_bases = B[] λ_variables = Union{Vector{MOI.VariableIndex}, Vector{Vector{MOI.VariableIndex}}}[] λ_constraints = UMCT[] - preprocessed = Certificate.get(set.certificate, Certificate.PreprocessedDomain(), set.domain, p) - for index in Certificate.get(set.certificate, Certificate.PreorderIndices(), preprocessed) + preprocessed = Certificate.preprocessed_domain(set.certificate, set.domain, p) + for index in Certificate.preorder_indices(set.certificate, preprocessed) λ, λ_variable, λ_constraint, λ_basis = lagrangian_multiplier( model, set.certificate, index, preprocessed, T) push!(λ_variables, λ_variable) @@ -44,13 +44,13 @@ function MOI.Bridges.Constraint.bridge_constraint( # need to call `changecoefficienttype`. This is critical since `T` is # `Float64` when used with JuMP and the coefficient type is often `Int` if # `set.domain.V` is `FullSpace` or `FixedPolynomialsSet`. - g = Certificate.get(set.certificate, Certificate.Generator(), index, preprocessed) + g = Certificate.generator(set.certificate, index, preprocessed) # TODO replace with `MA.sub_mul` when it works. p = MA.operate!!(MA.add_mul, p, -one(T), λ, MP.changecoefficienttype(g, T)) end new_set = SOS.SOSPolynomialSet( set.domain.V, MP.monomials(p), - Certificate.get(set.certificate, Certificate.IdealCertificate())) + Certificate.ideal_certificate(set.certificate)) constraint = MOI.add_constraint(model, MOIU.vectorize(MP.coefficients(p)), new_set) @@ -79,10 +79,10 @@ function MOIB.Constraint.concrete_bridge_type( # for most use cases G = MOIU.promote_operation(-, T, F, MOI.VectorOfVariables) MCT = SOS.matrix_cone_type(CT) - B = Certificate.get(CT, Certificate.MultiplierBasisType()) + B = Certificate.multiplier_basis_type(CT) UMCT = union_constraint_types(MCT) UMST = union_set_types(MCT) - IC = Certificate.get(CT, Certificate.IdealCertificate()) + IC = Certificate.ideal_certificate(CT) return SOSPolynomialInSemialgebraicSetBridge{T, G, AT, IC, B, UMCT, UMST, MCT, MT, MVT} end diff --git a/src/Certificate/Certificate.jl b/src/Certificate/Certificate.jl index 0d679f071..f4066ffab 100644 --- a/src/Certificate/Certificate.jl +++ b/src/Certificate/Certificate.jl @@ -31,23 +31,19 @@ const Index = Union{PreorderIndex, IdealIndex} abstract type Attribute end # For get -struct Cone <: Attribute end -struct GramBasis <: Attribute end +function cone end +function gram_basis end # FIXME currently, this returns `MB.MonomialBasis` instead of `MB.MonomialBasis{MT, MVT}` -struct GramBasisType <: Attribute end -struct ReducedPolynomial <: Attribute end -struct IdealCertificate <: Attribute end -struct PreprocessedDomain <: Attribute end +function gram_basis_type end +function reduced_polynomial end +function ideal_certificate end +function preprocessed_domain end # Only for PreorderIndex -struct PreorderIndices <: Attribute end -struct Generator <: Attribute end -struct MultiplierBasis <: Attribute end -struct MultiplierBasisType <: Attribute end - -# For set -#struct Monomials <: Attribute end - +function preorder_indices end +function generator end +function multiplier_basis end +function multiplier_basis_type end # PreorderCertificate # IdealCertificate @@ -80,17 +76,17 @@ struct Putinar{IC <: AbstractIdealCertificate, CT <: SumOfSquares.SOSLikeCone, B maxdegree::Int end -get(certificate::Putinar, ::Cone) = certificate.cone +cone(certificate::Putinar) = certificate.cone struct DomainWithVariables{S, V} domain::S variables::V end -function get(::Putinar, ::PreprocessedDomain, domain::BasicSemialgebraicSet, p) +function preprocessed_domain(::Putinar, domain::BasicSemialgebraicSet, p) return DomainWithVariables(domain, MP.variables(p)) end -function get(::Putinar, ::PreorderIndices, domain::DomainWithVariables) +function preorder_indices(::Putinar, domain::DomainWithVariables) return map(PreorderIndex, eachindex(domain.domain.p)) end @@ -98,22 +94,22 @@ function maxdegree_gram_basis(B::Type, variables, maxdegree::Int) return MB.maxdegree_basis(B, variables, div(maxdegree, 2)) end multiplier_maxdegree(maxdegree, q) = maxdegree - MP.maxdegree(q) -function get(certificate::Putinar, ::MultiplierBasis, index::PreorderIndex, domain::DomainWithVariables) +function multiplier_basis(certificate::Putinar, index::PreorderIndex, domain::DomainWithVariables) q = domain.domain.p[index.value] vars = sort!([domain.variables..., MP.variables(q)...], rev = true) unique!(vars) return maxdegree_gram_basis(certificate.basis, vars, multiplier_maxdegree(certificate.maxdegree, q)) end -function get(::Type{Putinar{IC, CT, BT}}, ::MultiplierBasisType) where {IC, CT, BT} +function multiplier_basis_type(::Type{Putinar{IC, CT, BT}}) where {IC, CT, BT} return BT end -function get(::Putinar, ::Generator, index::PreorderIndex, domain::DomainWithVariables) +function generator(::Putinar, index::PreorderIndex, domain::DomainWithVariables) return domain.domain.p[index.value] end -get(certificate::Putinar, ::IdealCertificate) = certificate.ideal_certificate -get(::Type{<:Putinar{IC}}, ::IdealCertificate) where {IC} = IC +ideal_certificate(certificate::Putinar) = certificate.ideal_certificate +ideal_certificate(::Type{<:Putinar{IC}}) where {IC} = IC SumOfSquares.matrix_cone_type(::Type{<:Putinar{IC, CT}}) where {IC, CT} = SumOfSquares.matrix_cone_type(CT) @@ -122,9 +118,9 @@ SumOfSquares.matrix_cone_type(::Type{<:Putinar{IC, CT}}) where {IC, CT} = SumOfS ###################### abstract type SimpleIdealCertificate{CT, BT} <: AbstractIdealCertificate end -get(::SimpleIdealCertificate, ::ReducedPolynomial, poly, domain) = poly +reduced_polynomial(::SimpleIdealCertificate, poly, domain) = poly -get(certificate::SimpleIdealCertificate, ::Cone) = certificate.cone +cone(certificate::SimpleIdealCertificate) = certificate.cone SumOfSquares.matrix_cone_type(::Type{<:SimpleIdealCertificate{CT}}) where {CT} = SumOfSquares.matrix_cone_type(CT) # TODO return something else when `PolyJuMP` support other bases. @@ -150,10 +146,10 @@ struct MaxDegree{CT <: SumOfSquares.SOSLikeCone, BT <: MB.AbstractPolynomialBasi basis::Type{BT} maxdegree::Int end -function get(certificate::MaxDegree, ::GramBasis, poly) where CT +function gram_basis(certificate::MaxDegree, poly) where CT return maxdegree_gram_basis(certificate.basis, MP.variables(poly), certificate.maxdegree) end -function get(::Type{MaxDegree{CT, BT}}, ::GramBasisType) where {CT, BT} +function gram_basis_type(::Type{MaxDegree{CT, BT}}) where {CT, BT} return BT end @@ -173,10 +169,10 @@ struct FixedBasis{CT <: SumOfSquares.SOSLikeCone, BT <: MB.AbstractPolynomialBas cone::CT basis::BT end -function get(certificate::FixedBasis, ::GramBasis, poly) where CT +function gram_basis(certificate::FixedBasis, poly) where CT return certificate.basis end -function get(::Type{FixedBasis{CT, BT}}, ::GramBasisType) where {CT, BT} +function gram_basis_type(::Type{FixedBasis{CT, BT}}) where {CT, BT} return BT end @@ -201,10 +197,10 @@ struct Newton{CT <: SumOfSquares.SOSLikeCone, BT <: MB.AbstractPolynomialBasis, basis::Type{BT} variable_groups::NPT end -function get(certificate::Newton{CT, B}, ::GramBasis, poly) where {CT, B} +function gram_basis(certificate::Newton{CT, B}, poly) where {CT, B} return MB.basis_covering_monomials(B, monomials_half_newton_polytope(MP.monomials(poly), certificate.variable_groups)) end -function get(::Type{<:Newton{CT, BT}}, ::GramBasisType) where {CT, BT} +function gram_basis_type(::Type{<:Newton{CT, BT}}) where {CT, BT} return BT end @@ -228,18 +224,18 @@ struct Remainder{GCT<:AbstractIdealCertificate} <: AbstractIdealCertificate gram_certificate::GCT end -function get(::Remainder, ::ReducedPolynomial, poly, domain) +function reduced_polynomial(::Remainder, poly, domain) return convert(typeof(poly), rem(poly, ideal(domain))) end -function get(certificate::Remainder, attr::GramBasis, poly) - return get(certificate.gram_certificate, attr, poly) +function gram_basis(certificate::Remainder, poly) + return gram_basis(certificate.gram_certificate, poly) end -function get(::Type{Remainder{GCT}}, attr::GramBasisType) where GCT - return get(GCT, attr) +function gram_basis_type(::Type{Remainder{GCT}}) where GCT + return gram_basis_type(GCT) end -get(certificate::Remainder, attr::Cone) = get(certificate.gram_certificate, attr) +cone(certificate::Remainder) = cone(certificate.gram_certificate) SumOfSquares.matrix_cone_type(::Type{Remainder{GCT}}) where {GCT} = SumOfSquares.matrix_cone_type(GCT) zero_basis(certificate::Remainder) = zero_basis(certificate.gram_certificate) zero_basis_type(::Type{Remainder{GCT}}) where {GCT} = zero_basis_type(GCT) diff --git a/src/Certificate/Sparsity/ideal.jl b/src/Certificate/Sparsity/ideal.jl index 29aa84302..8e231cbf5 100644 --- a/src/Certificate/Sparsity/ideal.jl +++ b/src/Certificate/Sparsity/ideal.jl @@ -33,19 +33,19 @@ function sparsity(monos, sp::Union{SignSymmetry, Monomial}, gram_basis::MB.Monom return MB.MonomialBasis.(sparsity(monos, sp, gram_basis.monomials)) end function sparsity(poly::MP.AbstractPolynomial, sp::Union{SignSymmetry, Monomial}, certificate::SumOfSquares.Certificate.AbstractIdealCertificate) - return sparsity(MP.monomials(poly), sp, SumOfSquares.Certificate.get(certificate, SumOfSquares.Certificate.GramBasis(), poly)) + return sparsity(MP.monomials(poly), sp, SumOfSquares.Certificate.gram_basis(certificate, poly)) end -function SumOfSquares.Certificate.get(certificate::Ideal, ::SumOfSquares.Certificate.GramBasis, poly) +function SumOfSquares.Certificate.gram_basis(certificate::Ideal, poly) return sparsity(poly, certificate.sparsity, certificate.certificate) end -function SumOfSquares.Certificate.get(::Type{Ideal{S, C}}, attr::SumOfSquares.Certificate.GramBasisType) where {S, C} - return Vector{<:SumOfSquares.Certificate.get(C, attr)} +function SumOfSquares.Certificate.gram_basis_type(::Type{Ideal{S, C}}) where {S, C} + return Vector{<:SumOfSquares.Certificate.gram_basis_type(C)} end -function SumOfSquares.Certificate.get(certificate::Ideal, attr::SumOfSquares.Certificate.ReducedPolynomial, poly, domain) - return SumOfSquares.Certificate.get(certificate.certificate, attr, poly, domain) +function SumOfSquares.Certificate.reduced_polynomial(certificate::Ideal, poly, domain) + return SumOfSquares.Certificate.reduced_polynomial(certificate.certificate, poly, domain) end -function SumOfSquares.Certificate.get(certificate::Ideal, attr::SumOfSquares.Certificate.Cone) - return SumOfSquares.Certificate.get(certificate.certificate, attr) +function SumOfSquares.Certificate.cone(certificate::Ideal) + return SumOfSquares.Certificate.cone(certificate.certificate) end SumOfSquares.matrix_cone_type(::Type{Ideal{S, C}}) where {S, C} = SumOfSquares.matrix_cone_type(C) diff --git a/src/Certificate/Sparsity/monomial.jl b/src/Certificate/Sparsity/monomial.jl index 566bed59e..4bfcb8517 100644 --- a/src/Certificate/Sparsity/monomial.jl +++ b/src/Certificate/Sparsity/monomial.jl @@ -156,13 +156,13 @@ function sparsity(poly::MP.AbstractPolynomial, domain::SemialgebraicSets.BasicSe gram_monos = _gram_monos( reduce((v, q) -> unique!(sort!([v..., MP.variables(q)...], rev=true)), domain.p, init = MP.variables(poly)), - SumOfSquares.Certificate.get(certificate, SumOfSquares.Certificate.IdealCertificate()) + SumOfSquares.Certificate.ideal_certificate(certificate) ) - processed = SumOfSquares.Certificate.get(certificate, SumOfSquares.Certificate.PreprocessedDomain(), domain, poly) + processed = SumOfSquares.Certificate.preprocessed_domain(certificate, domain, poly) multiplier_generator_monos = [ - (_monos(SumOfSquares.Certificate.get(certificate, SumOfSquares.Certificate.MultiplierBasis(), index, processed)), - MP.monomials(SumOfSquares.Certificate.get(certificate, SumOfSquares.Certificate.Generator(), index, processed))) - for index in SumOfSquares.Certificate.get(certificate, SumOfSquares.Certificate.PreorderIndices(), processed) + (_monos(SumOfSquares.Certificate.multiplier_basis(certificate, index, processed)), + MP.monomials(SumOfSquares.Certificate.generator(certificate, index, processed))) + for index in SumOfSquares.Certificate.preorder_indices(certificate, processed) ] cliques, multiplier_cliques = sparsity(MP.monomials(poly), sp, gram_monos, multiplier_generator_monos) return MB.MonomialBasis.(cliques), [MB.MonomialBasis.(clique) for clique in multiplier_cliques] diff --git a/src/Certificate/Sparsity/preorder.jl b/src/Certificate/Sparsity/preorder.jl index 182f79920..4ed24b840 100644 --- a/src/Certificate/Sparsity/preorder.jl +++ b/src/Certificate/Sparsity/preorder.jl @@ -13,7 +13,7 @@ struct Preorder{S <: Pattern, C <: SumOfSquares.Certificate.AbstractPreorderCert certificate::C end -SumOfSquares.Certificate.get(certificate::Preorder, attr::SumOfSquares.Certificate.Cone) = SumOfSquares.Certificate.get(certificate.certificate, attr) +SumOfSquares.Certificate.cone(certificate::Preorder) = SumOfSquares.Certificate.cone(certificate.certificate) struct Domain{S, P, B} domain::S @@ -21,27 +21,27 @@ struct Domain{S, P, B} bases::Vector{Vector{B}} end -function SumOfSquares.Certificate.get(certificate::Preorder, attr::SumOfSquares.Certificate.PreprocessedDomain, domain::SemialgebraicSets.BasicSemialgebraicSet, p) +function SumOfSquares.Certificate.preprocessed_domain(certificate::Preorder, domain::SemialgebraicSets.BasicSemialgebraicSet, p) basis, Preorder_bases = sparsity(p, domain, certificate.sparsity, certificate.certificate) - return Domain(domain, SumOfSquares.Certificate.get(certificate.certificate, attr, domain, p), Preorder_bases) + return Domain(domain, SumOfSquares.Certificate.preprocessed_domain(certificate.certificate, domain, p), Preorder_bases) end -function SumOfSquares.Certificate.get(certificate::Preorder, attr::SumOfSquares.Certificate.PreorderIndices, domain::Domain) - return SumOfSquares.Certificate.get(certificate.certificate, attr, domain.processed) +function SumOfSquares.Certificate.preorder_indices(certificate::Preorder, domain::Domain) + return SumOfSquares.Certificate.preorder_indices(certificate.certificate, domain.processed) end -function SumOfSquares.Certificate.get(::Preorder, ::SumOfSquares.Certificate.MultiplierBasis, index::SumOfSquares.Certificate.PreorderIndex, domain::Domain) +function SumOfSquares.Certificate.multiplier_basis(::Preorder, index::SumOfSquares.Certificate.PreorderIndex, domain::Domain) return domain.bases[index.value] end -function SumOfSquares.Certificate.get(::Type{Preorder{S, C}}, attr::SumOfSquares.Certificate.MultiplierBasisType) where {S, C} - return Vector{SumOfSquares.Certificate.get(C, attr)} +function SumOfSquares.Certificate.multiplier_basis_type(::Type{Preorder{S, C}}) where {S, C} + return Vector{SumOfSquares.Certificate.multiplier_basis_type(C)} end -function SumOfSquares.Certificate.get(certificate::Preorder, attr::SumOfSquares.Certificate.Generator, index::SumOfSquares.Certificate.PreorderIndex, domain::Domain) - return SumOfSquares.Certificate.get(certificate.certificate, attr, index, domain.processed) +function SumOfSquares.Certificate.generator(certificate::Preorder, index::SumOfSquares.Certificate.PreorderIndex, domain::Domain) + return SumOfSquares.Certificate.generator(certificate.certificate, index, domain.processed) end -SumOfSquares.Certificate.get(certificate::Preorder, attr::SumOfSquares.Certificate.IdealCertificate) = Ideal(certificate.sparsity, SumOfSquares.Certificate.get(certificate.certificate, attr)) -SumOfSquares.Certificate.get(::Type{<:Preorder{S, C}}, attr::SumOfSquares.Certificate.IdealCertificate) where {S, C} = Ideal{S, SumOfSquares.Certificate.get(C, attr)} +SumOfSquares.Certificate.ideal_certificate(certificate::Preorder) = Ideal(certificate.sparsity, SumOfSquares.Certificate.ideal_certificate(certificate.certificate)) +SumOfSquares.Certificate.ideal_certificate(::Type{<:Preorder{S, C}}) where {S, C} = Ideal{S, SumOfSquares.Certificate.ideal_certificate(C)} SumOfSquares.matrix_cone_type(::Type{Preorder{S, C}}) where {S, C} = SumOfSquares.matrix_cone_type(C) diff --git a/src/Certificate/Symmetry/block_diag.jl b/src/Certificate/Symmetry/block_diag.jl index 37b36b4e3..9099a2c13 100644 --- a/src/Certificate/Symmetry/block_diag.jl +++ b/src/Certificate/Symmetry/block_diag.jl @@ -57,7 +57,7 @@ function block_diag(As, d) blocks = Dict{Int,Vector{Int}}() for i in 1:n r = DataStructures.find_root!(union_find, i) - blocks[r] = push!(Base.get(blocks, r, Int[]), i) + blocks[r] = push!(get(blocks, r, Int[]), i) end if length(blocks) > 1 U = similar(T) diff --git a/src/Certificate/Symmetry/wedderburn.jl b/src/Certificate/Symmetry/wedderburn.jl index d73474390..fa4533ca0 100644 --- a/src/Certificate/Symmetry/wedderburn.jl +++ b/src/Certificate/Symmetry/wedderburn.jl @@ -71,15 +71,15 @@ struct Ideal{C,GT,AT<:SymbolicWedderburn.Action} <: SumOfSquares.Certificate.Abs pattern::Pattern{GT,AT} certificate::C end -SumOfSquares.Certificate.get(certificate::Ideal, attr::SumOfSquares.Certificate.Cone) = SumOfSquares.Certificate.get(certificate.certificate, attr) +SumOfSquares.Certificate.cone(certificate::Ideal) = SumOfSquares.Certificate.cone(certificate.certificate) function SumOfSquares.matrix_cone_type(::Type{<:Ideal{C}}) where {C} return SumOfSquares.matrix_cone_type(C) end -SumOfSquares.Certificate.get(::Type{<:Ideal}, ::SumOfSquares.Certificate.GramBasisType) = Vector{Vector{MB.FixedPolynomialBasis}} +SumOfSquares.Certificate.gram_basis_type(::Type{<:Ideal}) = Vector{Vector{MB.FixedPolynomialBasis}} SumOfSquares.Certificate.zero_basis_type(::Type{<:Ideal}) = MB.MonomialBasis SumOfSquares.Certificate.zero_basis(::Ideal) = MB.MonomialBasis -function SumOfSquares.Certificate.get(certificate::Ideal, attr::SumOfSquares.Certificate.ReducedPolynomial, poly, domain) - return SumOfSquares.Certificate.get(certificate.certificate, attr, poly, domain) +function SumOfSquares.Certificate.reduced_polynomial(certificate::Ideal, poly, domain) + return SumOfSquares.Certificate.reduced_polynomial(certificate.certificate, poly, domain) end function matrix_reps(cert, R, basis, ::Type{T}, form) where {T} @@ -96,8 +96,8 @@ function matrix_reps(cert, R, basis, ::Type{T}, form) where {T} end end -function SumOfSquares.Certificate.get(cert::Ideal, attr::SumOfSquares.Certificate.GramBasis, poly) - basis = SumOfSquares.Certificate.get(cert.certificate, attr, poly) +function SumOfSquares.Certificate.gram_basis(cert::Ideal, poly) + basis = SumOfSquares.Certificate.gram_basis(cert.certificate, poly) T = SumOfSquares._complex(Float64, SumOfSquares.matrix_cone_type(typeof(cert))) # We set `semisimple=true` as we don't support simple yet since it would not give all the simple components but only one of them. summands = SymbolicWedderburn.symmetry_adapted_basis(T, cert.pattern.group, cert.pattern.action, basis, semisimple=true) diff --git a/src/Certificate/newton_polytope.jl b/src/Certificate/newton_polytope.jl index fd9816405..97ea44943 100644 --- a/src/Certificate/newton_polytope.jl +++ b/src/Certificate/newton_polytope.jl @@ -186,7 +186,7 @@ end function post_filter(monos, X) num = Dict(mono => 1 for mono in X) function _increase(mono) - num[mono] = Base.get(num, mono, 0) + 1 + num[mono] = get(num, mono, 0) + 1 end function _decrease(mono) value = num[mono] - 1 diff --git a/src/constraint.jl b/src/constraint.jl index 0066d826f..61392b94e 100644 --- a/src/constraint.jl +++ b/src/constraint.jl @@ -63,7 +63,7 @@ function JuMP.in_set_string(print_mode, ::DSOSCone) end function JuMP.reshape_set(set::SOSPolynomialSet, ::PolyJuMP.PolynomialShape) - return Certificate.get(set.certificate, Certificate.Cone()) + return Certificate.cone(set.certificate) end function default_ideal_certificate(domain, basis, cone, maxdegree, newton_polytope) diff --git a/test/certificate.jl b/test/certificate.jl index 032daf977..0590223d3 100644 --- a/test/certificate.jl +++ b/test/certificate.jl @@ -62,7 +62,7 @@ end end function _certificate_api(certificate::Certificate.AbstractCertificate) - @test Certificate.get(certificate, Certificate.Cone()) isa SumOfSquares.SOSLikeCone + @test Certificate.cone(certificate) isa SumOfSquares.SOSLikeCone @test SumOfSquares.matrix_cone_type(typeof(certificate)) <: MOI.AbstractVectorSet end function _basis_check_each(basis::MB.AbstractPolynomialBasis, basis_type) @@ -99,9 +99,9 @@ function certificate_api(certificate::Certificate.AbstractIdealCertificate) @polyvar x poly = x + 1 domain = @set x == 1 - @test Certificate.get(certificate, Certificate.ReducedPolynomial(), poly, domain) isa MP.AbstractPolynomial - _basis_check(Certificate.get(certificate, Certificate.GramBasis(), poly), - Certificate.get(typeof(certificate), Certificate.GramBasisType())) + @test Certificate.reduced_polynomial(certificate, poly, domain) isa MP.AbstractPolynomial + _basis_check(Certificate.gram_basis(certificate, poly), + Certificate.gram_basis_type(typeof(certificate))) zbasis = Certificate.zero_basis(certificate) @test zbasis <: MB.AbstractPolynomialBasis @test zbasis == Certificate.zero_basis_type(typeof(certificate)) @@ -112,15 +112,15 @@ function certificate_api(certificate::Certificate.AbstractPreorderCertificate) @polyvar x poly = x + 1 domain = @set x >= 1 - processed = Certificate.get(certificate, Certificate.PreprocessedDomain(), domain, poly) - for idx in Certificate.get(certificate, Certificate.PreorderIndices(), processed) - _basis_check(Certificate.get(certificate, Certificate.MultiplierBasis(), idx, processed), - Certificate.get(typeof(certificate), Certificate.MultiplierBasisType())) - @test Certificate.get(certificate, Certificate.Generator(), idx, processed) isa MP.AbstractPolynomial + processed = Certificate.preprocessed_domain(certificate, domain, poly) + for idx in Certificate.preorder_indices(certificate, processed) + _basis_check(Certificate.multiplier_basis(certificate, idx, processed), + Certificate.multiplier_basis_type(typeof(certificate))) + @test Certificate.generator(certificate, idx, processed) isa MP.AbstractPolynomial end - icert = Certificate.get(certificate, Certificate.IdealCertificate()) + icert = Certificate.ideal_certificate(certificate) @test icert isa Certificate.AbstractIdealCertificate - @test typeof(icert) == Certificate.get(typeof(certificate), Certificate.IdealCertificate()) + @test typeof(icert) == Certificate.ideal_certificate(typeof(certificate)) end