JuliaAlgebra / StaticPolynomials.jl

Fast evaluation of multivariate polynomials
https://juliaalgebra.github.io/StaticPolynomials.jl/latest/
Other
16 stars 4 forks source link

conversion issue with TypedPolynomials.Polynomial #47

Open hofmannmartin opened 2 years ago

hofmannmartin commented 2 years ago

Great package. I am currently using the TypedPolynomials package for the construction of polynomials, as it is the most performant in my use case. However, a straight froward conversion to a StaticPolynomials.Polynomial fails.

using TypedPolynomials
import StaticPolynomials

@polyvar x y z
p = 3*z^2 + 2*y*x
ps = StaticPolynomials.Polynomial(p)

yields

MethodError: no method matching StaticPolynomials.Polynomial(::Vector{Float64}, ::Matrix{Int64}, ::Tuple{Symbol, Symbol, Symbol}, ::Nothing, ::Nothing)

Closest candidates are:
StaticPolynomials.Polynomial(::Vector, ::Matrix{<:Integer}, !Matched::Vector{Symbol}, ::Union{Nothing, Matrix{<:Integer}}, ::Any) at ~/.julia/packages/StaticPolynomials/TgQjK/src/polynomial.jl:63
StaticPolynomials.Polynomial(::Vector{T}, !Matched::StaticPolynomials.SExponents, ::Any, ::Union{Nothing, StaticPolynomials.SExponents}, ::Any, !Matched::Vector{Int64}) where T at ~/.julia/packages/StaticPolynomials/TgQjK/src/polynomial.jl:26
StaticPolynomials.Polynomial(::Vector, ::Matrix{<:Integer}, !Matched::Vector{Symbol}, ::Union{Nothing, Matrix{<:Integer}}) at ~/.julia/packages/StaticPolynomials/TgQjK/src/polynomial.jl:63

The issue seems to be that the Polynomial constructor expects Vector{Symbol} as third argument, but MultivariatePolynomials.variables returns a tuple in this case. That said I found the following workaround:

using TypedPolynomials, MultivariatePolynomials
import StaticPolynomials

@polyvar x y z
p = 3*z^2 + 2*y*x
ps = StaticPolynomials.Polynomial(p, Variable[variables(p)...], nothing)

What could be a permanent solution, which does not require this workaround?