(expr)
Rebuild a SymPy tree

    This function recursively calls constructors in the expression tree.
    This forces canonicalization and removes ugliness introduced by the use of
    Basic.__new__
Rebuild a SymPy tree
Rebuild a SymPy tree
def rebuild(expr):
    """ Rebuild a SymPy tree

    This function recursively calls constructors in the expression tree.
    This forces canonicalization and removes ugliness introduced by the use of
    Basic.__new__
    """
    try:
        return type(expr)(*list(map(rebuild, expr.args)))
    except:
        return expr
def rebuild ( expr ) : try : return type ( expr ) ( * list ( map ( rebuild , expr . args ) ) ) except : return expr