def get_n_step_backup(rewards, pcontinues, state_values, start, n):
  """Evaluates a single n-step backup (return) starting at position start.

    http://incompleteideas.net/sutton/book/ebook/node73.html (Eq. 7.1)

  Args:
    rewards: a list containing a sequence of rewards.
    pcontinues: a list containing a sequence of discounts.
    state_values: a list containing a sequence of state-values.
    start: position at which the n-Step return has to be evaluated.
    n: number of steps over which rewards are summed before adding the
        respective bootstrapped state-value.

  Returns:
    Sum of discounted rewards plus discounted bootstrapped value.
  """
  accumulator = 0.0
  k = 1.0
  for i in xrange(start, start + n):
    accumulator += k * rewards[i]
    k *= pcontinues[i]
  accumulator += k * state_values[start + n - 1]
  return accumulator
Evaluates a single n-step backup (return) starting at position start.

    http://incompleteideas.net/sutton/book/ebook/node73.html (Eq. 7.1)

  Args:
    rewards: a list containing a sequence of rewards.
    pcontinues: a list containing a sequence of discounts.
    state_values: a list containing a sequence of state-values.
    start: position at which the n-Step return has to be evaluated.
    n: number of steps over which rewards are summed before adding the
        respective bootstrapped state-value.

  Returns:
    Sum of discounted rewards plus discounted bootstrapped value.
  
trfl/sequence_ops_test.py