Skip to content

Commit

Permalink
Add mindegree, maxdegree, extdegree (#77)
Browse files Browse the repository at this point in the history
* Add mindegree, maxdegree, extdegree

* Use in flat
  • Loading branch information
blegat authored Dec 7, 2023
1 parent aa0f5b0 commit 82cb09c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/src/moments.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
2 changes: 1 addition & 1 deletion src/flat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions src/measure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions test/measure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(μ)) ==
Expand Down

0 comments on commit 82cb09c

Please sign in to comment.