def common_subexpression(expr, *exprs):
    # only one expression has itself as a common subexpression
    if not exprs:
        return expr

    exprs = (expr,) + exprs

    # get leaves for every expression
    all_leaves = [expr._leaves() for expr in exprs]

    # leaves common to all expressions
    leaves = set.intersection(*map(set, all_leaves))

    # no common leaves therefore no common subexpression
    if not leaves:
        raise ValueError(
            'No common leaves found in expressions %s' % list(exprs)
        )

    # list of paths from each expr to each leaf
    pathlist = [list(path(expr, leaf)) for expr in exprs for leaf in leaves]

    # ordered intersection of paths
    common = reduce(ordered_intersect, pathlist)
    if not common:
        raise ValueError(
            'No common subexpression found in paths to leaf: %s' % list(
                map(set, pathlist)
            )
        )

    # the first expression is the deepest node in the tree that is an ancestor
    # of every expression in `exprs`
    return first(common)
Run an arbitrary script on all nodes in the cluster.
dataset/ETHPy150Open blaze/blaze/blaze/expr/core.py/common_subexpression--crossover with--dataset/ETHPy150Open prestodb/presto-admin/prestoadmin/script.py/run