def all_rl(expr): if is_leaf(expr): return expr else: args = map(rule, expr.args) return new(type(expr), *args)
def top_down_rl(expr): newexpr = rule(expr) if is_leaf(newexpr): return newexpr return new(type(newexpr), *map(top_down_rl, newexpr.args))
def bottom_up_rl(expr): if is_leaf(expr): return rule(expr) else: return rule(new(type(expr), *map(bottom_up_rl, expr.args)))