def jaccard_index(pos1, pos2):
    """calculate intersection over union for two positions"""
    # assumes that within each tuple, the values are in increasing order
    intersection = min(
        max(pos1[1] - pos2[0], 0),
        max(pos2[1] - pos1[0], 0))
    min_point = min(pos1[0], pos2[0])
    max_point = max(pos1[1], pos2[1])
    union = min(max_point - min_point, (pos2[1] - pos2[0]) + (pos1[1] - pos1[0]))
    res = intersection / union
    return res