Symbolic .+ fails when substitute with fold=true

When substituteing a symbolic equation, I get .+ throwing an error when used on its own with fold=true.
Example below: All equations work apart from a1b, which fails with

MethodError: no method matching +(::Vector{Float64}, ::Float64)
For element-wise addition, use broadcasting with dot syntax: array .+ scalar
The function `+` exists, but no method is defined for this combination of argument types.

And oddly, f3 which also contains .+ but preceded with a .* does work!

If this is intended behaviour, could somebody explain the rationale for me?

a0 = [1., 2.25, 3.]
b0 = 1.

@variables a b  

f1 = 2a .+ b
f2 = 2a .* b
f3 = 2a .* b .+ a

a1b = substitute( f1, Dict([a=>a0, b=>b0]); fold=true)  
# >>> this fails

a1a = substitute( f1, Dict([a=>a0, b=>b0]); fold=false)  
# this works# 1 + 2[1.0, 2.25, 3.0]	

a2a = substitute( f2, Dict([a=>a0, b=>b0]); fold=false)  
# this works   # [2.0, 4.5, 6.0][Base.OneTo(3)]

a2b = substitute( f2, Dict([a=>a0, b=>b0]); fold=true)   
# this works   # [2.0, 4.5, 6.0][Base.OneTo(3)]

a3a = substitute( f3, Dict([a=>a0, b=>b0]); fold=false)  
# this works  # [1.0, 2.25, 3.0] + 2[1.0, 2.25, 3.0]*1

a3b = substitute( f3, Dict([a=>a0, b=>b0]); fold=true)   
# this works   # [3.0, 6.75, 9.0][Base.OneTo(3)]
		
1 Like

Open an issue

1 Like

issue opened: .+ operator fails when substitute() with fold=true · Issue #1433 · JuliaSymbolics/Symbolics.jl · GitHub