Why do you even want to use sympy for this? can’t you just do:
f(x) = [[a b];[c d]]
Why not just do that if that’s the function you want. With my symbolic package Reduce.jl, there is no such thing as lambdify
because it works directly on Julia abstract syntax trees. No need to overcomplicate things.
From my perspective, having separate types of symbolic variables and implementing a lambdify function are all superfluous, since one can just work with abstract syntax trees to manipulate and construct the expression one wants to get. So the way I see it the other symbolic packages way overcomplicate things that can be accomplished in a much simpler way using Julia’s language itself.
Since you do not appear to do any symbolic operations, you can just do this:
julia> f(a,b,c,d) = [a b;c d]
f (generic function with 1 method)
julia> f(1,2,3,4)
2×2 Array{Int64,2}:
1 2
3 4
Although, you could also manipulate an expression like that using Reduce
. For example, you could differentiate with respect to variable a
like so:
julia> Expr(:function,:(f(a,b,c,d)),:([a b;c d]))
:(function f(a, b, c, d)
[a b; c d]
end)
julia> df(ans, :a)
:(function f(a, b, c, d)
[1 0; 0 0]
end)
Then to use the function you just created, you can eval
it and use it like any other Julia function. With a Reduce.jl
style symbolic package in Julia, you don’t even need lambdify
or declare @vars
.
Here is another example:
julia> using Reduce;
julia> Expr(:function,:(f(a,b,c,d)),:([a^2 b*x;c*a d]))
:(function f(a, b, c, d)
[a ^ 2 b * x; c * a d]
end)
julia> df(ans,:a)
:(function f(a, b, c, d)
[2a 0; c 0]
end)
julia> eval(ans)
f (generic function with 1 method)
julia> f(1,2,3,4)
2×2 Array{Int64,2}:
2 0
3 0
Just work with julia’s abstract syntax tree, is what I would say.