def _absolute_and_relative_error(X, Y, norm):
    """Compute the absolute and relative errors between X and Y where Y is an
    approximation to X:

        absolute_error = ||X - Y||,
        relative_error = ||X - Y|| / ||X|| = absolute_error / ||X||,

    with ||X|| defined by norm(X).
    """
    norm_of_data = norm(X)
    absolute_error = norm(X - Y)
    return absolute_error, absolute_error / norm_of_data