def derivatives(seq):
    """Returns the derivative of this sequence by differencing.
    The output has the same length (`0` is added to the end)."""
    ret = [b-a for a,b in zip(seq, seq[1:])]
    ret.append(0)
    return ret