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 parsing the output is 20 times faster than lambdify:
@time sum(fl(y) for y in LinRange(0., 1., 10000000))
0.924081 seconds (50.00 M allocations: 762.940 MiB, 3.03% gc time)
@time sum(fm(y) for y in LinRange(0., 1., 10000000))