Пример #1
0
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))))
Пример #2
0
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))
Пример #3
0
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
Пример #4
0
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))
Пример #5
0
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))