Why Unitary Gates Cannot Purify a Mixed Qubit
A Hadamard can create off-diagonal entries without making a qubit purer. Test the spectral invariant in NumPy, then track what a SWAP with a clean ancilla really changes.
Suppose a qubit is in |0> with probability 0.8 and |1> with probability 0.2, with no accessible record telling you which preparation occurred. Could a clever sequence of gates turn it into a pure state?
Not if those gates act only on that qubit. You can rotate its state, change its measurement probabilities, and introduce off-diagonal matrix entries. You cannot change its eigenvalues. That small mathematical fact explains both the limitation and the resources that let you get around it.
Gates rotate eigenvectors, not eigenvalues
The qubit's density matrix is
rho = [[0.8, 0.0],
[0.0, 0.2]]
For a unitary gate U, the output is U rho U-dagger. If rho has an eigenvector v with eigenvalue lambda, then
rho v = lambda v
(U rho U-dagger)(U v) = lambda (U v)
The eigenvector rotates to U v, but its eigenvalue stays lambda. A whole circuit of unitary gates is another unitary, so adding more layers does not escape the argument.
Our input has eigenvalues 0.8 and 0.2. A pure qubit state has eigenvalues 1 and 0. There is no single-qubit unitary that connects them. IBM's density-matrix lesson explains the pure-state spectrum and the distinction between pure states and mixtures.
Two useful checks depend only on this spectrum:
purity = Tr(rho^2) = sum_j lambda_j^2
S(rho) = -sum_j lambda_j log2(lambda_j)
For the input, purity is 0.68 and von Neumann entropy is about 0.721928 bits. Both are unchanged by unitary gates acting on this same closed system. A pure state would have purity 1 and entropy 0. The spectral definition and unitary invariance of entropy are developed in Preskill's quantum-information notes, Section 5.2.
Coherence is not the same as purity
Apply a Hadamard gate. Direct matrix multiplication gives
H rho H-dagger = [[0.5, 0.3],
[0.3, 0.5]]
The output now has coherence in the computational basis: its off-diagonal entries are nonzero. Its Z measurement outcomes are equally likely. Yet its eigenvalues are still 0.8 and 0.2, so it is no purer than before.
The reverse confusion is just as common. A pure |0> state is diagonal in the computational basis, while the equally pure |+> state is not. Off-diagonal entries are basis-dependent. Mixedness is not.
On a qubit's Bloch ball, the same fact has a simple picture. Unitary gates rotate the Bloch vector without changing its length. This input has length 0.6, so it stays inside the ball rather than reaching the pure-state surface. The maximally mixed state has length zero and does not move at all under any single-qubit unitary.
Then why can a SWAP leave the qubit pure?
Add a second qubit B prepared in a clean |0> state. A joint SWAP operation does this:
rho_A tensor |0><0|_B --> |0><0|_A tensor rho_B
A is now pure. Nothing contradicts the theorem because SWAP acted on the two-qubit system, not on A alone. The joint spectrum and joint entropy are unchanged. The mixed state was transferred to B, not erased from the combined system.
This uses a resource: the initially pure ancilla. You cannot indefinitely reuse B as a clean ancilla after the swap without resetting it or supplying another clean system. Also, if A was correlated with a reference system, SWAP transfers those correlations to B rather than deleting them.
Check the complete bookkeeping in NumPy
This example constructs both operations exactly. The basis order for the joint matrix is |00>, |01>, |10>, |11>, with A first. The partial traces recover the individual qubit states after SWAP.
import numpy as np
rho = np.diag([0.8, 0.2])
H = np.array([[1.0, 1.0], [1.0, -1.0]]) / np.sqrt(2)
zero = np.diag([1.0, 0.0])
SWAP = np.array([[1, 0, 0, 0],
[0, 0, 1, 0],
[0, 1, 0, 0],
[0, 0, 0, 1]], dtype=float)
def report(label, state):
eigenvalues = np.linalg.eigvalsh(state)
nonzero = eigenvalues[eigenvalues > 1e-12]
entropy = -np.sum(nonzero * np.log2(nonzero))
entropy = max(0.0, entropy) # Avoid printing negative zero.
purity = np.trace(state @ state).real
print(f"{label}: purity={purity:.6f}, entropy={entropy:.6f}")
rotated = H @ rho @ H.conj().T
joint_before = np.kron(rho, zero)
joint_after = SWAP @ joint_before @ SWAP.conj().T
tensor = joint_after.reshape(2, 2, 2, 2) # a, b, a_prime, b_prime
A_after = np.trace(tensor, axis1=1, axis2=3)
B_after = np.trace(tensor, axis1=0, axis2=2)
assert np.allclose(rotated, [[0.5, 0.3], [0.3, 0.5]])
assert np.allclose(np.linalg.eigvalsh(rotated), np.linalg.eigvalsh(rho))
assert np.allclose(A_after, zero)
assert np.allclose(B_after, rho)
assert np.allclose(np.linalg.eigvalsh(joint_before),
np.linalg.eigvalsh(joint_after))
for label, state in [("input", rho), ("after H", rotated),
("A after SWAP", A_after), ("B after SWAP", B_after),
("joint before", joint_before), ("joint after", joint_after)]:
report(label, state)
Output:
input: purity=0.680000, entropy=0.721928
after H: purity=0.680000, entropy=0.721928
A after SWAP: purity=1.000000, entropy=0.000000
B after SWAP: purity=0.680000, entropy=0.721928
joint before: purity=0.680000, entropy=0.721928
joint after: purity=0.680000, entropy=0.721928
Notice that the joint state remains mixed. This is not a mathematical purification, where a mixed state's density matrix is represented as the reduced state of a larger pure system. Here we physically exchange states using a pure ancilla, and the total state remains mixed throughout.
Read the system boundary carefully
Measurement with an accessible outcome can produce a purer conditional state. Measurement followed by feedback can reset a qubit, and an environment can carry away entropy during cooling. These are not unitary operations on the isolated qubit. If you average over an unread projective measurement without feedback, it does not generally purify the qubit either. For this diagonal input, an unread Z measurement changes nothing.
A classical preparation record also matters. If you know whether this particular run contains |0> or |1>, you can choose I or X accordingly. That is record-dependent control, not one fixed unitary acting on the unlabelled mixture.
So when a circuit seems to clean up a mixed state, ask three questions: Which system is becoming purer? What additional resource was supplied? Where did the mixedness or the correlations go? Those questions usually reveal the missing ancilla, measurement record, reset, or discarded environment.