|q⟩ Bad Qubits

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

X, Y, Z on Superpositions

The Pauli gates XX, YY, and ZZ do familiar things to the computational basis states ∣0⟩|0\rangle and ∣1⟩|1\rangle — but their effect on the superposition states ∣+⟩|+\rangle and ∣−⟩|-\rangle is just as important, and it reveals a beautiful symmetry.

Recall the two states:

∣+⟩=12(∣0⟩+∣1⟩),∣−⟩=12(∣0⟩−∣1⟩).|+\rangle = \frac{1}{\sqrt{2}}\big(|0\rangle + |1\rangle\big), \qquad |-\rangle = \frac{1}{\sqrt{2}}\big(|0\rangle - |1\rangle\big).

What X does to |+⟩ and |−⟩

The matrix X=(0110)X = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix} swaps the two amplitudes. Applying it to ∣+⟩|+\rangle:

X∣+⟩=12(0110)(11)=12(11)=∣+⟩.X|+\rangle = \frac{1}{\sqrt{2}}\begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}\begin{pmatrix} 1 \\ 1 \end{pmatrix} = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 \\ 1 \end{pmatrix} = |+\rangle.

And for ∣−⟩|-\rangle with column vector 12(1,−1)T\tfrac{1}{\sqrt{2}}(1,-1)^T:

X∣−⟩=12(0110)(1−1)=12(−11)=−∣−⟩.X|-\rangle = \frac{1}{\sqrt{2}}\begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}\begin{pmatrix} 1 \\ -1 \end{pmatrix} = \frac{1}{\sqrt{2}}\begin{pmatrix} -1 \\ 1 \end{pmatrix} = -|-\rangle.

So ∣+⟩|+\rangle and ∣−⟩|-\rangle are eigenstates of XX with eigenvalues +1+1 and −1-1 respectively. On the Bloch sphere, XX is a rotation by π\pi about the xx-axis — which fixes the ±x\pm x poles.

What Z does to |+⟩ and |−⟩

The matrix Z=(100−1)Z = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix} flips the sign of the ∣1⟩|1\rangle amplitude. This swaps ∣+⟩|+\rangle and ∣−⟩|-\rangle:

Z∣+⟩=12(∣0⟩−∣1⟩)=∣−⟩,Z∣−⟩=12(∣0⟩+∣1⟩)=∣+⟩.Z|+\rangle = \frac{1}{\sqrt{2}}\big(|0\rangle - |1\rangle\big) = |-\rangle, \qquad Z|-\rangle = \frac{1}{\sqrt{2}}\big(|0\rangle + |1\rangle\big) = |+\rangle.

In other words, ZZ acts like a bit-flip in the XX basis — it exchanges the two XX-basis states, just as XX exchanges ∣0⟩|0\rangle and ∣1⟩|1\rangle in the ZZ basis.

What Y does to |+⟩ and |−⟩

The matrix Y=(0−ii0)Y = \begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix} introduces imaginary factors. Direct multiplication gives:

Y∣+⟩=12(−ii)=−i⋅12(1−1)=−i∣−⟩,Y|+\rangle = \frac{1}{\sqrt{2}}\begin{pmatrix} -i \\ i \end{pmatrix} = -i \cdot \frac{1}{\sqrt{2}}\begin{pmatrix} 1 \\ -1 \end{pmatrix} = -i|-\rangle, Y∣−⟩=12(ii)=i⋅12(11)=i∣+⟩.Y|-\rangle = \frac{1}{\sqrt{2}}\begin{pmatrix} i \\ i \end{pmatrix} = i \cdot \frac{1}{\sqrt{2}}\begin{pmatrix} 1 \\ 1 \end{pmatrix} = i|+\rangle.

So YY also swaps ∣+⟩|+\rangle and ∣−⟩|-\rangle, but with an imaginary phase factor of ∓i\mp i.

Try it

Verify the prediction Z∣+⟩=∣−⟩Z|+\rangle = |-\rangle by building the circuit. Start in ∣0⟩|0\rangle, apply HH to reach ∣+⟩|+\rangle, then apply ZZ. The simulator will confirm the resulting state is ∣−⟩|-\rangle.

Run your code to see the quantum state.

After running, you should see amplitudes ≈+0.707\approx +0.707 for ∣0⟩|0\rangle and ≈−0.707\approx -0.707 for ∣1⟩|1\rangle — the characteristic signature of ∣−⟩|-\rangle. The Bloch vector points along −x-x.

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