# SymEngine - turn to function

Hey guys!

I have derived a symbolic array as:

``````Bmat
3×8 Array{Basic,2}:
(1/4)*y/(a*b) + (-1/4)*a^(-1)                              0   (-1/4)*y/(a*b) + (1/4)*a^(-1)  …                             0  (-1/4)*y/(a*b) + (-1/4)*a^(-1)                               0
0  (1/4)*x/(a*b) + (-1/4)*b^(-1)                               0     (1/4)*x/(a*b) + (1/4)*b^(-1)                               0   (-1/4)*x/(a*b) + (1/4)*b^(-1)
(1/4)*x/(a*b) + (-1/4)*b^(-1)  (1/4)*y/(a*b) + (-1/4)*a^(-1)  (-1/4)*x/(a*b) + (-1/4)*b^(-1)     (1/4)*y/(a*b) + (1/4)*a^(-1)   (-1/4)*x/(a*b) + (1/4)*b^(-1)  (-1/4)*y/(a*b) + (-1/4)*a^(-1)
``````

How would I turn this into a function of x,y,a,b using the SymEngine.jl package?

Kind regards

I’ve found this temporary solution:

``````Bf = lambdify(Bmat, [x,y,a,b])
``````

But according to the post it might be slow. It works atleast.

Kind regards, if someone else have a better solution I would love to hear

As a followup to the mentioned discussion, you may use the following:

``````lambdify_fast(ex, vars=free_symbols(ex)) = eval(Expr(:function,
Expr(:call, gensym(), map(Symbol,vars)...),
convert(Expr, ex)))
``````

and then

``````Bf = lambdify_fast(Bmat,[x,y,a,b])
``````

This one is a bit faster. It is told that it is prone to the “world time problem”, However I am not sure how really to achieve the problem – so feel free to use the faster version

2 Likes

Thanks! I didn’t understand the problem either, but I got the right result (in this case) Thanks for taking your time to write it out.

Kind regards