code: def adjoint_reduce(
      adj_sum_op, adj_prod_op, out_adj, op, arg, reduced_vars
  ):
      if op is adj_sum_op:
          out_adj = Approximate(
              adj_sum_op,
              out_adj,
              adj_prod_op(out_adj, arg),
              reduced_vars,
          )
          return ((arg, out_adj),)
      elif op is adj_prod_op:  # plate!
          out = arg.reduce(adj_prod_op, reduced_vars)
          div_op = ops.SAFE_BINARY_INVERSES[adj_prod_op]
          return ((arg, div_op(adj_prod_op(out_adj, out), arg)),)
      raise ValueError("should not be here!")
  
imports: from collections import defaultdict
  from collections.abc import Hashable
  from funsor.cnf import Contraction
  from funsor.interpretations import Interpretation, reflect
  from funsor.interpreter import stack_reinterpret
  from funsor.ops import AssociativeOp
  from funsor.registry import KeyedRegistry
  from funsor.terms import Approximate, Binary, Cat, Funsor, Reduce, Scatter, Slice, Subs, substitute, to_funsor
  from .None import instrument, interpreter, ops
label_desc: Use image node_id 6 for calling a global function with example usage: adjoint_reduce(adj_sum_op, adj_prod_op, out_adj, op, arg, reduced_vars) and returns: arg,  out_adj, arg,  div_op