class_docstr: Backend program for evaluating a symbolic funsor expression.
  
  Programs depend on the funsor library only via ``funsor.ops`` and op
  registrations; program evaluation does not involve funsor interpretation or
  rewriting. Programs can be pickled and unpickled.
  
  :param iterable expr: A list of built-in constants (leaves).
  :param iterable inputs: A list of string names of program inputs (leaves).
  :param iterable operations: A list of program operations defining
      non-leaf nodes in the program dag. Each operations is a tuple ``(op,
      arg_ids)`` where op is a funsor op and ``arg_ids`` is a tuple of
      positions of values, starting from zero and counting: constants,
      inputs, and operation outputs.
class_docstr_tok: ["Backend","program","for","evaluating","a","symbolic","funsor","expression",".","Programs","depend","on","the","funsor","library","only","via","``","funsor.ops","``","and","op","registrations",";","program","evaluation","does","not","involve","funsor","interpretation","or","rewriting",".","Programs","can","be","pickled","and","unpickled",".",":","param","iterable","expr",":","A","list","of","built-in","constants","(","leaves",")",".",":","param","iterable","inputs",":","A","list","of","string","names","of","program","inputs","(","leaves",")",".",":","param","iterable","operations",":","A","list","of","program","operations","defining","non-leaf","nodes","in","the","program","dag",".","Each","operations","is","a","tuple","``","(","op",",","arg_ids",")","``","where","op","is","a","funsor","op","and","``","arg_ids","``","is","a","tuple","of","positions","of","values",",","starting","from","zero","and","counting",":","constants",",","inputs",",","and","operation","outputs","."]
docstr: Returns Python code text defining a straight-line function equivalent
  to this program.
  
  :param str name: Optional name for the function, defaults to "program".
  :returns: A string defining a python function equivalent to this program.
  :rtype: str
docstr_tok: ["Returns","Python","code","text","defining","a","straight-line","function","equivalent","to","this","program",".",":","param","str","name",":","Optional","name","for","the","function",",","defaults","to","``","program","''",".",":","returns",":","A","string","defining","a","python","function","equivalent","to","this","program",".",":","rtype",":","str"]
code: def as_code(self, name="program"):
      """
      Returns Python code text defining a straight-line function equivalent
      to this program.
  
      :param str name: Optional name for the function, defaults to "program".
      :returns: A string defining a python function equivalent to this program.
      :rtype: str
      """
      lines = [
          "# Automatically generated by funsor.compiler.FunsorProgram.as_code().",
          "def {}({}):".format(name, ", ".join(self.inputs)),
          "    from funsor import set_backend, ops",
          f"    set_backend({repr(self.backend)})",
      ]
      start = len(lines)
  
      def let(body):
          i = len(lines) - start
          lines.append(f"    v{i} = {body}")
  
      for c in self.constants:
          let(c)
      for name in self.inputs:
          let(name)
      for op, arg_ids in self.operations:
          op = _print_op(op)
          args = ", ".join(f"v{arg_id}" for arg_id in arg_ids)
          let(f"{op}({args},)")
      lines.append(f"    return v{len(lines) - start - 1}")
      return "\n".join(lines)
  
imports: from funsor.util import get_backend, set_backend
label_desc: Use image node_id 3 for calling the OpProgram obj's underlying member method code with example usage: obj.as_code(name) and returns: str