def knuth_sum(a, b):
    """Error-free transformation of the sum of two floating point numbers
    according to

    D.E. Knuth.
    The Art of Computer Programming: Seminumerical Algorithms, volume 2.
    Addison Wesley, Reading, Massachusetts, second edition, 1981.

    The underlying problem is that the exact sum a+b of two floating point
    number a and b is not necessarily a floating point number; for example if
    you add a very large and a very small number. It is however known that the
    difference between the best floating point approximation of a+b and the
    exact a+b is again a floating point number. This routine returns the sum
    and the error.

    Algorithm 3.1 in <https://doi.org/10.1137/030601818>.
    """
    x = a + b
    z = x - a
    y = (a - (x - z)) + (b - z)
    return x, y