|q⟩ Bad Qubits

beginner · Programming · Single-Qubit Gates I: X, Y, Z

The Z Gate

The Pauli-Z gate is the third of the three Pauli single-qubit gates. Unlike X, which swaps amplitudes, Z leaves 0|0\rangle untouched and multiplies the 1|1\rangle amplitude by 1-1:

Z0=0,Z1=1.Z|0\rangle = |0\rangle, \qquad Z|1\rangle = -|1\rangle.

Its matrix is

Z=(1001).Z = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}.

Phase, not amplitude

When the qubit is in a basis state 0|0\rangle or 1|1\rangle, Z has no effect you can detect by measuring: the probability of each outcome is amplitude2|\text{amplitude}|^2, and multiplying by 1-1 does not change the absolute value. This minus sign is called a relative phase.

The effect of Z only becomes observable when the qubit is in a superposition. Apply Z to the equal superposition +=12(0+1)|+\rangle = \tfrac{1}{\sqrt{2}}\big(|0\rangle + |1\rangle\big):

Z+=12(Z0+Z1)=12(01)=.Z|+\rangle = \tfrac{1}{\sqrt{2}}\big(Z|0\rangle + Z|1\rangle\big) = \tfrac{1}{\sqrt{2}}\big(|0\rangle - |1\rangle\big) = |{-}\rangle.

The state |{-}\rangle has the same measurement probabilities as +|+\rangle — both give 0 or 1 with probability 12\tfrac{1}{2} — but the relative phase between the two amplitudes has flipped. That difference matters enormously in interference-based algorithms: a Hadamard applied after Z will rotate |{-}\rangle back to 1|1\rangle, not 0|0\rangle, demonstrating that the phase is physically real.

On the Bloch sphere, Z is a rotation by π\pi around the zz-axis: it leaves the north and south poles fixed while flipping the equatorial states +|+\rangle \leftrightarrow |{-}\rangle and +ii|{+i}\rangle \leftrightarrow |{-i}\rangle.

Try it

Prepare +|+\rangle with a Hadamard, then apply Z to produce |{-}\rangle. The grader checks the full state vector, so the sign of the 1|1\rangle amplitude matters.

Run your code to see the quantum state.

After running, you should see the amplitude on 0|0\rangle is +120.707+\tfrac{1}{\sqrt{2}} \approx 0.707 and the amplitude on 1|1\rangle is 120.707-\tfrac{1}{\sqrt{2}} \approx -0.707. Both probabilities are still 12\tfrac{1}{2}, confirming that Z changes phase without changing measurement outcomes — unless you look in a basis that is sensitive to the phase.

Sign in on the full site to ask questions and join the discussion.