Skip to content

Better compatibility with packages such as ApproxFun.jl and Polynomials.jl #127

Open
@benjione

Description

@benjione

If DynamicPolynomials library is used together with e.g. ApproxFun, there is an error if the package IntervalSets is used and the following is executed with v being of type PolyVar:

_in(v, I::TypedEndpointsInterval{:closed,:closed}) = leftendpoint(I) ≤ v ≤ rightendpoint(I)
_in(v, I::TypedEndpointsInterval{:open,:open}) = leftendpoint(I) < v < rightendpoint(I)
_in(v, I::TypedEndpointsInterval{:closed,:open}) = leftendpoint(I) ≤ v < rightendpoint(I)
_in(v, I::TypedEndpointsInterval{:open,:closed}) = leftendpoint(I) < v ≤ rightendpoint(I)

The error is because Base.isless is not defined for PolyVar
Code example producing the error:

using SumOfSquares
using DynamicPolynomials
using DynamicPolynomials: PolyVar
using ApproxFun
using SCS
using IntervalSets

## use it for something:
@polyvar x

model = SOSModel(SCS.Optimizer)
@variable(model, a[1:10])
p = Fun(Chebyshev(), a)
p(x)  # this throws for example the error

One can manually overwrite those functions for the desired type, e.g.

using DynamicPolynomials: PolyVar
using IntervalSets

## define these functions as a trick:
IntervalSets.in(v::PolyVar, I::IntervalSets.TypedEndpointsInterval{:closed,:closed}) = true
IntervalSets.in(v::PolyVar, I::IntervalSets.TypedEndpointsInterval{:open,:open}) = true
IntervalSets.in(v::PolyVar, I::IntervalSets.TypedEndpointsInterval{:closed,:open}) = true
IntervalSets.in(v::PolyVar, I::IntervalSets.TypedEndpointsInterval{:open,:closed}) = true

Is it possible to overwrite the IntervalSets.in in order to get better compatibility between the polynomial packages?
Or has this to be done in MultivariatePolynomials.jl instead of here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions