Skip to content

.+ operator fails when substitute() with fold=true #1433

@RobbesU

Description

@RobbesU

.+ operator throws an error when substituteing a symbolic equation containing (only?) .+ and 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!
and, as in f4, if specifying the variable as being of length c[1:3] it also works, but folds irrespective of the fold= flag.

Example:

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

@variables a b c[1:3] # `a` fails in .+ when folding
f1 = 2a .+ b
f2 = 2a .* b
f3 = 2a .* b .+ a
f4 = 2c .+ b

a1a = substitute( f1, Dict([a=>a0, b=>b0]); fold=false)  
# this works # 1 + 2[1.0, 2.25, 3.0]	
a1b = substitute( f1, Dict([a=>a0, b=>b0]); fold=true)  
# this fails      
	
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)]
	
a4b = substitute( f4, Dict([c=>a0, b=>b0]); fold=false)   
# this works but folds  # [3.0, 5.5, 7.0][Base.OneTo(3)]
a4b = substitute( f4, Dict([c=>a0, b=>b0]); fold=true)   
# this works   # [3.0, 5.5, 7.0][Base.OneTo(3)]
		

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions