code: def naive_einsum(eqn, *terms, **kwargs):
      """
      Implements standard variable elimination.
      """
      backend = kwargs.pop("backend", "torch")
      if backend in BACKEND_OPS:
          sum_op, prod_op = BACKEND_OPS[backend]
      else:
          raise ValueError("{} backend not implemented".format(backend))
  
      assert isinstance(eqn, str)
      assert all(isinstance(term, Funsor) for term in terms)
      inputs, output = eqn.split("->")
      assert len(output.split(",")) == 1
      input_dims = frozenset(
          d for inp in inputs.split(",") for d in inp
      )
      output_dims = frozenset(output)
      reduce_dims = input_dims - output_dims
      return reduce(prod_op, terms).reduce(sum_op, reduce_dims)
  
file_path: funsor/funsor/einsum/__init__.py
imports: from functools import reduce
  import funsor.ops
  from funsor.cnf import Contraction
  from funsor.optimizer import apply_optimizer
  from funsor.sum_product import sum_product
  from funsor.terms import Funsor, Variable, lazy
label_desc: Use image node_id 2 for calling a global function with example usage: naive_einsum(eqn) and returns: reduce