Why does substitute API in Symbolic.jl returns a tuple instead of a number?

using Pkg
Pkg.activate("/Users/ssiew/juliascript/Symbolics")
using Symbolics
# using Nemo
# using SymbolicNumericIntegration

@variables x

expr =  x 
println("expr is ",expr)

answer = substitute.( expr, (Dict(x => 7),) )
println("answer is ",answer)
print(
"""
Why is the answer "(7,)" instead of just "7"
The documentation for substitute does not explain.
"""
)
#

with output:

expr is x
answer is (7,)
Why is the answer “(7,)” instead of just “7”
The documentation for substitute does not explain.

Do you really need broadcast? If not:

julia> using Symbolics

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

julia> expr = x
x

julia> answer = substitute(expr, Dict(x => 7))
7

Yes that makes sense

julia> @variables x y z
3-element Vector{Num}:
 x
 y
 z

julia> expr = x + y + z
x + y + z

julia> answer1 = substitute.( expr, ( Dict(x => 2),Dict(y => 30),Dict(z => 400) )
       )
(2 + y + z, 30 + x + z, 400 + x + y)

julia> answer2 = substitute( expr,Dict(x => 2,y => 30,z => 400) )
432
1 Like