Jacobi's algorithm