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:

Hello, what would be a good way to define a Julia function based on the result of symbolic calculations?
For the moment, using lambdify in SymEngine gives a rather slow result, as compared to “brute force” parsing of the SymEngine output:
using SymEngine
@vars x
# Complicated symbolic expression here
symf = x
fl = lambdify(symf, [x])
eval(Meta.parse("fm(x)="*SymEngine.toString(symf)))
This defines two functions fl and fm which evaluate the expression in symf. However, the variant with par…
```
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

fedxa
September 18, 2019, 7:24pm
#3
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