Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is conversion from number to Polynomial supposed to work? #143

Closed
shashi opened this issue Sep 6, 2023 · 4 comments
Closed

Is conversion from number to Polynomial supposed to work? #143

shashi opened this issue Sep 6, 2023 · 4 comments

Comments

@shashi
Copy link

shashi commented Sep 6, 2023

julia> convert(DynamicPolynomials.Polynomial{true, Integer}, 2)
ERROR: MethodError: no method matching iscomm(::Bool)

Closest candidates are:
  iscomm(::Type{<:DynamicPolynomials.Commutative})
   @ DynamicPolynomials ~/.julia/packages/DynamicPolynomials/W9SrI/src/var.jl:103
  iscomm(::Type{<:DynamicPolynomials.NonCommutative})
   @ DynamicPolynomials ~/.julia/packages/DynamicPolynomials/W9SrI/src/var.jl:112
  iscomm(::Type{DynamicPolynomials.Variable{C}}) where C
   @ DynamicPolynomials ~/.julia/packages/DynamicPolynomials/W9SrI/src/var.jl:146
  ...

Stacktrace:
 [1] MonomialVector{true, Integer}(vars::Vector{DynamicPolynomials.Variable{true, Integer}}, Z::Vector{Vector{Int64}})
   @ DynamicPolynomials ~/.julia/packages/DynamicPolynomials/W9SrI/src/monomial_vector.jl:12
 [2] convert(#unused#::Type{Polynomial{true, Integer, Int64}}, t::MultivariatePolynomials.Term{Int64, Monomial{true, Integer}})
   @ DynamicPolynomials ~/.julia/packages/DynamicPolynomials/W9SrI/src/poly.jl:82
 [3] polynomial!(::MultivariatePolynomials.Term{Int64, Monomial{true, Integer}})
   @ MultivariatePolynomials ~/.julia/packages/MultivariatePolynomials/ckbfK/src/polynomial.jl:84
 [4] polynomial(::MultivariatePolynomials.Term{Int64, Monomial{true, Integer}})
   @ MultivariatePolynomials ~/.julia/packages/MultivariatePolynomials/ckbfK/src/polynomial.jl:53
 [5] convert(#unused#::Type{Polynomial{true, Integer}}, t::MultivariatePolynomials.Term{Int64, Monomial{true, Integer}})
   @ DynamicPolynomials ~/.julia/packages/DynamicPolynomials/W9SrI/src/promote.jl:53
 [6] convert_constant(#unused#::Type{Polynomial{true, Integer}}, α::Int64)
   @ MultivariatePolynomials ~/.julia/packages/MultivariatePolynomials/ckbfK/src/conversion.jl:7
 [7] convert(#unused#::Type{Polynomial{true, Integer}}, α::Int64)
   @ MultivariatePolynomials ~/.julia/packages/MultivariatePolyno

I think this used to work but a recent version has broken it, and broken Symbolics CI. I'm fixing it by making the output Vector{Any} instead of Vector{Polynomial}

@shashi
Copy link
Author

shashi commented Sep 6, 2023

Actually my fix does not work since the next sequence of code expects polynomials.

@shashi
Copy link
Author

shashi commented Sep 6, 2023

I see the type parameters are different now.

    polynoms = Vector{DP.Polynomial{true, commontype}}(undef, length(sympolys))

this is the offending line and there might be other broken things.

It seems the CompatHelper was not watching this
JuliaSymbolics/Symbolics.jl#965

@blegat
Copy link
Member

blegat commented Sep 6, 2023

Yes, I changed the type, you should use polynomial_type(x, Float64) to get the type of polynomials or you can do something like https://github.com/jump-dev/PolyJuMP.jl/blob/master/src/nl_to_polynomial.jl#L4-L8

@shashi
Copy link
Author

shashi commented Sep 8, 2023

thanks!

@shashi shashi closed this as completed Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants