Symbolically evaluating an in-place function

Hi there,

I have an in-place function (RHS of an ODE) and would like to evaluate it with Symbolics.jl. Later on, I want to compute its Jacobian.
However, I cannot figure out how to do that. It appears to not do anything. Certainly, I’m not using the package correctly.

I’ve come up with an MWE

using Symbolics
@variables x[1:2] y[1:2]

function f!(result, arg)
    result[1] = arg[1] + 2
    result[2] = 2 * arg[2] + arg[1]
    nothing
end

f!(collect(y), x)

Executing in the REPL yields

julia> y
y[1:2]

How can I get the symbolic representation of the function?

Nevermind, I figured it out:

using Symbolics
@variables x[1:2] y[1:2]

function f!(result, arg)
    result[1] = arg[1] + 2
    result[2] = 2 * arg[2] + arg[1]
    nothing
end

yy = collect(y)
f!(yy, x)

This gives

julia> yy
2-element Vector{Num}:
     2 + x[1]
 x[1] + 2x[2]

Using similar also works, and is perhaps a bit more clear in terms of intent since you’re not actually using the symbolic y variable

@variables x[1:2]
x = collect(x)
out = similar(x)
f!(out, x)