def _within_interval(x, interval):
    """Utility function returns boolean if in interval (inclusive, both sides)."""
    if len(interval) == 2:
        return interval[0] <= x and x <= interval[1]
    else:
        raise ValueError("Invalid interval parameter '{0}'. Expected to be tuple "
                "or list of length 2.".format(interval))