def sig_cmp(u, v, order):
    """
    Compare two signatures by extending the term order to K[X]^n.

    u < v iff
        - the index of v is greater than the index of u
    or
        - the index of v is equal to the index of u and u[0] < v[0] w.r.t. order

    u > v otherwise

    """
    if u[1] > v[1]:
        return -1
    if u[1] == v[1] and order(u[0]) < order(v[0]):
        return -1
    return 1
