def get_complex_n_step_backup(rewards, pcontinues, state_values, start, n,
                              lambda_):
  """Evaluates a complex n=step backup (sum of lambda-weighted n-step backups).

    http://incompleteideas.net/sutton/book/ebook/node74.html (Eq. 7.3)

  Args:
    rewards: a list containing rewards.
    pcontinues: a list containing discounts.
    state_values: a list containing boostrapped 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 respective
        boostrapped state values.
    lambda_: mixing parameter lambda.

  Returns:
    A single complex backup.
  """
  accumulator = 0.0
  for t in xrange(1, n):
    value = get_n_step_backup(rewards, pcontinues, state_values, start, t)
    weight = (1 - lambda_) * (lambda_ ** (t - 1))
    accumulator += + value * weight
  value = get_n_step_backup(rewards, pcontinues, state_values, start, n)
  weight = lambda_ ** (n - 1)
  accumulator += value * weight
  return accumulator
Evaluates a complex n=step backup (sum of lambda-weighted n-step backups).

    http://incompleteideas.net/sutton/book/ebook/node74.html (Eq. 7.3)

  Args:
    rewards: a list containing rewards.
    pcontinues: a list containing discounts.
    state_values: a list containing boostrapped 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 respective
        boostrapped state values.
    lambda_: mixing parameter lambda.

  Returns:
    A single complex backup.
  
trfl/sequence_ops_test.py