|q⟩ Bad Qubits

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

Gates Are Unitary

A quantum gate is more than just a transformation — it must be reversible and norm-preserving. These two properties are captured in a single word: unitary.

What unitarity means

A matrix UU is unitary if UU=IU^\dagger U = I, where UU^\dagger is the conjugate transpose of UU. This condition has an immediate physical consequence: if ψ|\psi\rangle is any normalized quantum state, then UψU|\psi\rangle is also normalized:

ψUUψ=ψIψ=ψψ=1.\langle \psi | U^\dagger U | \psi \rangle = \langle \psi | I | \psi \rangle = \langle \psi | \psi \rangle = 1.

In other words, the total probability of all outcomes is always exactly 1, no matter which gate you apply.

Verifying the X gate

The Pauli XX gate has the matrix

X=(0110).X = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}.

Its conjugate transpose is X=XX^\dagger = X (real and symmetric), so

XX=XX=(0110)(0110)=(1001)=I.X^\dagger X = X X = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}\begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} = I.

Starting from 0=(10)|0\rangle = \binom{1}{0}, applying XX gives X0=(01)=1X|0\rangle = \binom{0}{1} = |1\rangle. The amplitude squared of the single non-zero component is 12=1|1|^2 = 1 — full probability, nothing lost.

The same is true for the YY and ZZ gates, and indeed for every gate you will encounter in this course. Unitarity is what ensures that quantum computations are always physically valid.

Try it

The XX gate maps +=12(0+1)|+\rangle = \tfrac{1}{\sqrt{2}}(|0\rangle + |1\rangle) to 12(1+0)\tfrac{1}{\sqrt{2}}(|1\rangle + |0\rangle), which still has amplitudes 12\tfrac{1}{\sqrt{2}} for both basis states. Compute the sum of the squared amplitudes and return it. The grader checks that the result equals 1, confirming that XX preserves the norm.

Run your code to see the quantum state.

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