Quantum Algorithms, Quantum Computing, Physics, Mathematics, Education.
# calculate eigenvalues of the density matrix accumulator = 0 lamb_vals = [None] * len(eig_vals) for i in range(len(eig_vals) - 1, -1, -1): if eig_vals[i] + (accumulator / (i + 1)) >= 0: for j in range(i + 1): lamb_vals[j] = eig_vals[j] + (accumulator / (i + 1)) break else: lamb_vals[i] = 0