From 82cb09c5f5df77b69e6f95d3421fa5e4a99ff8b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Thu, 7 Dec 2023 15:51:04 +0100 Subject: [PATCH] Add mindegree, maxdegree, extdegree (#77) * Add mindegree, maxdegree, extdegree * Use in flat --- docs/src/moments.md | 3 +++ src/flat.jl | 2 +- src/measure.jl | 21 +++++++++++++++++++++ test/measure.jl | 3 +++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/src/moments.md b/docs/src/moments.md index cd64a49..32f14a0 100644 --- a/docs/src/moments.md +++ b/docs/src/moments.md @@ -30,6 +30,9 @@ that is, it implements the following two functions ```@docs MultivariatePolynomials.variables(::MultivariateMoments.Measure) MultivariatePolynomials.monomials(::MultivariateMoments.Measure) +MultivariatePolynomials.maxdegree(::MultivariateMoments.Measure) +MultivariatePolynomials.mindegree(::MultivariateMoments.Measure) +MultivariatePolynomials.extdegree(::MultivariateMoments.Measure) moments ``` diff --git a/src/flat.jl b/src/flat.jl index 544e7ef..9d8f3ed 100644 --- a/src/flat.jl +++ b/src/flat.jl @@ -79,7 +79,7 @@ function compute_support!( solver::FlatExtension, ) where {T} μ = measure(ν) - d = MP.maxdegree(μ.x) + d = MP.maxdegree(μ) v = MP.variables(μ) d0 = div(d - 1, 2) d1 = d - 1 - d0 diff --git a/src/measure.jl b/src/measure.jl index b92b395..3089d9b 100644 --- a/src/measure.jl +++ b/src/measure.jl @@ -65,6 +65,27 @@ Returns an iterator over the monomials of `μ` sorted in the decreasing order. """ MP.monomials(μ::Measure) = μ.x +""" + maxdegree(μ::AbstractMeasureLike) + +Returns the maximal degree of the monomials of `μ`. +""" +MP.maxdegree(μ::Measure) = MP.maxdegree(MP.monomials(μ)) + +""" + mindegree(μ::AbstractMeasureLike) + +Returns the minimal degree of the monomials of `μ`. +""" +MP.mindegree(μ::Measure) = MP.mindegree(MP.monomials(μ)) + +""" + extdegree(μ::AbstractMeasureLike) + +Returns the extremal degrees of the monomials of `μ`. +""" +MP.extdegree(μ::Measure) = MP.extdegree(MP.monomials(μ)) + """ moments(μ::AbstractMeasureLike) diff --git a/test/measure.jl b/test/measure.jl index 91fe289..03ee58c 100644 --- a/test/measure.jl +++ b/test/measure.jl @@ -3,6 +3,9 @@ @test_throws ArgumentError measure([1, 2], [x, x * y, y]) @test_throws ArgumentError measure([1, 2, 3, 4], [x, x * y, y]) μ = measure([1, 0, 2, 3], [x^2 * y^2, y * x^2, x * y * x^2, x * y^2]) + @test MP.mindegree(μ) == 3 + @test MP.maxdegree(μ) == 4 + @test MP.extdegree(μ) == (3, 4) @test monomials(μ) == monomial_vector([x^3 * y, x^2 * y^2, x^2 * y, x * y^2]) @test monomial.(moments(μ)) ==