def contract(lhs, rhs, metric=None):
    """Performs a contraction between two vectors,
    given a metric. In the absence of a metric,
    returns a Euclidean dot product.
    """
    return sum(m*l*r for m, l, r in
               zip(metric if metric else [1]*len(lhs),
                   lhs, rhs))