On Jul 1, 2012, at 1:20 AM, "Ondřej Čertík" <[email protected]> wrote:
> On Sat, Jun 30, 2012 at 7:48 PM, Aaron Meurer <[email protected]> wrote: >> On Jun 30, 2012, at 8:38 PM, "[email protected]" >> <[email protected]> wrote: >> >>> Two reasons basically: >>> >>> - the original lambdify has a very convoluted logic and seems hard to >>> maintain (the new one is not that great either, however it does not >>> break as easily) (in the commit history one can see how stuff >>> completely unrelated to the functionality of lambdify was bolted on >>> it) >>> >>> - there were serious differences between what the docstring says and >>> what lambdify does in many corner cases >>> >>> I have discussed a lot why I dislike the original lambdify back in >>> November when I was writing the plotting module. I can bring these >>> discussions back if there is interest. I have also documented this in >>> details at the beginning of the source file for the new lambdify. It >>> would be nice to merge them together, but there is too much cruft in >>> the old lambdify so this will be difficult (even useless, I would >>> prefer simply removing both lambdify functions and relying on good >>> code in sympy for performance, not on some strange combination of >>> libraries and eval(str) operations) >> >> +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 see. So basically one has to convert the SymPy expression into a literal Python code closure in order to be efficient. The only other way I know how to do this is to use the ast module. That should be more robust than string processing, but probably a little harder to do. The code converting SymPy -> ast could probably be useful for other things as well, though. Aaron Meurer > > ------------------ > > 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. > > Ondrej > > -- > 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. > -- 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.
