def canon(*rules): """ Strategy for canonicalization Apply each rule in a bottom_up fashion through the tree. Do each one in turn. Keep doing this until there is no change. """ return exhaust(top_down(exhaust(do_one(*rules))))
def canon(*rules, **kwargs): """ Strategy for canonicalization Apply each rule in a bottom_up fashion through the tree. Do each one in turn. Keep doing this until there is no change. """ return exhaust(top_down(exhaust(do_one(*rules)), **kwargs))
def subs(d): """ Full simultaneous exact substitution Example ======= >>> from sympy.strategies.tools import subs >>> from sympy import Basic >>> mapping = {1: 4, 4: 1, Basic(5): Basic(6, 7)} >>> expr = Basic(1, Basic(2, 3), Basic(4, Basic(5))) >>> subs(mapping)(expr) Basic(4, Basic(2, 3), Basic(1, Basic(6, 7))) """ if d: return top_down(do_one(*map(rl.subs, *zip(*d.items())))) else: return lambda x: x
def top_down(brule, fns=basic_fns): """ Apply a rule down a tree running it on the top nodes first """ return chain(do_one(brule, identity), lambda expr: sall(top_down(brule, fns), fns)(expr))