Lesson 4: Single-qubit gates
Gates as matrices and as turns of the Bloch sphere, and why every gate is unitary
The interactive version checks every answer, gives hints and saves your progress in this browser. This page is the same lesson on one page, with the answers folded away.
1 / 11 · Learn
Before you start
So far you have written states down and measured them. A gate changes a state without reading anything out, and every computation in the rest of this course is built from gates.
By the end of this lesson you can:
- apply , and to a state by matrix multiplication;
- read a gate's two columns as what it does to and ;
- test whether a matrix is unitary, and say why every gate must be;
- turn a circuit into a matrix product in the right order;
- picture , and as half turns of the Bloch sphere.
Check yourself
A warm-up: make a guess before reading on. The lesson comes back to it.
A qubit starts in . One Hadamard gate would make a measurement in the 0/1 basis come out 0 or 1 with equal odds. Instead of measuring, you apply a second time, and only then measure in that basis. What is the probability of getting 0?
- A
- B
- C
- D
Show the answer
Answer: A.
and , so . A measurement in the 0/1 basis then gives 0 with certainty, so .
Why not the others
- B. A common picture is that randomizes a qubit, so a second leaves it random. But after one the qubit is in the definite state , not a coin, and the second makes the two contributions to cancel. So : the 50/50 appears only if you measure in the 0/1 basis between the gates.
- C. It is tempting to multiply two 50/50 steps, . But a gate does not add randomness step by step: it changes amplitudes, and amplitudes can cancel. Here the cancellation is complete, because .
- D. This treats as a "square root of NOT", as if two of them made an and sent to . They don't: , so the qubit ends in , and the outcome is 0 every time.
Check yourself
A warm-up: make a guess before reading on. The lesson comes back to it.
Is there a single-qubit gate that turns every input state into , whatever the input was?
- AYes: the matrix keeps the part, and you rescale the result.
- BNo: every gate can be undone, so no gate can send two different inputs to the same output.
- CYes: a suitable fixed sequence of , and .
- DNo: gates never change the probabilities of the measurement outcomes 0 and 1; only measurements do.
Show the answer
Answer: B. No: every gate can be undone, so no gate can send two different inputs to the same output.
Gates are unitary, and a unitary always has an inverse. A gate that sent both and to would have no inverse. Resetting an unknown qubit takes a measurement in the 0/1 basis, followed by if the result was 1.
Why not the others
- A. Keeping only the part is a natural first idea. But that matrix sends to the zero vector, which is not a state, and the rescaling factor depends on an input you may not know. A gate must keep every state normalized and be undoable, so it can never send two different inputs to the same output.
- C. Each of , and can be undone, so any sequence of them can be undone too. A sequence that sent both and to could not be undone: from the output alone you could not tell which input you had.
- D. Gates change probabilities all the time: turns a certain outcome 0 into a 50/50 split. The real obstacle is different: a gate is invertible, so it cannot merge two different inputs into one output.
2 / 11 · Learn
A gate is a linear map
The classical NOT gate swaps 0 and 1. Its quantum version, , does the same to the basis states: and . Quantum gates are linear, so those two facts settle what does to every state:
With states written as column vectors, a gate is a matrix, and you can read it straight off: the first column is the image of , the second column is the image of .
Refresher: Matrices acting on states Matrix times vector, and why order matters, if either is rusty.
Check yourself
A gate sends and . Which matrix is ?
- A
- B
- C
Hints
- Which column does pick out when you multiply?
- Column 1 is and column 2 is , written top to bottom.
Show the answer
Answer: B.
Column 1 is and column 2 is . Multiplying by picks out column 1, and by column 2.
Why not the others
- A. This writes the images as rows. Test it: multiplying by picks out the first column, , which is not . Rows feel natural because we read across, but the multiplication rule puts each input's image down a column.
- C. That is , whose second column is . Here the image of is , so the second column is . On alone the would be a global phase, but next to the first column it becomes a relative phase, so dropping it changes the gate.
Check yourself
Apply to . Enter the exact amplitudes of the result.
Hints
- Where does the amplitude of end up after ?
- Linearity: .
Show the answer
Answer:
swaps the entries of the column vector: , that is .
3 / 11 · Learn
Z, H and the Bloch sphere
Two more single-qubit gates come up all the time. leaves alone and flips the sign of . The Hadamard gate sends to and to . Stack those images as columns:
On the Bloch sphere each of these gates is a half turn of the whole sphere: about the axis, about the axis, and about the axis halfway between and . A state on the rotation axis stays put; every other state moves.
Check yourself
What is ?
- A
- B
- C
- D
Hints
- What does do to the two amplitudes of a state?
- swaps the amplitudes of and . What are the two amplitudes of ?
Show the answer
Answer: A.
lies on the axis, the axis of 's half turn, so it does not move. In vectors: swaps two equal entries.
Why not the others
- B. acts as NOT on the basis states, but it does not send every state to . By linearity .
- C. A natural guess is that NOT flips into . But swaps the two amplitudes, and has equal amplitudes, so nothing changes: . On the sphere sits on the axis of 's half turn; turning into is what does.
- D. No sign appears: swapping two equal amplitudes gives back exactly . A sign does appear for : , the same physical state.
Check yourself
Using only the gate buttons, move the state from to , the south pole.
Set the state on the Bloch sphere with the gates X, Z, H.
Hints
- Which gate takes to one of the poles?
- swaps and ; swaps the two poles.
Show the answer
Answer:
Two routes work: then (), or then ().
Aside: the Pauli Y gate
There is a fourth gate, . Together , and are called the Pauli matrices. On the Bloch sphere is a half turn about the axis. You can check that , so for this course it adds nothing new.
4 / 11 · Learn
Why gates must be unitary
A gate has to turn every state into a state, so it must preserve length: before and after. For a matrix that requirement is exactly
where the adjoint is transposed with every entry complex-conjugated. A matrix with this property is unitary. In practice you check the columns: each must have length 1, and the two must be orthogonal (conjugate the first column's entries before multiplying; see the inner-product refresher). A unitary can always be undone by applying . In the other direction, every unitary matrix is a valid gate. So there are infinitely many single-qubit gates, against one non-trivial classical one-bit gate, NOT.
Check yourself
Select every matrix that is a valid gate.
Select all that apply.
- A
- B
- C
- D
Hints
- What length must each column have?
- A unitary has columns of length 1 that are orthogonal to each other.
Show the answer
Answers: A. ; B.
Check the columns. In the first matrix each has squared length , and , so they are orthogonal. has columns and . The shear and the projector each have a second column whose length is not 1.
Why not the others
- C. The shear can be undone, yet it is not unitary: its second column has length , so it sends to an unnormalized vector. Being invertible is not enough; a gate must also preserve length.
- D. This projector keeps the part and sends to the zero vector, which is not a state. It cannot be undone: and both come out as . It describes the outcome 0 of a measurement in the 0/1 basis, and a measurement is not a gate.
Check yourself
You know a qubit is in the state . Can a gate turn it into ?
- ANo: only a measurement can turn a superposition into a basis state.
- BYes: the gate does it, since .
- COnly half the time: measure in the 0/1 basis and hope for 0.
- DYes: apply and multiply by .
Hints
- Which gate turns into a basis state?
- A gate is one fixed, invertible map. It can carry one known state anywhere; what it cannot do is send every state to the same place.
Show the answer
Answer: B. Yes: the gate does it, since .
. This is the contrast with your guess: a gate is one fixed, invertible map, so it can carry one known state to (or anywhere else), but it cannot send every state to the same place.
Why not the others
- A. Gates turn superpositions into basis states all the time: , with certainty and no measurement. What a gate cannot do is reset an unknown state, because it would have to send different inputs to the same output.
- C. A measurement gives 0 only half the time, and you would then need after a 1. No measurement is needed here: because the state is known, the gate turns it into every time.
- D. That does give for this one input. But the projector is not unitary, so it is not a gate, and the factor only works because you already knew the input. On the same recipe gives the zero vector.
Aside: every gate from three rotations
Every single-qubit unitary can be written as a global phase times three rotations:
with real , , , . Careful: here and are angles, not the amplitudes of a state. For now you only need the idea that a gate can be any unitary.
5 / 11 · Learn
Order matters
In a circuit diagram time runs left to right: the gate drawn first acts first. In algebra the matrix written next to the ket acts first. So a circuit that applies and then is written
The order changes the answer. Take and on :
These two differ only by an overall sign, because . For and the difference shows up in a measurement: on input , " then " gives , but " then " gives .
Check yourself
Compute .
- A
- B
- C
- D
Hints
- In , which gate stands next to the ket, and so acts first?
- Work outward from the ket: find first, then apply to that result.
Show the answer
Answer: A.
. In the other order : the two products differ by a sign because .
Why not the others
- B. That applies first: . In the gate next to the ket acts first, so and then . Here the slip costs only a sign, but for pairs such as and it changes what you measure.
- C. moves to , and never turns one basis state into the other, so the answer must be a multiple of .
- D. The minus sign is what does to , but by the time acts, has already moved the qubit to : .
Check yourself
A circuit applies , then , then to . Which expression gives its output?
- A
- B
- C
- D
Hints
- Which gate does the qubit meet first, and where must that gate stand in the product?
- The first gate stands next to the ket; each later gate is written to the left of the one before it.
Show the answer
Answer: C.
Read the circuit left to right and write the matrices right to left: .
Why not the others
- A. This writes the gates in the order they appear in the diagram. In algebra the matrix next to the ket acts first, so the first gate, , must stand on the right: . The diagram reads like text, which is why this slip is so common.
- B. Gates applied one after another compose by multiplication, not addition: each gate acts on the output of the one before it.
- D. is in the right place, next to the ket, but and are swapped. After the qubit meets , so comes next to the left, and , the last gate, stands on the far left.
6 / 11 · Explore
Two Hadamards
Predict, then see
Two circuits start from . A: , then , then measure in the 0/1 basis. B: , measure in that basis, , measure again. Over 100 runs, how often does each give 0 at the end?
- AA: all 100 runs. B: about 50.
- BBoth all 100: the second undoes the first whether or not you look in between.
- CA: none, because two gates make an . B: about 50.
- DBoth about 50: randomizes the qubit, and doing it twice leaves it random.
In a sentence or two: why does a measurement between the two gates change the result?
Show what happens
What happens: A. A: all 100 runs. B: about 50.
After one the qubit is in : a definite state, not a coin. The second sends to and to , so the two contributions to cancel and the two contributions to add; this cancellation is interference, and it makes . A measurement in the 0/1 basis in between replaces with or at random, so there is nothing left to interfere. The second then gives or , and the final result is 50/50.
Why not the others
- B. The second undoes the first only if nothing happens in between. A measurement in the 0/1 basis replaces by or ; then gives or , each 50/50 in that basis. Looking changed the state.
- C. is not a "square root of NOT": , not , so circuit A returns the qubit to .
- D. That is the picture of as a coin flip. If it were right, A and B would behave the same, but A gives 0 every time. Only the measurement in B turns the qubit into a coin.
The arithmetic
As matrices:
Check yourself
As a half turn about the axis between and , swaps the and axes of the Bloch sphere. Use that, or multiply the matrices: which single gate equals ?
- A
- B
- C
- D
Hints
- What does do to ? Apply the gates one at a time, starting from the right.
- and . Apply the last , then do the same for and compare with , , and .
Show the answer
Answer: B.
and , which is exactly what does. In the same way .
Why not the others
- A. Test it on : , while .
- C. It is tempting to cancel the two gates, but they are not next to each other, and matrices do not commute in general. Use the sphere: the first swaps the and axes, so a half turn about between two gates acts as a half turn about .
- D. Only copies of a gate standing side by side cancel. Test it on : , so it is not the identity.
7 / 11 · Worked example
Worked example: a gate, column by column
Worked example
H on a general state
Find for , and the probability of outcome 0 when you measure it in the 0/1 basis.
Use linearity
By linearity : the first column of times , plus the second column times .
Add the columns
Check the length: , as a unitary guarantees.
Your turn
Your turn
What is the probability of outcome 0 when is measured in the 0/1 basis? An exact expression or a decimal is fine.
Hints
- Which entry of belongs to ?
- Square its magnitude: .
Show the answer
Answer:
.
Common slips
- : is for the input . The question is about the state after , whose amplitude on is .
- : A common idea is that a Hadamard always produces 50/50 odds. That holds for the inputs and , but this input already leans toward , and moves it closer still. Square the top entry: .
Your turn: same method, new gate
Your turn
Compute and enter the exact amplitudes.
Hints
- What are the two columns of ?
- Column 1 is and column 2 is , so the output is .
Show the answer
Answer:
The columns of are and , so the output is : the vector .
Here is the same method once more, with different numbers.
Another worked example
H on another state
Use linearity
Add the columns
Probabilities
In the 0/1 basis, and . They add to 1, as they must.
The same idea with X
The columns of are and , so it just moves the amplitudes: .
Check yourself
Compute and enter the exact amplitudes.
Hints
- Which column of does multiply, and which does ?
- Linearity: .
- The top entry is and the bottom entry is .
Show the answer
Answer:
By linearity, . With and this is , that is, the vector .
8 / 11 · Practice
Practice
Check yourself
A qubit in goes through and then . Enter the final state.
Hints
- Which gate does the qubit meet first?
- Apply the gates one at a time, starting with the first one in the circuit. As a product the circuit reads right to left.
- After the state is .
Show the answer
Answer:
In algebra the circuit is . Work from the ket outward: , then . The final state is . (Any overall sign is accepted: it is the same physical state.)
Check yourself
Is a valid gate?
- AUnitary: a valid gate
- BNot unitary: a column does not have length 1
- CNot unitary: both columns have length 1, but they are not orthogonal
Hints
- What two things must be true of the columns of a unitary?
- Each column must have length 1, and the two must be orthogonal. For the inner product, conjugate the first column's entries before multiplying.
- Each column has squared length .
Show the answer
Answer: A. Unitary: a valid gate
It is unitary. Each column has squared length . With the conjugate, . Skipping the conjugate would give 1 instead.
Why not the others
- B. Both tests pass here. Each column has squared length . With the conjugate, . Skipping the conjugate would give 1 instead.
- C. Both tests pass here. Each column has squared length . With the conjugate, . Skipping the conjugate would give 1 instead.
Check yourself
Build a circuit that takes to . Any global phase is fine.
Build it in the circuit builder (gates: X, Z, H).
Hints
- Which gate turns a basis state into a state, or back?
- swaps and ; swaps ; swaps .
- One route is then .
Show the answer
One circuit that works: X on q0, then H on q0.
From : , then . Another route is then : , then .
9 / 11 · Explain
Explain it
Explain it
People often say that "randomizes" a qubit. If that were the whole story, why would give with certainty? Explain what actually happens.
Show a model answer
is the definite state , not a coin that has secretly landed. When the second acts, the part contributes to the amplitude of and the part contributes , so they cancel, while the two contributions to add up to 1. Randomness appears only when you measure, and it depends on the basis: gives 50/50 in the 0/1 basis but a certain result in the ± basis.
A good answer covers
- Says that is a definite state with amplitudes (), not a random mixture of 0 and 1.
- Explains that the second makes the contributions to cancel and those to add (interference), so .
- Says that randomness appears only at measurement, and depends on the basis measured in.
10 / 11 · Mastery check
Mastery check
Check yourself
A qubit starts in . You apply , then again, then measure in the 0/1 basis. What is the probability of outcome 0?
- A
- B
- C
- D
Show the answer
Answer: D.
and , so . A measurement in the 0/1 basis then gives 1 with certainty, so .
Why not the others
- A. This treats as a "square root of NOT", as if two of them made an and sent to . They don't: , so the qubit ends in , and the outcome is 1 every time.
- B. A common picture is that randomizes a qubit, so a second leaves it random. But after one the qubit is in the definite state , not a coin, and the second makes the two contributions to cancel. So : the 50/50 appears only if you measure in the 0/1 basis between the gates.
- C. It is tempting to multiply two 50/50 steps, . But a gate does not add randomness step by step: it changes amplitudes, and amplitudes can cancel. Here the cancellation is complete, because .
Check yourself
A gate sends and . Compute and enter its exact amplitudes, keeping any global phase factor (this asks for the vector, not just the physical state).
Show the answer
Answer:
By linearity .
Check yourself
The expression describes a two-gate circuit acting on . Which state comes out, up to an overall sign?
- A
- B
- C
- D
Show the answer
Answer: A.
The gate next to the ket acts first: , then . (Got ? That is the other order.)
Read right to left. First : . Then : . Up to its sign this is .
Why not the others
- B. That reads the product left to right, applying first. The gate next to the ket acts first: , then . In a circuit diagram would be drawn on the left.
- C. Work outward from the ket, one gate at a time: , then .
- D. Work outward from the ket, one gate at a time: , then .
Check yourself
A gate sends to . Which of these could be, up to a global phase?
- A
- B
- C
- D
Show the answer
Answer: C.
and are the columns of . A unitary has orthogonal columns of length 1, and the only state on the list orthogonal to is .
Why not the others
- A. and are the two columns of , and a unitary has orthogonal columns. But , not 0.
- B. and are the two columns of , and a unitary has orthogonal columns. But , not 0.
- D. Then would send both and to the same state, and nothing could undo it: from the output you could not tell which input you had. A unitary keeps orthogonal inputs orthogonal.
Check yourself
Is there a single-qubit gate that turns every input state into , whatever the input was?
- ANo: every gate can be undone, so no gate can send two different inputs to the same output.
- BYes: a suitable fixed sequence of , and .
- CYes: the matrix keeps the part, and you rescale the result.
- DNo: gates never change the probabilities of the measurement outcomes 0 and 1; only measurements do.
Show the answer
Answer: A. No: every gate can be undone, so no gate can send two different inputs to the same output.
Gates are unitary, and a unitary always has an inverse. A gate that sent both and to would have no inverse. Resetting an unknown qubit takes a measurement in the 0/1 basis, followed by if the result was 1.
Why not the others
- B. Each of , and can be undone, so any sequence of them can be undone too. A sequence that sent both and to could not be undone: from the output alone you could not tell which input you had.
- C. Keeping only the part is a natural first idea. But that matrix sends to the zero vector, which is not a state, and the rescaling factor depends on an input you may not know. A gate must keep every state normalized and be undoable, so it can never send two different inputs to the same output.
- D. Gates change probabilities all the time: turns a certain outcome 0 into a 50/50 split. The real obstacle is different: a gate is invertible, so it cannot merge two different inputs into one output.
11 / 11 · Recap
Recap
From memory
Before reading the summary, write down what you remember. Pulling it back from memory is what makes it last.
How do you find the matrix of a gate from what it does to and , and how do you then apply it to ?
Show the key points
- Column 1 is the image of ; column 2 is the image of .
- By linearity the output is times column 1 plus times column 2.
- Equivalently, each output entry is a row of the matrix times the input column.
What makes a matrix a valid gate, and why can no gate reset every state to ?
Show the key points
- : columns of length 1 that are orthogonal (conjugate before multiplying).
- A unitary preserves normalization and can be undone by .
- A reset would send different inputs to the same output, which cannot be undone; resetting needs a measurement.
Why does measuring in the 0/1 basis give the outcome 0 every time, and what changes if you measure between the two gates?
Show the key points
- is a definite state, not a coin.
- The second makes the contributions to ( and ) cancel: interference, so .
- A measurement in the 0/1 basis in between replaces by or , so the final result is 50/50.
Key ideas
A gate acts linearly, so what it does to and fixes everything. Its matrix has those two images as its columns.
swaps the amplitudes, flips the sign of the amplitude, and sends and . On the Bloch sphere each is a half turn: about , about , and about the axis between and .
Every gate is unitary, , and every unitary is a gate. A unitary keeps states normalized and can always be undone, so no gate resets an unknown state.
Circuits run left to right; matrix products act right to left. " then " is . Most gates do not commute: , and while .
because the second makes amplitudes cancel (interference). Sandwiching between two gates swaps and : , .
Go further
Free resources for when you want more than this lesson covers.
- Linear transformations and matrices3Blue1Brown · Video
Animates why a matrix’s columns are where the basis vectors land, the rule used here to build each gate’s matrix.
- Quantum logic gateWikipedia · Article
Goes beyond X, Z and H to the Y, phase-shift, swap and Toffoli gates, and to which gate sets can build every circuit.
- Quirk: a quantum circuit simulatorCraig Gidney · Interactive
A free in-browser circuit simulator: drag gates onto wires and watch Bloch spheres and amplitudes change as you build.
Math refreshers
The toolkit topics this lesson leans on.
- Matrices acting on statesGates are matrices; circuit order vs matrix order
- Inner products and bases⟨φ|ψ⟩, orthogonality, and |⟨φ|ψ⟩|² as a probability