Skip to content

Type instability SymPy Sym #143

@fgerick

Description

@fgerick

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.

Activity

blegat

blegat commented on May 29, 2020

@blegat
Member

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.

self-assigned this
on May 29, 2020
linked a pull request that will close this issue on May 29, 2020
fgerick

fgerick commented on May 30, 2020

@fgerick
Author

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

fgerick commented on Sep 22, 2020

@fgerick
Author

is there anything that keeps #144 from being merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @blegat@fgerick

    Issue actions

      Type instability SymPy Sym · Issue #143 · JuliaAlgebra/MultivariatePolynomials.jl