MultivariatePolynomials.jl icon indicating copy to clipboard operation
MultivariatePolynomials.jl copied to clipboard

Type instability SymPy Sym

Open fgerick opened this issue 4 years ago • 3 comments

Hi, I encountered the following problem:

using TypedPolynomials, SymPy
@polyvar x
@syms a
differentiate(a*x^0-a,x)

gives a

ERROR: MethodError: no method matching zero(::Type{Any})
Closest candidates are:
  zero(::Type{Union{Missing, T}}) where T at missing.jl:105
  zero(::Type{Missing}) at missing.jl:103
  zero(::Type{LibGit2.GitHash}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/LibGit2/src/oid.jl:220
  ...
Stacktrace:
 [1] zero(::Type{Any}) at ./missing.jl:105
 [2] reduce_empty(::typeof(+), ::Type{T} where T) at ./reduce.jl:306
 [3] reduce_empty(::typeof(Base.add_sum), ::Type{T} where T) at ./reduce.jl:313
 [4] mapreduce_empty(::typeof(identity), ::Function, ::Type{T} where T) at ./reduce.jl:335
 [5] _mapreduce(::typeof(identity), ::typeof(Base.add_sum), ::IndexLinear, ::Array{Any,1}) at ./reduce.jl:392
 [6] _mapreduce_dim at ./reducedim.jl:312 [inlined]
 [7] #mapreduce#580 at ./reducedim.jl:307 [inlined]
 [8] mapreduce at ./reducedim.jl:307 [inlined]
 [9] _sum at ./reducedim.jl:657 [inlined]
 [10] _sum at ./reducedim.jl:656 [inlined]
 [11] #sum#583 at ./reducedim.jl:652 [inlined]
 [12] sum at ./reducedim.jl:652 [inlined]
 [13] polynomial!(::Array{Any,1}, ::MultivariatePolynomials.SortedState) at /Users/gerickf/.julia/packages/MultivariatePolynomials/fixWm/src/polynomial.jl:64
 [14] differentiate(::Polynomial{Sym,Term{Sym,Monomial{(x,),1}},Array{Term{Sym,Monomial{(x,),1}},1}}, ::Variable{:x}) at /Users/gerickf/.julia/packages/MultivariatePolynomials/fixWm/src/differentiation.jl:40
 [15] top-level scope at REPL[8]:1

I'm using julia v1.4.0 with the masters of TypedPolynomials.jl and MultivariatePolynomials.jl.

fgerick avatar May 29 '20 07:05 fgerick

I can reproduce it. The issue is that the polynomial has no terms, (you can check it with iszero or nterms, it's cheap) so it has troubles inferring the type of the differentiation of a term.

blegat avatar May 29 '20 10:05 blegat

I assumed that it must be due to no terms in the polynomial. It came a bit of a surprise, because typeof(a*x^0-a) gives Polynomial{Sym,Term{Sym,Monomial{(x,),1}},Array{Term{Sym,Monomial{(x,),1}},1}}, a very clearly defined type!

fgerick avatar May 30 '20 06:05 fgerick

is there anything that keeps #144 from being merged?

fgerick avatar Sep 22 '20 14:09 fgerick