code: def sequential_sum_product(sum_op, prod_op, trans, time, step):
      """
      For a funsor ``trans`` with dimensions ``time``, ``prev`` and ``curr``,
      computes a recursion equivalent to::
  
          tail_time = 1 + arange("time", trans.inputs["time"].size - 1)
          tail = sequential_sum_product(sum_op, prod_op,
                                        trans(time=tail_time),
                                        time, {"prev": "curr"})
          return prod_op(trans(time=0)(curr="drop"), tail(prev="drop")) \
             .reduce(sum_op, "drop")
  
      but does so efficiently in parallel in O(log(time)).
  
      :param ~funsor.ops.AssociativeOp sum_op: A semiring sum operation.
      :param ~funsor.ops.AssociativeOp prod_op: A semiring product operation.
      :param ~funsor.terms.Funsor trans: A transition funsor.
      :param Variable time: The time input dimension.
      :param dict step: A dict mapping previous variables to current variables.
          This can contain multiple pairs of prev->curr variable names.
      """
      assert isinstance(sum_op, AssociativeOp)
      assert isinstance(prod_op, AssociativeOp)
      assert isinstance(trans, Funsor)
      assert isinstance(time, Variable)
      assert isinstance(step, dict)
      assert all(isinstance(k, str) for k in step.keys())
      assert all(isinstance(v, str) for v in step.values())
      if time.name in trans.inputs:
          assert time.output == trans.inputs[time.name]
  
      step = OrderedDict(sorted(step.items()))
      drop = tuple("_drop_{}".format(i) for i in range(len(step)))
      prev_to_drop = dict(zip(step.keys(), drop))
      curr_to_drop = dict(zip(step.values(), drop))
      drop = frozenset(
          Variable(v, trans.inputs[k]) for k, v in curr_to_drop.items()
      )
  
      time, duration = time.name, time.output.size
      while duration > 1:
          even_duration = duration // 2 * 2
          x = trans(
              **{time: Slice(time, 0, even_duration, 2, duration)},
              **curr_to_drop,
          )
          y = trans(
              **{time: Slice(time, 1, even_duration, 2, duration)},
              **prev_to_drop,
          )
          contracted = Contraction(sum_op, prod_op, drop, x, y)
  
          if duration > even_duration:
              extra = trans(
                  **{time: Slice(time, duration - 1, duration)}
              )
              contracted = Cat(time, (contracted, extra))
          trans = contracted
          duration = (duration + 1) // 2
      return trans(**{time: 0})
  
imports: import re
  from collections import OrderedDict, defaultdict
  from functools import reduce
  from math import gcd
  import funsor
  import funsor.ops
  from funsor.cnf import Contraction
  from funsor.domains import Bint, Reals
  from funsor.interpreter import gensym
  from funsor.ops import PRODUCT_TO_POWER, UNITS, AssociativeOp
  from funsor.terms import Cat, Funsor, FunsorMeta, Number, Slice, Stack, Subs, Variable, eager, substitute, to_funsor
  from funsor.util import quote
label_desc: Use image node_id 9 for calling a global function with example usage: sequential_sum_product(sum_op, prod_op, trans, time, step) and returns: trans