JuliaSymbolics / SymbolicUtils.jl

Symbolic expressions, rewriting and simplification
https://docs.sciml.ai/SymbolicUtils/stable/
Other
541 stars 108 forks source link

Certain expression manipulation can lead to errors #424

Closed augustinas1 closed 2 years ago

augustinas1 commented 2 years ago
@variables a b
expr = substitute(a*b, (b => 0))
expand(expr)
ERROR: MethodError: no method matching +()
Closest candidates are:
  +(::T, ::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8} at int.jl:87
  +(::Union{UInt16, UInt32, UInt64, UInt8}, ::BigInt) at gmp.jl:528
  +(::Union{Int16, Int32, Int64, Int8}, ::BigInt) at gmp.jl:534
  ...
Stacktrace:
 [1] #similarterm#2
   @ ~/.julia/packages/TermInterface/hZ5oG/src/TermInterface.jl:130 [inlined]
 [2] #similarterm#1
   @ ~/.julia/packages/TermInterface/hZ5oG/src/TermInterface.jl:125 [inlined]
 [3] simterm
   @ ~/.julia/packages/SymbolicUtils/shh4H/src/polyform.jl:235 [inlined]
 [4] (::Metatheory.Rewriters.Walk{:post, typeof(identity), SymbolicUtils.var"#simterm#108"{SymbolicUtils.var"#simterm#107#109"}, false})(x::PolyForm{Real, Nothing})
   @ Metatheory.Rewriters ~/.julia/packages/Metatheory/XcKKW/src/Rewriters.jl:198
 [5] unpolyize(x::PolyForm{Real, Nothing})
   @ SymbolicUtils ~/.julia/packages/SymbolicUtils/shh4H/src/polyform.jl:236
 [6] expand(expr::SymbolicUtils.Mul{Real, Int64, Dict{Any, Number}, Nothing})
   @ SymbolicUtils ~/.julia/packages/SymbolicUtils/shh4H/src/polyform.jl:232
 [7] expand(n::Num)
   @ Symbolics ~/.julia/packages/Symbolics/HDE84/src/Symbolics.jl:138
 [8] top-level scope
   @ REPL[60]:1

The error can be avoided by using simplify in this case but still seems to be a bug?