code: def rewrite_ops(infix={}, prefix={}, const={}):
      """
      Decorator to replace infix binary operators, prefix unary operators, and
      constants (nullary operators) in the decorated function's code with named
      variables.
  
      For example the following code::
  
          @rewrite_ops({"+": "sum_op", "*": "prod_op"})
          def product_rule(sum_op, prod_op, lhs, rhs, d):
              return d(lhs) * rhs + lhs * d(rhs)
  
      will be rewritten as::
  
          def product_rule(sum_op, prod_op, lhs, rhs, d):
              return sum_op(prod_op(d(lhs), rhs), prod_op(lhs, d(rhs)))
  
      .. warning:: This must be used as the innermost decorator.
  
      .. warning:: This requires Python 3.9+ and should not yet be used in
          Funsor library code.
  
      :param dict infix: An optional mapping from infix operator symbol to
          variable name.
      :param dict prefix: An optional mapping from prefix operator symbol to
          variable name.
      :param dict const: An optional mapping from constant literal to variable
          name.
      :returns: A decorator
      :rtype: callable
      """
      transformer = OpTransformer(infix, prefix, const)
  
      def decorator(fn):
          source = inspect.getsource(fn)
  
          # Strip indentation and all decorators.
          indent = len(source) - len(source.lstrip())
          lines = []
          discard = True
          for line in source.split("\n"):
              line = line[indent:]
              if discard:
                  if line.startswith("def "):
                      discard = False
                  else:
                      continue
              lines.append(line)
          source = "\n".join(lines)
          assert source
  
          # Transform the function.
          a = ast.parse(source)
          a_t = transformer.visit(a)
          source_t = ast.unparse(a_t)
          result = {}
          exec(source_t, globals(), result)
          fn_t = result[fn.__name__]
          functools.update_wrapper(fn_t, fn)
          return fn_t
  
      return decorator
  
file_path: funsor/funsor/syntax.py
imports: import ast
  import functools
  import inspect
  from .None import ops
label_desc: Use image node_id 1 for calling a global function with example usage: rewrite_ops(infix, prefix, const) and returns: decorator, fn_t