def compute_l(i, m, j, n):
    """Computes the `l` index from the composition of shift operators, Q_{i, m} Q_{j, n} = Q_{k, l} in Proposition 2
    of the paper (regarding efficient multiplication of simple Jacobians)."""
    if i >= 0 and j >= 0:
        return max(m - j, n)
    elif i >= 0 and j <= 0:
        return max(m, n) + min(i, -j)
    elif i <= 0 and j >= 0 and i + j >= 0:
        return max(m - i - j, n)
    elif i <= 0 and j >= 0 and i + j <= 0:
        return max(n + i + j, m)
    else:
        return max(m, n + i)