|q⟩ Bad Qubits

beginner · Programming · Single-Qubit Gates II: H, S, T & Phase

HZH = X and Friends

The Hadamard gate exchanges the computational (ZZ) basis and the XX basis. A useful consequence is that conjugating ZZ by HH turns it into XX:

HZH=X.H Z H = X.

You can check it by multiplying the matrices, but the idea is cleaner: ZZ flips the sign of 1|1\rangle (a reflection about the zz-axis), while HH swaps the xx- and zz-axes. Doing "swap axes → reflect about zz → swap back" is the same as reflecting about xx, which is exactly what XX does.

This is your first taste of building one operation out of others — the heart of compiling quantum programs onto a fixed gate set.

Try it

Implement XX using only HH and ZZ. This exercise grades the whole operation (its unitary matrix), so doing nothing won't pass — you must actually realize XX.

Run your code to see the quantum state.

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