Cadabra
Computer algebra system for field theory problems

Functionality to clean up expressions so that they satisfy the requirements of a consistent expression tree.
Functions  
void  cadabra::cleanup_dispatch (const Kernel &kernel, Ex &tr, Ex::iterator &it) 
void  cadabra::cleanup_dispatch_deep (const Kernel &k, Ex &tr, dispatcher_t dispatch) 
Central cleanup dispatch routine, which calls the other cleanup functions defined later.
These cleanup routines do NOT use normal cadabra algorithms; they are completely independent of them to prevent circular dependence or infinite recursion.
These algorithms clean up the tree at the current node and the first layer of child nodes, but do NOT descend deeper down the tree, UNLESS that would leave the tree in an inconsistent state. An example is acting at the top node of \prod{4}{\sum{a}{b}}
, which would push the 4 to the multiplier of the sum, but that is not allowed, so it needs to go further down. Sibling nodes of 'it' remain untouched as well.
void cadabra::cleanup_dispatch_deep  (  const Kernel &  k, 
Ex &  ,  
dispatcher_t  disp = &cleanup_dispatch 

) 
More general cleanup of an entire tree. Walks depthfirst along the entire tree and call cleanup_dispatch at every node.