optimization and Jacobi sorting