Hello, On Mon, Aug 13, 2012 at 01:19:22AM +0200, Timo Kluck wrote:
One of those methods is variables(), which returns a list of symbols appearing in the expression. It does so by recursively walking down the expression tree. At one point, that was a bottle neck in my algorithm, and I realized that it would be very easy to cache those variables at construction time from the subexpressions.
I think the natural place to implement such a thing would be in GiNaC itself, so that everyone (not only sage users) may benefit.
I don't think it's a good idea. This adds quite a non-negligible overhead to every eval() and expression construction, even if the actual calculation does not need the variables() (symbols(), or whatever it is). Besides I don't think caching really helps. Consider the following code: symbol x, y; ex e = x + y; ex g = x - y; ex e_plus_g = e + g; One would expect e_plus_g.symbols() to return just x, that means symbols() needs to scan the whole e_plus_g expression (to find out that it doesn't contain y), which makes the cache kind of useless. Best regards, Alexei