compute w(i, j) based on Theorem 2.