>> +1 to this. Each function should know how to numerically evaluate >> itself using numpy or stdlib math (or whatever), and you should be >> able to just do it directly, like expr.evalf(library=numpy) or >> something like that. I don't see any reason why that wouldn't work. >> eval'ing strings feels like a hack, but actually imo anything that >> works by rebuilding the expression tree in some what or another is >> inefficient because we already have the expression tree. > > The idea is quite simple. In SymPy, sin(x)+cos(x) is equivalent to > Add(sin(x), cos(x)) and so if you need to evaluate it at x=5, you > need to run a couple function calls, recursively, and finally > you just call math.sin or math.cos from the Python's math module. > > Using Python's math module directly, sin(x)+cos(x) is just > two function calls and a "+" on two floats. So it is much faster. > > How can this be done without lambdify()?
I was just hopping that it won't be necessary performancewise. If you want to use numpy, you will work on big arrays, and most of the time will be outside-of-python number crunching, so a few more function calls in total do not seem like a big problem. And you are saving many more function calls by not using lambdify() (this counts if you are evaluating it only once like in plotting). > ------------------ > > Stefan, yes, I read the module introduction, but it was not clear to me at all > what the difference is. The description sounds like a temporary hack. > But from what you are saying, it seems to me it's a better implementation > of lambdify(). I agree with you that the best would be to simply rely on sympy > directly, but I don't know how to do that. > The new lambdify is indeed a bit better, mainly because you do not need to add manually every single class in order for it to work (check the commit that adds Integral to lambdify for instance). However it does not support all the options of the old lambdify, so there is work to be done if we want to merge them. It basically rebuilds the object tree using string manipulations over the "str(expression)" output. It is a hack, like the old lambdify in this regard (the code is documented in details however). For an example that does not work in the old lambdify lambdify(y, Sum(x**y, (x, 1, oo)))(-2) -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
