JuliaSymbolics / Symbolics.jl

Symbolic programming for the next generation of numerical software
https://symbolics.juliasymbolics.org/stable/
Other
1.33k stars 147 forks source link

Symbolic functions from `Symbolics.variable` with multiple arguments are not Number-like #1184

Open KPCCoiL opened 2 weeks ago

KPCCoiL commented 2 weeks ago

Symbolic functions created with @variables accept multiple arguments and can be manipulated normally:

julia> @variables x f(..)

2-element Vector{Any}:
 x
  f⋆

julia>

julia> 2f(x)
2f(x)

julia> 2f(x, x)
2f(x, x)

On the other hand, ones created with Symbolics.variable fed more than one argument cannot be multiplied by a number:

julia> @variables x
1-element Vector{Num}:
 x

julia> f = Symbolics.variable(:f, T=Symbolics.FnType)
f⋆

julia> 2f(x)
2f(x)

julia> 2f(x, x)
ERROR: ArgumentError: The function * cannot be applied to f(x, x) which is not a Number-like object.Define `islike(::Num, ::Type{Number}) = true` to enable this.
Stacktrace:
 [1] assert_like(::Function, ::Type, ::Num)
   @ SymbolicUtils ~/.julia/packages/SymbolicUtils/dtCid/src/methods.jl:43
 [2] assert_like
   @ ~/.julia/packages/SymbolicUtils/dtCid/src/methods.jl:45 [inlined]
 [3] *(a::Int64, b::Num)
   @ Symbolics ~/.julia/packages/SymbolicUtils/dtCid/src/methods.jl:74
 [4] top-level scope
   @ REPL[5]:1

Not totally sure if this is a bug, but confusing at least.

ChrisRackauckas commented 2 weeks ago

It's missing its eltype:

yy = Symbolics.variable(:y, T = Symbolics.FnType{Tuple, Real})

That error is a bit confusing in how it's reported.