def topt(t,s,epsilon = 1e-7):
    """
    One optimization method to choose t' such that the rank of
    the resultant Rp is low
    Parameters
    ----------
    t : vector t[k]
        constructed from tensor U
           |k
         --U--
        |____|
    s : vector s[i]
        singular spectrum of an eivironment matrix.
    epsilon : float, optional
         a small number below which we think the singular value is zero.
         The default is 1e-7.

    Returns
    -------
    tprime : vector tprime[k]
        optimized t.

    """
    # properly normalize the environment spectrum if it is not
    s = s / s.norm()
    # For Z2 symmetric tensor
    t = t.flip_dir(0)
    # choose t' according to eq.(31) in the paper
    if epsilon !=0:
        ratio = s / epsilon
        weight = ratio ** 2 / (1 + ratio**2)
        tprime = t.multiply_diag(weight, 0 , direction="left")
    else:
        tprime = t * 1.0
    return tprime