The X, H and Z gates
Lesson 7 of 23 in the course “Quantum”. Free, with animations and a quiz.
A gate is a turn
In an ordinary computer, bits are changed by logic gates: AND, OR, NOT. In a quantum computer that job goes to quantum gates. A gate is a command that turns the qubit’s arrow on the Bloch sphere. Physically it’s a short pulse: a microwave for a superconducting qubit or a laser flash for an ion. A key difference: any gate can be undone with the reverse turn. Only measurement can’t be undone, because it wipes the amplitudes.
X: flipping 0 and 1
The X gate is the quantum version of NOT. It turns the sphere upside down: 0 becomes 1, 1 becomes 0. If the qubit was in superposition, X swaps the amplitudes of 0 and 1. It’s the simplest gate, and every course starts with it. In practice X is used to prepare the inputs, for example to write the number 101 into a register.
H: making a superposition
The H gate is named after French mathematician Jacques Hadamard. It moves the arrow from a pole to the equator: a sure 0 becomes the “plus” state, 50/50. A sure 1 becomes “minus”, also 50/50 but with a different sign. Almost every quantum program starts by putting an H on every qubit. That gives the algorithm a superposition of all inputs, which interference then works on.
Two H’s in a row undo each other
Logic says: H made a 50/50 coin, a second H will shuffle it again, and it’s 50/50 once more. Reality: after two H’s the qubit always gives 0. Why? Two paths lead to 1, one with a plus amplitude and one with a minus, and they cancel. It’s the interferometer from level one, just drawn as a circuit. An ordinary random coin can’t do that: flipped twice, it stays random.
Z: invisible, yet it changes everything
The Z gate puts a minus in front of the amplitude of 1, that is, it changes the phase. The chances don’t change: measure right away and Z seems to do nothing. But put it between two H’s, and instead of a guaranteed 0 you get a guaranteed 1. So H · Z · H does the same thing as X. That’s the core trick of quantum algorithms: hide information in a sign, then use H to turn the sign into a measurement result.
Reading circuits like sheet music
Quantum programs are drawn as circuits, and that’s easier than it looks. Each horizontal line is one qubit, and all start at 0. Time runs left to right. A box with a letter is a gate; a dot joined to a circled plus is a two-qubit gate, which we’ll cover next lesson. The dial icon at the end is a measurement. You’ll see exactly these diagrams in textbooks, papers and in IBM’s cloud, where you can build them with a mouse.
Check yourself
- What will measurement show after two H gates in a row?
Correct answer: Always 0. The second H brings the arrow back to the 0 pole: the plus and minus paths to 1 cancel out. - Your friend says: “Z is broken, the result didn’t change.” What do you say?
Correct answer: Z changes the sign; add an H before measuring and the difference shows up. Z doesn’t touch the chances, only the phase. Measurement can’t see phase, but an H gate turns it into a difference between 0 and 1. - Which gate do you add to write a 1 into the second qubit?
Correct answer: X: it turns 0 into a sure 1. X is quantum NOT: it turns a sure 0 into a sure 1. That’s exactly how inputs are prepared.