Status: Accepted
Owner: ----
Labels: Type-Defect Priority-Medium Core

New issue 2822 by ronan.l...@gmail.com: Move preorder_traversal to the core
http://code.google.com/p/sympy/issues/detail?id=2822

There are several methods in Basic that walk the full expression tree of the object to output some information. Instead of reimplementing this tree traversal in each method, they should use preorder_traversal(). For that, preorder_traversal needs to be moved to sympy.core.basic.

I've started doing this in https://github.com/rlamy/sympy/tree/refactor-has
This turns effectively Basic.atoms(), Basic.find() and Basic.count() into one-liners (modulo pre- and postprocessing complicatedness), so they could be deprecated and their use replaced with direct calls to preorder_traversal(). However, in that case, it would be used a lot and the name "preorder_traversal" would seem too long and too technical, so we could maybe add a method Basic.iterall() implemented thus:

def iterall(self):
    return preorder_traversal(self)

With this, "expr.count(Integer)" becomes "sum(isinstance(subexpr, Integer) for subexpr in expr.iterall())", and "x in expr.atoms()" becomes "x in expr.iterall()".

--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
To post to this group, send email to sympy-issues@googlegroups.com.
To unsubscribe from this group, send email to 
sympy-issues+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy-issues?hl=en.

Reply via email to