I support the idea of being smarter about running fewer Python functions. Your post brought up a couple experiences I had trying to get unification based rewriterules to run efficiently.
- expand currently works by recursively calling _eval_expand_hint on > an expression. So if you have something like 1 + 2*log(x*y), it calls > (1 + 2*log(x*y))._eval_expand_log(), then > Integer(1)._eval_expand_log(), then (2*log(x*y))._eval_expand_log(), > and finally log(x*y)._eval_expand_log(). But it is only this final > form that actually does anything. This is a lot of recursive function > calls, which can be slow in Python. We should think of ways to reduce > this, while still keeping the API open (and backwards compatible if > possible). > I ran into a problem like this in my rewrite rules code. I ended up filtering small functions like this based on the types present in the expression. This ended up culling large branches of the recursive call tree and was well worth the up-front cost. Unfortunately I'm not very knowledgable about how expand works so I'm not sure how relevant this optimization is here. > - I wonder if it would be possible to do a sort of "structural" > caching. How easy is it to say, "is expression 1 the same as > expression 2, except up to a permutation of the Symbols?" (and > actually give the permutation), and most importantly, determine that > efficiently? How complicated would an expression have to be for it to > be faster to apply a permutation of Symbols against a cached result > instead of just doing things the way we do now? Even if it's slower, I > guess it would be much more efficient memory-wise for the cache. > Commutativity and associativity may present problems here. There are cool algorithms and data structures to do this efficiently but they're challenging to grasp (or at least challenging to me). http://webloria.loria.fr/~moreau/Papers/KirchnerM-JFP2001.pdf -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sympy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
