import torch


def value_td_residuals(
    rewards: torch.Tensor,
    values: torch.Tensor,
    next_values: torch.Tensor,
    discount: float,
) -> torch.Tensor:
    """Compute TD residual of state value function.

    All tensors must be one dimensional. This is valid only for one trajectory.

    Parameters
    ----------
    rewards:
        The one step reward.
    values:
        The estimated values at the current step. Note that the last test is
        terminal, the associated value should be zero.
    next_values:
        The estimated values at the next step.
    discount:
        The discount rate.

    """
    return rewards + (discount * next_values) - values