def unitsum_tuples(n, k, mn, mx):
    """Generates unitsum k-tuples with elements from mn to mx.

    This function is more general than slots(n,k,normalized=True), as it can
    return unitsum vectors with elements outside of (0,1).

    In order to generate unitsum samples, the following must be satisfied:
        1 = mx + (k-1) * mn

    Parameters
    ----------
    n : int
        The number of increments to include between mn and mx. n >= 1. The
        meaning of n is similar to the n in slots(n,k) and represents the
        number of ``items'' to place in each slot.
    k : int
        The length of the tuples (equivalently, the number of slots).
    mn : float
        The minimum value in the unitsum samples.
    mx : float
        The maximum value in the unitsum samples.

    Examples
    --------
    >>> s = unitsum_tuples(3, 2, .2, .8)
    >>> s.next()
    (0.20000000000000001, 0.80000000000000004)
    >>> s.next()
    (0.40000000000000008, 0.60000000000000009)
    >>> s.next()
    (0.60000000000000009, 0.40000000000000002)
    >>> s.next()
    (0.80000000000000004, 0.19999999999999996)

    """
    s = mx + (k - 1) * mn
    tol = 1e-09
    if not abs(s - 1) <= tol:
        msg = 'Specified min and max will not create unitsum tuples.'
        e = Exception(msg)
        raise e
    n += 1
    if mn < 0:
        shift = float(abs(mn))
    else:
        shift = -float(mn)
    seq, i = [mx + shift] * k + [0], k
    while i:
        t = tuple(seq[i] - seq[i + 1] - shift for i in range(k))
        s = float(sum(t))
        assert s > 0.001
        yield tuple(t)
        for idx, val in enumerate(seq):
            if abs(val) < 1e-09:
                i = idx - 1
                break
        seq[i:k] = [seq[i] - (mx - mn) / float(n - 1)] * (k - i)
