Chapter 3

Gates are rotations

So far the arrow was set by hand: you grabbed it and turned it where you wanted. A real qubit has no hand. There are a few well-tuned moves, and every program is put together from them, like a melody from notes.

Such a move is called a gate. A gate knows nothing about where the arrow is right now: it rotates the whole sphere around its own axis by its own angle. Let's look at the three main ones.

XXHHHZH100%you get 00%you get 1

Three letters

The letters on the keys are not arbitrary. Here is what each one means.

Under each letter is its rule: what the gate does to |0⟩ and to |1⟩. A letter in front of a ket means “the gate was applied to this state”.

  • X

    X — the X gate

    X|0⟩ = |1⟩X|1⟩ = |0⟩

    A half-turn around the horizontal axis. Swaps zero and one.

    The letter is the name of the axis: in physics the axis it rotates around is called the x axis. The gate's other name is the quantum NOT.

  • H

    H — the Hadamard gate

    H|0⟩ = |+⟩H|1⟩ = |−⟩

    A half-turn around the tilted axis. Takes the arrow from a pole to the equator and back.

    Named after the French mathematician Jacques Hadamard: the table of numbers used to write this gate down bears his name.

  • Z

    Z — the Z gate

    Z|0⟩ = |0⟩Z|1⟩ = −|1⟩

    A half-turn around the vertical axis. Leaves the tilt alone and changes only the turn.

    Also the name of an axis: the vertical axis that zero and one sit on is called the z axis.

In the rule for Z a minus sign appears in front of a ket for the first time. It does not affect the chances: the square of a negative number is positive. What it does change is the subject of the next chapter.

There is also a Y gate, a rotation around the third axis. It works the same way and will be needed later.

A gate as a table

The rules speak only about |0⟩ and |1⟩. That is enough for any arrow: a gate acts on each part of the notation separately. We take this as a fact — all gates work this way.

H(0.6|0⟩ + 0.8|1⟩)= 0.6·H|0⟩ + 0.8·H|1⟩

To make calculating easier, the state is written more compactly: two amplitudes one above the other. The amplitude of zero on top, of one below. It is the same notation, just without the kets.

α|0⟩ + β|1⟩ = αβ|0⟩ = 10 |1⟩ = 01

A gate is then written as a table of two columns. The first column is where the gate sends |0⟩, the second where it sends |1⟩. Such a table is called a matrix.

X = 0110 Z = 100−1H = 1/√2111−1

Using it is simple: multiply the first column by α, the second by β, and add. Let us check with H and a familiar state.

1/√2111−1 0.60.8 = 1/√20.6 + 0.80.6 − 0.8= 1/√21.4−0.2

The squares of the new amplitudes are 0.98 and 0.02. They add up to one again: the gate changed the chances but lost nothing.

Control panel

A chain of gates is drawn as a line: the arrow at zero on the left, then the gates in the order they are applied, and the measurement on the right. This drawing is called a quantum circuit, and you read it left to right, like a line of text.

Now you try. The buttons add gates to the circuit, the arrow starts at zero, and the simulator works out the state after every gate. Try putting Z first and then H — and the other way round.

side view
top view
you get 0100%
you get 10%
0
Click a gate in the circuit to remove it.
From the side you see the arrow's tilt, from above its turn. The chances depend only on the tilt.

Order matters: H then Z is not the same as Z then H. Gates are rotations, and rotations around different axes can't be swapped. Take a book, rotate it first around one axis, then around another; then repeat in the opposite order. The book ends up lying differently.

The same chain can be written in letters. The gate closest to the ket acts first, so the line is read right to left: HZ|0⟩ means “first Z, then H”.

Why a rotation

Could a gate be anything at all? Try a “reset”: it puts any arrow at |0⟩. Its rule: |0⟩ stays |0⟩, and |1⟩ also becomes |0⟩.

Apply it to |+⟩, part by part. Both parts turn into |0⟩, so the amplitude of zero becomes 2/√2 ≈ 1.41. Its square is 2: a chance of two hundred percent. That cannot be.

A real gate must keep the sum of the chances equal to one for every arrow. That is exactly what it means not to stretch or squeeze the sphere but only to rotate it. It also explains why a gate can be undone: a rotation can always be turned back.

HH = I

Two H gates in a row return any arrow to where it was. The gate “do nothing” is written I.

Gate versus measurement

A gate and a measurement are two different ways to touch a qubit. A gate rotates the arrow and tells you nothing: after it you haven't learned a single bit. But it can be undone. A measurement tells you one bit and erases everything else in return; it cannot be undone.

Hence the shape of every quantum program: many gates in a row, blind, and a measurement at the very end.

What to remember

  • A gate is a rotation of the whole sphere around its own axis. The axis of X is horizontal, of Z vertical, of H slanted.
  • Any gate can be undone. Two X's, two Z's or two H's in a row put the arrow back in place.
  • Z doesn't change the chances, but it changes where the next H will send the arrow.
  • A gate is written as a matrix: the first column is where |0⟩ goes, the second where |1⟩ goes.

Test yourself

The problems are optional: solve them now or come back to them later.

1

Without X

not solved

The X button is broken. Take the arrow from zero to one using the two that are left.

side view
top view
you get 0100%
you get 10%
0
Click a gate in the circuit to remove it.

One has to come up for certain.

2

Without Z

not solved

Set the arrow to the west of the equator, where H and Z brought it in the scene. Only this time the Z button doesn't work.

side view
top view
you get 0100%
you get 10%
0
Click a gate in the circuit to remove it.

West is a turn of 180° at a tilt of 90°.

3

A hundred presses

not solved

The arrow is at zero. The H gate was pressed a hundred times in a row. Where is it now?

The Z gate left a puzzle: the chances are the same, yet the outcome after H is different. So an arrow on the equator has a property that measurement can't see but gates can feel. It has a name: phase.