Skip to the content
Kets & Gates homeOpen the app

Lesson 6: Many bits: tensor products, CNOT and reversible logic

Combine qubits with ⊗, flip bits with CNOT and Toffoli, and see why every gate must be reversible

about 35 min15 partsbest after lesson 4

Start the interactive lesson

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 / 15 · Learn

Before you start

Every lesson so far has used one qubit. This one puts several together, first as ordinary bits and then in superposition, and adds gates that act on two or three of them at once.

By the end of this lesson you can:

  • write a multi-qubit product state as a column vector in this course’s order, top qubit first;
  • say how many amplitudes nn qubits need, and how many bits one measurement returns;
  • find the odds and the leftover state when you measure one qubit of two;
  • apply CNOT and Toffoli to basis states, and read a circuit’s time order against its operator order;
  • explain why AND can’t be a quantum gate as it stands, and how Toffoli gets around that.

Check yourself

A warm-up: make a guess before reading on. The lesson comes back to it.

A general state of three qubits: how many complex amplitudes does it take to write down, and how many bits do you get when you measure all three qubits in the 0/1 basis?

  1. A8 amplitudes; 8 bits
  2. B3 amplitudes; 3 bits
  3. C8 amplitudes; 3 bits
  4. D6 amplitudes; 3 bits
Show the answer

Answer: C. 8 amplitudes; 3 bits

Each of the 23=82^{3} = 8 strings is a basis state with its own amplitude, but one measurement picks out one string: 3 bits.

Why not the others

  • A. A common idea is that every amplitude gets read out. One shot of the measurement returns one 3-bit string, so 3 bits. The 8 amplitudes set the odds of the 8 possible strings; they never come out as data.
  • B. One number per qubit would describe a classical register, where each bit has a definite value. A quantum register gives an amplitude to every string: 23=82^{3} = 8 numbers. Even one qubit needs two, α\alpha and β\beta.
  • D. Adding 2 per qubit treats the qubits as separate lists. The basis states are the strings 000 to 111, and there are 23=82^{3} = 8 of them, each with its own amplitude. Dimensions multiply under ⊗\tp.

Check yourself

A warm-up: make a guess before reading on. The lesson comes back to it.

Every quantum gate is reversible. Can a quantum computer compute AND(a,b)\mathrm{AND}(a, b) of two bits?

  1. ANo. AND is irreversible, so quantum circuits cannot compute it.
  2. BYes. Apply an AND gate to the two qubits, as in a classical chip.
  3. COnly approximately: the answer comes out right with some probability below 1.
  4. DYes, if the circuit keeps aa and bb and writes the answer into an extra bit.
Show the answer

Answer: D. Yes, if the circuit keeps aa and bb and writes the answer into an extra bit.

Keep aa and bb and write the answer into a third bit: (a,b,c)↦(a,b,c⊕AND(a,b))(a, b, c)\mapsto(a, b, c\oplus \mathrm{AND}(a, b)) is a permutation of the eight strings. That is exactly the Toffoli gate. With c=0c = 0 the third bit ends up holding AND(a,b)\mathrm{AND}(a, b).

Why not the others

  • A. This takes "gates must be reversible" one step too far. The function AND can still be computed: keep aa and bb and XOR the answer into an extra bit, (a,b,c)↦(a,b,c⊕AND(a,b))(a, b, c)\mapsto(a, b, c\oplus \mathrm{AND}(a, b)). That is a permutation of bit strings, so it is reversible. Only a gate that throws its inputs away is ruled out.
  • B. A classical AND gate turns two bits into one and loses information: three of its four inputs (00, 01, 10) all give 0. A quantum gate is unitary, so it must be undoable, and no rule can undo a collision like that. Classical chips may lose information; quantum gates may not.
  • C. Nothing random is needed. On basis-state inputs a reversible circuit is a permutation of bit strings and gives the answer with certainty. Randomness only enters if you feed in superpositions and then measure.

2 / 15 · Learn

Part A · Bits as vectors

Refresher: Tensor products Kronecker products of vectors, if you want a refresher first.

Start with ordinary bits. Write a bit that is 0 as ∣0⟩=[10]\ket0 = \begin{bmatrix}1\\0\end{bmatrix} and a bit that is 1 as ∣1⟩=[01]\ket1 = \begin{bmatrix}0\\1\end{bmatrix}. A pair of bits x,yx, y becomes the tensor product ∣x⟩⊗∣y⟩\ket x\tp\ket y, also written ∣x⟩∣y⟩\ket x\ket y or ∣xy⟩\ket{xy}. To build it, multiply each entry of the first column by the whole second column, and stack the results:

∣1⟩⊗∣0⟩=[01]⊗[10]=[0⋅10⋅01⋅11⋅0]=[0010].\ket1\tp\ket0 = \begin{bmatrix}0\\1\end{bmatrix}\tp\begin{bmatrix}1\\0\end{bmatrix} = \begin{bmatrix}0\cdot1\\0\cdot0\\1\cdot1\\1\cdot0\end{bmatrix} = \begin{bmatrix}0\\0\\1\\0\end{bmatrix}.

This column is ∣10⟩\ket{10}. The four slots are labelled 00, 01, 10, 11: binary counting, with the first label (the top wire of a circuit) as the most significant bit. A definite string of bits always gives a single 1, in the slot named by that string.

Check yourself

Write ∣0⟩⊗∣1⟩\ket0\tp\ket1 as a column vector, slots in the order 00, 01, 10, 11.

Hints
  1. Read the factors left to right, first factor first: which two-bit string do they spell?
  2. They spell 01. Which entry of the column is slot 01, counting 00, 01, 10, 11?
  3. Slot 01 is the second entry: put the 1 there and 0 everywhere else.
Show the answer

Answer: ∣01⟩|01\rangle

Top entry of ∣0⟩\ket0 is 1, so the first half is ∣1⟩=(0,1)\ket1 = (0, 1) and the second half is 0⋅∣1⟩0\cdot\ket1: (0,1,0,0)=∣01⟩(0, 1, 0, 0) = \ket{01}.

Check yourself

Three bits in the state ∣110⟩=∣1⟩⊗∣1⟩⊗∣0⟩\ket{110} = \ket1\tp\ket1\tp\ket0 give a column of 8 entries, with slots 000, 001, …, 111 in binary order. Where is the 1?

  1. AIn the 6th entry, slot 101
  2. BIn the 4th entry, slot 011
  3. CIn the 7th entry, slot 110
  4. DThe column has only 3 entries: 1, 1, 0
Show the answer

Answer: C. In the 7th entry, slot 110

Slots run 000, 001, 010, 011, 100, 101, 110, 111. The string 110 is binary for 6, so the 1 is in slot 6, the 7th entry.

Why not the others

  • A. Binary 110 is 6, but the slots start at 000 = 0, so slot 6 is the 7th entry; the 6th entry is slot 101. Read the slot label rather than counting positions.
  • B. That reads the string from the right. The first label, the top wire, is the most significant bit, so ∣110⟩\ket{110} sits in slot 110. That is binary for 6, the 7th entry when you start counting at slot 000.
  • D. Three bits need 2×2×2=82\times2\times2 = 8 slots, one for each string 000 … 111, not one slot per bit. A definite string puts a single 1 in its own slot and 0 everywhere else.

3 / 15 · Learn

Part A · Superposed factors: the ⊗ grid

Nothing changes when the factors are superpositions. If the top qubit is a0∣0⟩+a1∣1⟩a_0\ket0 + a_1\ket1 and the bottom one is b0∣0⟩+b1∣1⟩b_0\ket0 + b_1\ket1, expanding the product term by term gives

(a0∣0⟩+a1∣1⟩)⊗(b0∣0⟩+b1∣1⟩)=a0b0∣00⟩+a0b1∣01⟩+a1b0∣10⟩+a1b1∣11⟩.\begin{aligned} &(a_0\ket0+a_1\ket1)\tp(b_0\ket0+b_1\ket1)\\ &\quad= a_0b_0\ket{00}+a_0b_1\ket{01}\\ &\qquad+a_1b_0\ket{10}+a_1b_1\ket{11}. \end{aligned}

Each amplitude is the top qubit’s amplitude for the first label times the bottom qubit’s amplitude for the second label: αxy=axby\alpha_{xy} = a_x b_y. Products, never sums. The basis states that appear do not change; only the amplitudes do.

Check yourself

Write ∣+⟩⊗∣1⟩\ket+\tp\ket1 as a column vector (order 00, 01, 10, 11).

Hints
  1. Which basis states have bottom label 1?
  2. Each amplitude is (top amplitude) × (bottom amplitude) for that slot’s two labels.
  3. The bottom factor ∣1⟩\ket1 has b0=0b_0 = 0, so slots 00 and 10 are 0.
Show the answer

Answer: 12∣01⟩+12∣11⟩\frac{1}{\sqrt{2}}|01\rangle + \frac{1}{\sqrt{2}}|11\rangle

12(∣0⟩+∣1⟩)∣1⟩=12(∣01⟩+∣11⟩)\tfrac{1}{\sqrt2}(\ket0+\ket1)\ket1 = \tfrac{1}{\sqrt2}(\ket{01}+\ket{11}): the entries are (0,12,0,12)(0, \tfrac{1}{\sqrt2}, 0, \tfrac{1}{\sqrt2}).

Check yourself

The top qubit is in 32∣0⟩+12∣1⟩\tfrac{\sqrt3}{2}\ket0 + \tfrac12\ket1 and the bottom qubit in 12(∣0⟩−i∣1⟩)\tfrac{1}{\sqrt2}(\ket0 - i\ket1). What is the amplitude of ∣01⟩\ket{01} in the two-qubit state?

α01=  ?\alpha_{01} = \;?

Hints
  1. Which factor supplies the first label, 0, and which supplies the second, 1?
  2. For a product state, αxy=axby\alpha_{xy} = a_x b_y.
  3. Multiply 32\tfrac{\sqrt3}{2} by −i2-\tfrac{i}{\sqrt2}.
Show the answer

Answer: α01=−64 i\alpha_{01} = -\frac{\sqrt{6}}{4}\,i

α01=a0b1=32⋅(−i2)=−i64≈−0.612i\alpha_{01} = a_0 b_1 = \tfrac{\sqrt3}{2}\cdot\left(-\tfrac{i}{\sqrt2}\right) = -\tfrac{i\sqrt6}{4} \approx -0.612i.

Common slips

  • 24\frac{\sqrt{2}}{4}: That is a1b0a_1 b_0, the amplitude of ∣10⟩\ket{10}. In ∣01⟩\ket{01} the first label belongs to the top qubit: you need the top qubit’s ∣0⟩\ket0 amplitude times the bottom qubit’s ∣1⟩\ket1 amplitude.
  • 32−12i\frac{\sqrt{3}}{2}-\frac{1}{\sqrt{2}}i: Adding the two amplitudes treats the qubits as separate lists. In a product state they multiply: 32×(−i2)\tfrac{\sqrt3}{2}\times\left(-\tfrac{i}{\sqrt2}\right). A quick check: a sum like this has size above 1, and no amplitude can.
  • −64-\frac{\sqrt{6}}{4}: Right size, but the −i-i from the bottom factor went missing. The bottom qubit’s ∣1⟩\ket1 amplitude is −i/2-i/\sqrt2, and the whole factor carries into the product.

4 / 15 · Learn

Part A · 2ⁿ amplitudes, n bits out

Each qubit you add doubles the list of basis strings: 2 for one qubit, 4 for two, 2n2^n for nn. A general nn⁠-qubit state needs one complex amplitude per string. Most states are not products, so you cannot shrink the list to two numbers per qubit (Lesson 7 shows why). Take n=500n = 500: 25002^{500} is roughly 1015010^{150}, far more numbers than there are atoms in the observable universe.

Measurement does not read that list out. Measuring all nn qubits in the 0/1 basis returns one nn⁠-bit string xx, with probability ∣αx∣2\abs{\alpha_x}^2, and leaves the register in ∣x⟩\ket{x}. You get nn bits per run, never 2n2^n numbers.

Check yourself

A register has 10 qubits. How many complex amplitudes does a general state of it need?

Hints
  1. How many 10-bit strings are there?
  2. Each added qubit doubles the number of basis states.
  3. Compute 2102^{10}.
Show the answer

Answer: 10241024

210=10242^{10} = 1024: one amplitude for each 10-bit string.

Common slips

  • 2020: That is 2 per qubit, added up. Dimensions multiply: the basis states are the 10-bit strings, each with its own amplitude. How many 10-bit strings are there?
  • 1010: One number per qubit would do for a classical register. A quantum state gives an amplitude to every 10-bit string, and each added qubit doubles the number of strings.
  • 100100: That is 10210^2. Each added qubit doubles the number of basis strings, rather than adding to it or squaring it: one qubit has 2, two have 4, three have 8.

Check yourself

You measure all 10 qubits of that register in the 0/1 basis, once. How many bits of output do you get?

Hints
  1. What does one shot of the figure above return: eight numbers, or something shorter?
  2. Measuring one qubit in the 0/1 basis gives one bit, 0 or 1.
  3. One bit from each of the ten qubits.
Show the answer

Answer: 1010

One run returns one 10-bit string. The 1024 amplitudes set the odds of each string.

Common slips

  • 10241024: That counts amplitudes, not output. One measurement returns one 10-bit string, such as 0110100011. The 1024 amplitudes decide how likely each string is, but they never come out as data.
  • 11: One bit per qubit, not one in total: measuring all 10 qubits gives a 10-bit string.

5 / 15 · Learn

Part A · Measuring one qubit of two

You can also measure just one qubit. Lay the four amplitudes out as a 2×22\times2 grid, rows for the top qubit and columns for the bottom one. Measuring the top qubit in the 0/1 basis gives 0 with probability ∣α00∣2+∣α01∣2\abs{\alpha_{00}}^2 + \abs{\alpha_{01}}^2, the total of row 0. If you get 0, row 1 is wiped out and row 0 is rescaled so the state is normalized again:

∣ψ′⟩=α00∣00⟩+α01∣01⟩∣α00∣2+∣α01∣2.\ket{\psi'} = \frac{\alpha_{00}\ket{00} + \alpha_{01}\ket{01}}{\sqrt{\abs{\alpha_{00}}^2 + \abs{\alpha_{01}}^2}}.

For the bottom qubit, use columns instead of rows.

Check yourself

Take ∣ψ⟩=12∣00⟩+i2∣01⟩+12∣10⟩\ket\psi = \tfrac12\ket{00} + \tfrac{i}{\sqrt2}\ket{01} + \tfrac12\ket{10}. You measure only the top qubit, in the 0/1 basis. What is the probability that it gives 0?

P(top=0)=  ?P(\text{top} = 0) = \;?

Hints
  1. Which two basis states have the top (first) label equal to 0?
  2. Add ∣α∣2\abs{\alpha}^2 over that row.
  3. ∣12∣2+∣i2∣2=14+…\abs{\tfrac12}^2 + \abs{\tfrac{i}{\sqrt2}}^2 = \tfrac14 + \ldots
Show the answer

Answer: P(top=0)=34P(\text{top} = 0) = \frac{3}{4}

Row 0: ∣12∣2+∣i2∣2=14+12=34\abs{\tfrac12}^2 + \abs{\tfrac{i}{\sqrt2}}^2 = \tfrac14 + \tfrac12 = \tfrac34.

Common slips

  • −14-\frac{1}{4}: A probability can’t be negative. Squaring i2\tfrac{i}{\sqrt2} itself brings in i2=−1i^2 = -1. A probability uses the squared size, ∣α∣2=αα∗\abs{\alpha}^2 = \alpha\alpha^*, which is never negative. Redo the sum with squared sizes.
  • 14\frac{1}{4}: 14\tfrac14 is the other row, ∣α10∣2\abs{\alpha_{10}}^2 (the top qubit giving 1), or ∣α00∣2\abs{\alpha_{00}}^2 on its own. For 0 you need both entries of row 0: ∣α00∣2+∣α01∣2\abs{\alpha_{00}}^2 + \abs{\alpha_{01}}^2.
  • 12\frac{1}{2}: That adds a column, ∣α00∣2+∣α10∣2\abs{\alpha_{00}}^2 + \abs{\alpha_{10}}^2, which belongs to the bottom qubit. The top qubit is the first label, so add the row: ∣α00∣2+∣α01∣2\abs{\alpha_{00}}^2 + \abs{\alpha_{01}}^2.

Check yourself

The top qubit gave 0. What is the two-qubit state now?

Hints
  1. Which entries are wiped out by the result 0?
  2. Keep row 0 and divide by P=3/4\sqrt{P} = \sqrt{3/4}.
Show the answer

Answer: 13∣00⟩+26 i∣01⟩\frac{1}{\sqrt{3}}|00\rangle + \frac{2}{\sqrt{6}}\,i|01\rangle

Keep row 0 and divide by 3/4=32\sqrt{3/4} = \tfrac{\sqrt3}{2}: 13∣00⟩+i23 ∣01⟩\tfrac{1}{\sqrt3}\ket{00} + i\sqrt{\tfrac23}\,\ket{01}. Check: 13+23=1\tfrac13 + \tfrac23 = 1.

6 / 15 · Learn

Part B · CNOT: XOR that keeps its input

Refresher: Bits, XOR and bit strings XOR and bit strings, if ⊕\oplus is new to you.

The basic two-qubit gate is the controlled-NOT, or CNOT. It has a control qubit (top wire, drawn •) and a target qubit (drawn ⊕). On basis states it flips the target exactly when the control is 1:

∣A,B⟩ → ∣A, B⊕A⟩,\ket{A, B}\ \to\ \ket{A,\ B\oplus A},

where ⊕\oplus is addition mod 2 (XOR). So ∣10⟩→∣11⟩\ket{10}\to\ket{11} and ∣11⟩→∣10⟩\ket{11}\to\ket{10}, while ∣00⟩\ket{00} and ∣01⟩\ket{01} stay put. Classical XOR turns two bits into one. CNOT keeps AA as well, and that is why it can be undone: apply it twice and B⊕A⊕A=BB\oplus A\oplus A = B.

Check yourself

Which matrix is UCNU_{CN} (control on top) in the basis order 00, 01, 10, 11? Column kk is the image of the kk⁠-th basis state.

  1. A[1000010000010010]\begin{bmatrix}1&0&0&0\\0&1&0&0\\0&0&0&1\\0&0&1&0\end{bmatrix}
  2. B[0100100000100001]\begin{bmatrix}0&1&0&0\\1&0&0&0\\0&0&1&0\\0&0&0&1\end{bmatrix}
  3. C[1000000100100100]\begin{bmatrix}1&0&0&0\\0&0&0&1\\0&0&1&0\\0&1&0&0\end{bmatrix}
  4. D[100001000010000−1]\begin{bmatrix}1&0&0&0\\0&1&0&0\\0&0&1&0\\0&0&0&-1\end{bmatrix}
Show the answer

Answer: A. [1000010000010010]\begin{bmatrix}1&0&0&0\\0&1&0&0\\0&0&0&1\\0&0&1&0\end{bmatrix}

∣00⟩\ket{00} and ∣01⟩\ket{01} map to themselves; ∣10⟩↦∣11⟩\ket{10}\mapsto\ket{11} and ∣11⟩↦∣10⟩\ket{11}\mapsto\ket{10}, so the last two columns of the identity are exchanged.

Why not the others

  • B. This swaps ∣00⟩\ket{00} and ∣01⟩\ket{01}, so it flips the bottom bit when the top bit is 0. CNOT acts when the control is 1, so the first two slots stay put.
  • C. This one swaps ∣01⟩\ket{01} and ∣11⟩\ket{11}: it flips the top bit when the bottom bit is 1. That is CNOT with control and target exchanged. With the control on top, the pair that trades places is ∣10⟩\ket{10} and ∣11⟩\ket{11}, the last two slots.
  • D. This only changes the sign of ∣11⟩\ket{11} (it is the controlled-ZZ gate) and moves nothing. CNOT moves basis states: ∣10⟩\ket{10} and ∣11⟩\ket{11} trade places, so its matrix has 1s off the diagonal.

Check yourself

Now put the control on the bottom wire and the ⊕ on the top wire. What does this CNOT do to ∣01⟩\ket{01}?

  1. A∣10⟩\ket{10}
  2. B∣11⟩\ket{11}
  3. C∣00⟩\ket{00}
  4. D∣01⟩\ket{01}, unchanged
Show the answer

Answer: B. ∣11⟩\ket{11}

The control is the bottom bit, which is 1, so the top (target) bit flips: ∣01⟩→∣11⟩\ket{01}\to\ket{11}.

Why not the others

  • A. That exchanges the two bits. One CNOT changes only its target bit. Exchanging two bits takes three CNOTs, as the next segment shows.
  • C. That flips the control. On a basis input a CNOT never changes its control bit; it flips the target bit, and only when the control bit is 1.
  • D. That treats the top bit as the control. Here the control is the bottom bit, and in ∣01⟩\ket{01} the bottom bit is 1, so the top bit flips.

7 / 15 · Learn

Part B · Time order and operator order

Reading a circuit takes three conventions. Each wire is a qubit, and the top wire is the first label. Time runs left to right. But when you write the circuit as operators, the order reverses: a circuit that applies AA and then BB is the operator BABA, because the matrix written next to the ket acts first. A one-qubit gate UU on the top wire of two is U⊗IU\tp I; on the bottom wire it is I⊗UI\tp U.

Check yourself

A two-qubit circuit applies UCNU_{CN} (control on top) first and then XX on the top wire. Which operator does the whole circuit apply?

  1. AUCN (X⊗I)U_{CN}\,(X\tp I)
  2. B(X⊗I) UCN(X\tp I)\,U_{CN}
  3. CUCN+X⊗IU_{CN} + X\tp I
  4. D(I⊗X) UCN(I\tp X)\,U_{CN}
Show the answer

Answer: B. (X⊗I) UCN(X\tp I)\,U_{CN}

Time runs left to right, but operators act right to left: the first gate sits next to the ket. XX on the top wire is X⊗IX\tp I, so the circuit is (X⊗I)UCN(X\tp I)U_{CN}.

Why not the others

  • A. That is the circuit order written left to right. The matrix next to the ket acts first, so the first gate goes on the right. You can check that the two differ: on ∣00⟩\ket{00}, (X⊗I)UCN(X\tp I)U_{CN} gives ∣10⟩\ket{10}, while UCN(X⊗I)U_{CN}(X\tp I) gives ∣11⟩\ket{11}.
  • C. Gates in sequence multiply; they never add. A sum of two unitaries is usually not even unitary.
  • D. I⊗XI\tp X acts on the bottom wire. The first factor of a tensor product belongs to the top wire, so XX on the top wire is X⊗IX\tp I.

Three CNOTs, the middle one upside down (control on the bottom), swap two qubits. Follow the bits:

∣a,b⟩→∣a, a⊕b⟩→∣b, a⊕b⟩→∣b, a⟩.\ket{a,b}\to\ket{a,\ a\oplus b}\to\ket{b,\ a\oplus b}\to\ket{b,\ a}.

The middle CNOT XORs the bottom bit into the top one, and a⊕(a⊕b)=ba\oplus(a\oplus b) = b. The last CNOT XORs the new top bit into the bottom one: (a⊕b)⊕b=a(a\oplus b)\oplus b = a.

Check yourself

Trace ∣10⟩\ket{10} through the swap circuit: CNOT (control top), then CNOT (control bottom), then CNOT (control top). Which list gives the state after each gate?

  1. A∣11⟩\ket{11}, then ∣01⟩\ket{01}, then ∣00⟩\ket{00}
  2. B∣01⟩\ket{01}, then ∣01⟩\ket{01}, then ∣01⟩\ket{01}
  3. C∣11⟩\ket{11}, then ∣01⟩\ket{01}, then ∣01⟩\ket{01}
  4. D∣11⟩\ket{11}, then ∣10⟩\ket{10}, then ∣11⟩\ket{11}
Show the answer

Answer: C. ∣11⟩\ket{11}, then ∣01⟩\ket{01}, then ∣01⟩\ket{01}

∣10⟩→∣11⟩\ket{10}\to\ket{11} (top is 1, flip the bottom) →∣01⟩\to\ket{01} (bottom is 1, flip the top) →∣01⟩\to\ket{01} (top is 0, nothing). The bits have traded places: 10 became 01.

Why not the others

  • A. In the last step the control (top) bit is 0, so nothing happens and ∣01⟩\ket{01} stays ∣01⟩\ket{01}. A CNOT acts on its target only when its control bit is 1.
  • B. A single CNOT can’t swap: it changes only its target bit. The first CNOT turns ∣10⟩\ket{10} into ∣11⟩\ket{11}; the swap is complete only after all three.
  • D. That runs the middle CNOT with its control still on top. In the swap circuit the middle CNOT is flipped: the bottom bit controls and the top bit is the target, so ∣11⟩→∣01⟩\ket{11}\to\ket{01}.

Check yourself

Build the swap yourself, using only CNOTs. Click a wire to place a CNOT with its control there; click a placed CNOT to flip its direction. The truth table shows what your circuit does to each basis input.

Build it in the circuit builder (gates: CNOT).

Hints
  1. How many CNOTs does the swap use, and which one is upside down?
  2. Control on top, then control on the bottom, then control on top again.
Show the answer

One circuit that works: CNOT q0→q1, then CNOT q1→q0, then CNOT q0→q1.

CNOT (control top), CNOT (control bottom), CNOT (control top): every input ∣ab⟩\ket{ab} comes out as ∣ba⟩\ket{ba}. Starting with the control on the bottom works too, since the circuit is symmetric.

8 / 15 · Explore

Part B · Can the control qubit change?

Predict, then see

So far CNOT has only ever flipped its target. Now feed it superpositions: control ∣+⟩\ket+ on top, target ∣−⟩\ket- below. Predict the output.

  1. A∣−⟩∣−⟩\ket-\ket-: the control changes and the target does not.
  2. B∣+⟩∣+⟩\ket+\ket+: the control is partly 1, so the target flips.
  3. CAn entangled state: CNOT on a superposition always entangles.
  4. D∣+⟩∣−⟩\ket+\ket-: the control never changes, and a ∣+⟩\ket+ control is not definitely 1.

In a sentence or two: a CNOT only ever applies XX to its target. Why did the control change here?

Show what happens

What happens: A. ∣−⟩∣−⟩\ket-\ket-: the control changes and the target does not.

Write the control in the 0/1 basis: 12(∣0⟩∣−⟩+∣1⟩∣−⟩)\tfrac{1}{\sqrt2}(\ket0\ket- + \ket1\ket-). CNOT leaves the first term alone and applies XX to the target in the second, and X∣−⟩=−∣−⟩X\ket- = -\ket-. The result is 12(∣0⟩−∣1⟩)∣−⟩=∣−⟩∣−⟩\tfrac{1}{\sqrt2}(\ket0 - \ket1)\ket- = \ket-\ket-: the target is untouched and the control picked up the sign. “The control never changes” is guaranteed only when the control is in a basis state.

Why not the others

  • B. Flipping ∣−⟩\ket- does not give ∣+⟩\ket+: X∣−⟩=−∣−⟩X\ket- = -\ket-, the same state with a sign. Where that sign ends up is the whole story.
  • C. CNOT can entangle (Lesson 7 shows how), but not always. Here the output factors as ∣−⟩∣−⟩\ket-\ket-, one state for each qubit.
  • D. The rule “the control never changes” comes from the truth table, which lists basis inputs only. Expand the input in the 0/1 basis and apply CNOT term by term, and a minus sign lands on the control’s ∣1⟩\ket1 term.
Why a sign can change the control (open after the experiment)

For a basis-state control the sign is harmless: UCN∣1⟩∣−⟩=−∣1⟩∣−⟩U_{CN}\ket1\ket- = -\ket1\ket-, which differs from ∣1⟩∣−⟩\ket1\ket- only by a global phase. In a superposition the sign multiplies only the ∣1⟩\ket1 branch, so it becomes a relative phase between the control’s ∣0⟩\ket0 and ∣1⟩\ket1, and that turns ∣+⟩\ket+ into ∣−⟩\ket-. This effect is called phase kickback. Lesson 7 builds on it: which targets kick a sign back, which leave the control alone, and which entangle the pair. Deutsch’s algorithm (Lesson 9) runs on it.

Check yourself

Same CNOT (control on top), new input: control ∣−⟩\ket-, target ∣−⟩\ket-. What comes out?

  1. A∣+⟩∣+⟩\ket+\ket+
  2. B∣−⟩∣+⟩\ket-\ket+
  3. C∣−⟩∣−⟩\ket-\ket-, unchanged
  4. D∣+⟩∣−⟩\ket+\ket-
Hints
  1. Write the control ∣−⟩\ket- in the 0/1 basis first.
  2. Only the control’s ∣1⟩\ket1 term gets XX on the target, and X∣−⟩=−∣−⟩X\ket- = -\ket-.
Show the answer

Answer: D. ∣+⟩∣−⟩\ket+\ket-

Expand the control: 12(∣0⟩−∣1⟩)∣−⟩\tfrac{1}{\sqrt2}(\ket0 - \ket1)\ket-. CNOT turns the second term into −∣1⟩(−∣−⟩)=+∣1⟩∣−⟩-\ket1(-\ket-) = +\ket1\ket-, giving 12(∣0⟩+∣1⟩)∣−⟩=∣+⟩∣−⟩\tfrac{1}{\sqrt2}(\ket0 + \ket1)\ket- = \ket+\ket-.

Why not the others

  • A. Only one thing changes. The target stays ∣−⟩\ket-, because XX only multiplies it by −1-1; that −1-1 is what flips the control.
  • B. The target ∣−⟩\ket- is not flipped to ∣+⟩\ket+: X∣−⟩=−∣−⟩X\ket- = -\ket-. The sign lands on the control’s ∣1⟩\ket1 term instead.
  • C. The control changes here too. Term by term: 12(∣0⟩∣−⟩−∣1⟩∣−⟩)→12(∣0⟩∣−⟩+∣1⟩∣−⟩)\tfrac{1}{\sqrt2}(\ket0\ket- - \ket1\ket-)\to\tfrac{1}{\sqrt2}(\ket0\ket- + \ket1\ket-), because X∣−⟩=−∣−⟩X\ket- = -\ket- flips the sign of the second term. That is ∣+⟩∣−⟩\ket+\ket-.

9 / 15 · Worked example

Part B · Worked example: CNOT shuffles slots

Worked example

CNOT on a product state, slot by slot

CNOT only moves basis states around, so on a column vector it just shuffles entries. Here it acts on ∣1⟩⊗(35∣0⟩+45∣1⟩)\ket1\tp\left(\tfrac35\ket0 + \tfrac45\ket1\right), control on top.

  1. Build the vector

    The top factor is (0,1)(0, 1), the bottom factor (35,45)(\tfrac35, \tfrac45). The top qubit’s ∣0⟩\ket0 amplitude is 0, so slots 00 and 01 are 0; its ∣1⟩\ket1 amplitude is 1, so slots 10 and 11 copy the bottom factor: (0, 0, 35, 45)\left(0,\ 0,\ \tfrac35,\ \tfrac45\right).

  2. Shuffle

    UCNU_{CN} fixes ∣00⟩\ket{00} and ∣01⟩\ket{01} and exchanges ∣10⟩↔∣11⟩\ket{10}\leftrightarrow\ket{11}. So the amplitude in slot 10 moves to slot 11 and the one in slot 11 moves to slot 10: (0, 0, 45, 35)\left(0,\ 0,\ \tfrac45,\ \tfrac35\right).

  3. Read it back

    That is ∣1⟩⊗(45∣0⟩+35∣1⟩)\ket1\tp\left(\tfrac45\ket0 + \tfrac35\ket1\right). With the control definitely 1, the target simply got an XX. Multiplying by the matrix UCNU_{CN} gives the same result; the shuffle is a faster way to do that product.

  4. Your turn

    Now the control is the bottom wire and the ⊕ is on the top wire. The input is (32∣0⟩+12∣1⟩)⊗∣1⟩\left(\tfrac{\sqrt3}{2}\ket0 + \tfrac12\ket1\right)\tp\ket1.

    Your turn

    Build the input vector, decide which slots this CNOT exchanges, and enter the output (order 00, 01, 10, 11).

    Hints
    1. Which basis states have the control (bottom) bit equal to 1?
    2. Those states get their top bit flipped: ∣01⟩↔∣11⟩\ket{01}\leftrightarrow\ket{11}.
    Show the answer

    Answer: 12∣01⟩+32∣11⟩\frac{1}{2}|01\rangle + \frac{\sqrt{3}}{2}|11\rangle

    Input (0,32,0,12)(0, \tfrac{\sqrt3}{2}, 0, \tfrac12). Exchanging slots 01 and 11 gives (0,12,0,32)=(12∣0⟩+32∣1⟩)⊗∣1⟩(0, \tfrac12, 0, \tfrac{\sqrt3}{2}) = \left(\tfrac12\ket0 + \tfrac{\sqrt3}{2}\ket1\right)\tp\ket1: the top qubit got an XX.

Here is one more worked example, with the control on the bottom wire.

Another worked example

Control on the bottom wire

  1. Build the vector

    Input (35∣0⟩+45∣1⟩)⊗∣1⟩\left(\tfrac35\ket0 + \tfrac45\ket1\right)\tp\ket1. The bottom factor is ∣1⟩\ket1, so only slots whose second label is 1 are nonzero: slot 01 gets 35⋅1\tfrac35\cdot1 and slot 11 gets 45⋅1\tfrac45\cdot1. The vector is (0, 35, 0, 45)\left(0,\ \tfrac35,\ 0,\ \tfrac45\right).

  2. Shuffle

    With the control on the bottom wire, a basis state has its top bit flipped when its bottom bit is 1: ∣01⟩↔∣11⟩\ket{01}\leftrightarrow\ket{11}, while ∣00⟩\ket{00} and ∣10⟩\ket{10} stay. Exchange entries 2 and 4: (0, 45, 0, 35)\left(0,\ \tfrac45,\ 0,\ \tfrac35\right).

  3. Read it back

    That is (45∣0⟩+35∣1⟩)⊗∣1⟩\left(\tfrac45\ket0 + \tfrac35\ket1\right)\tp\ket1: the top qubit got an XX, because its control was definitely 1.

Check yourself

A CNOT with its control on the top wire acts on ∣1⟩⊗(12∣0⟩−32∣1⟩)\ket1\tp\left(\tfrac12\ket0 - \tfrac{\sqrt3}{2}\ket1\right). Enter the output vector in the order 00, 01, 10, 11.

Hints
  1. Which bit is the control, and in which slots is it 1?
  2. Those slots trade places in pairs that differ only in the target bit.
Show the answer

Answer: −32∣10⟩+12∣11⟩-\frac{\sqrt{3}}{2}|10\rangle + \frac{1}{2}|11\rangle

The input vector is (0, 0, 12, −32)\left(0,\ 0,\ \tfrac12,\ -\tfrac{\sqrt3}{2}\right). The control on top exchanges slots 10 and 11, giving (0, 0, −32, 12)\left(0,\ 0,\ -\tfrac{\sqrt3}{2},\ \tfrac12\right): the target qubit got an XX.

10 / 15 · Learn

Part B · Gates must be reversible

Every quantum gate is unitary, and a unitary always has an inverse, U†U^\dagger. So a gate can never send two different inputs to the same output: if it did, nothing could tell them apart afterwards to undo it. On basis states, then, a reversible classical gate must be a permutation: each input string goes to its own output string, with as many bits out as in.

NOT, CNOT and swap pass this test. Classical AND does not. It takes two bits and returns one, and three of its four inputs (00, 01, 10) all give 0.

Check yourself

An AND gate outputs 0. Can you tell what its inputs were?

  1. AYes: an output of 0 means both inputs were 0.
  2. BNo: 00, 01 and 10 all give 0, so the information is gone.
  3. CYes, by running the AND gate backwards.
Show the answer

Answer: B. No: 00, 01 and 10 all give 0, so the information is gone.

AND sends 00, 01 and 10 to the same output, 0. A unitary gate can’t do that, because it must be undoable.

Why not the others

  • A. That is only one of three cases: AND(0, 1) and AND(1, 0) are also 0. The output 0 leaves three possibilities, and that loss is exactly why AND cannot be a unitary gate.
  • C. Running a gate backwards needs a rule that sends each output to one input. For AND the output 0 has three possible inputs, so no such rule exists. Every unitary gate has one: U†U^\dagger.

Check yourself

Which of these classical operations could run on a quantum computer as gates, exactly as stated?

Select all that apply.

  1. AXOR: (a,b)↦a⊕b(a, b)\mapsto a\oplus b, one bit out
  2. BSwap: (a,b)↦(b,a)(a, b)\mapsto(b, a)
  3. CNOT: a↦aˉa\mapsto\bar a
  4. DCNOT: (a,b)↦(a, a⊕b)(a, b)\mapsto(a,\ a\oplus b)
  5. ENAND: (a,b)↦ab‾(a, b)\mapsto\overline{ab}
  6. FOR: (a,b)↦a∨b(a, b)\mapsto a\lor b
Show the answer

Answers: B. Swap: (a,b)↦(b,a)(a, b)\mapsto(b, a); C. NOT: a↦aˉa\mapsto\bar a; D. CNOT: (a,b)↦(a, a⊕b)(a, b)\mapsto(a,\ a\oplus b)

NOT, CNOT and swap permute the bit strings, so each can be undone (each is its own inverse). XOR, OR and NAND squeeze two bits into one, so different inputs collide.

Why not the others

  • A. XOR turns two bits into one: 01 and 10 both give 1. Keeping aa next to the XOR fixes that, and the result is CNOT.
  • E. NAND gives 1 for three of its four inputs, so it loses information just as AND does.
  • F. Three inputs (01, 10, 11) all give 1, so OR cannot be undone.

11 / 15 · Learn

Part B · Toffoli: AND without losing anything

The Toffoli gate has two controls and one target. On basis states it flips the target only when both controls are 1:

(a, b, c) ↦ (a, b, c⊕ab).(a,\ b,\ c)\ \mapsto\ (a,\ b,\ c\oplus ab).

It keeps aa and bb, so it is a permutation of the eight 3-bit strings: it exchanges 110 and 111 and leaves the other six alone. Apply it twice and you are back where you started. In a circuit it is drawn as two control dots joined to a ⊕.

Check yourself

Toffoli has its controls on the top two wires and its target on the bottom wire. Match each input with its output.

Match each of these…

  1. ∣110⟩\ket{110}
  2. ∣101⟩\ket{101}
  3. ∣111⟩\ket{111}

…with one of these

  • ∣011⟩\ket{011}
  • ∣110⟩\ket{110}
  • ∣100⟩\ket{100}
  • ∣101⟩\ket{101}
  • ∣111⟩\ket{111}
Hints
  1. For each input, are both control bits (the first two labels) equal to 1?
  2. Only then does the last bit flip.
Show the answer
∣110⟩\ket{110}∣111⟩\ket{111}
∣101⟩\ket{101}∣101⟩\ket{101}
∣111⟩\ket{111}∣110⟩\ket{110}

∣110⟩\ket{110}: both controls are 1, so c=0c = 0 flips to 1, giving ∣111⟩\ket{111}. ∣101⟩\ket{101}: the second control is 0, so nothing changes. ∣111⟩\ket{111}: both controls are 1, so c=1c = 1 flips to 0, giving ∣110⟩\ket{110}.

Fix some of the inputs and Toffoli computes other things. With c=0c = 0 the target ends up as abab: AND, with nothing thrown away. The extra input you supply is called an ancilla; outputs kept only so the gate stays reversible (here aa and bb, if all you wanted was the AND) are called garbage. Two other settings matter. NAND gates can build any classical circuit, provided you can also copy a bit (FANOUT) so that one output feeds several gates. Toffoli can do both jobs, so a quantum computer can run any classical computation.

Check yourself

Which fixed inputs make Toffoli compute NAND(aa, bb) in the third bit, and which make it copy bb?

  1. ANAND: set c=1c = 1. Copy: impossible, because copying is forbidden.
  2. BNAND: set c=1c = 1. Copy: set a=1a = 1 and c=0c = 0.
  3. CNAND: set c=0c = 0. Copy: set a=1a = 1 and c=0c = 0.
  4. DNAND: set c=1c = 1. Copy: set a=0a = 0 and c=0c = 0.
Hints
  1. What is 1⊕ab1\oplus ab?
  2. For a copy you need c⊕ab=bc\oplus ab = b.
Show the answer

Answer: B. NAND: set c=1c = 1. Copy: set a=1a = 1 and c=0c = 0.

With c=1c = 1 the target becomes 1⊕ab=ab‾1\oplus ab = \overline{ab}, which is NAND. With a=1a = 1 and c=0c = 0 it becomes 0⊕b=b0\oplus b = b, so the output (1,b,b)(1, b, b) holds two copies of bb.

Why not the others

  • A. What is forbidden is copying an unknown quantum state (Lesson 7). Copying a classical bit, a basis state 0 or 1, is fine: with a=1a = 1 and c=0c = 0, Toffoli outputs (1,b,b)(1, b, b).
  • C. With c=0c = 0 the third bit becomes abab: that is AND. NAND is ab‾=1⊕ab\overline{ab} = 1\oplus ab, so the target has to start at 1.
  • D. With a=0a = 0 the product abab is always 0, so the target never flips and stays 0. To copy bb you need ab=bab = b, which takes a=1a = 1.

12 / 15 · Practice

Practice

Three problems from both parts. Hints unlock after a first try.

Check yourself

The top qubit is in 35∣0⟩+45∣1⟩\tfrac35\ket0 + \tfrac45\ket1 and the bottom qubit in 45∣0⟩−3i5∣1⟩\tfrac45\ket0 - \tfrac{3i}{5}\ket1. What is the amplitude of ∣01⟩\ket{01} in the two-qubit state?

Hints
  1. Which qubit does the first label of ∣01⟩\ket{01} belong to?
  2. For a product state, αxy=axby\alpha_{xy} = a_x b_y: top amplitude for the first label times bottom amplitude for the second.
  3. Multiply the top qubit’s ∣0⟩\ket{0} amplitude, 35\tfrac35, by the bottom qubit’s ∣1⟩\ket{1} amplitude, −3i5-\tfrac{3i}{5}.
Show the answer

Answer: −925 i-\frac{9}{25}\,i

α01=a0 b1=(35)(−3i5)=−925 i≈−0.36i\alpha_{01} = a_0\,b_1 = \left(\tfrac35\right)\left(-\tfrac{3i}{5}\right) = -\tfrac{9}{25}\,i \approx -0.36i.

Expand the product term by term: the coefficient of ∣01⟩\ket{01} is the top qubit’s ∣0⟩\ket{0} amplitude times the bottom qubit’s ∣1⟩\ket{1} amplitude, (35)(−3i5)=−925 i≈−0.36i\left(\tfrac35\right)\left(-\tfrac{3i}{5}\right) = -\tfrac{9}{25}\,i \approx -0.36i.

Common slips

  • 1625\frac{16}{25}: That is a1b0a_1b_0, the amplitude of ∣10⟩\ket{10}. In ∣01⟩\ket{01} the first label belongs to the top qubit, so you need the top qubit’s ∣0⟩\ket{0} amplitude times the bottom qubit’s ∣1⟩\ket{1} amplitude.
  • 35−35i\frac{3}{5}-\frac{3}{5}i: Adding the two amplitudes treats the qubits as separate lists. In a product state each amplitude is a product, αxy=axby\alpha_{xy} = a_x b_y: expanding (a0∣0⟩+a1∣1⟩)(b0∣0⟩+b1∣1⟩)(a_0\ket0 + a_1\ket1)(b_0\ket0 + b_1\ket1) multiplies them.

Check yourself

Build a circuit on three wires that leaves q0=aq_0 = a and q1=bq_1 = b unchanged and turns q2q_2, which starts at 0, into NAND(aa, bb). An XX in a column with control dots becomes a ⊕ that acts only when every dot in that column is 1.

Build it in the circuit builder (gates: control, X).

Hints
  1. What does a Toffoli put on q2q_2 when q2q_2 starts at 0?
  2. NAND is NOT of AND: ab‾=1⊕ab\overline{ab} = 1\oplus ab.
  3. Place a Toffoli (two dots and an XX in one column), then an XX on q2q_2 alone in the next column.
Show the answer

One circuit that works: Toffoli q0,q1→q2, then X on q2.

A Toffoli writes abab into q2q_2, and an XX on q2q_2 then gives 1⊕ab=ab‾1\oplus ab = \overline{ab}. Putting the XX first also works: it sets the target to 1, and the Toffoli then gives 1⊕ab1\oplus ab.

Column 1: control dots on q0q_0 and q1q_1, XX on q2q_2 (a Toffoli): (a,b,0)↦(a,b,ab)(a, b, 0)\mapsto(a, b, ab). Column 2: XX on q2q_2 alone: (a,b,ab)↦(a,b,1⊕ab)(a, b, ab)\mapsto(a, b, 1\oplus ab). Inputs 000, 010, 100, 110 go to 001, 011, 101, 110.

Check yourself

Take ∣ψ⟩=16∣00⟩+i6∣01⟩−26∣11⟩\ket\psi = \tfrac{1}{\sqrt6}\ket{00} + \tfrac{i}{\sqrt6}\ket{01} - \tfrac{2}{\sqrt6}\ket{11}. You measure only the bottom qubit, in the 0/1 basis. What is the probability that it gives 0?

P=  ?P = \;?

Hints
  1. Which two basis states have the bottom (second) label equal to 0?
  2. The probability of a result on one qubit is the sum of ∣α∣2\abs{\alpha}^2 over every basis state that agrees with it.
  3. Add ∣α00∣2\abs{\alpha_{00}}^2 and ∣α10∣2\abs{\alpha_{10}}^2.
Show the answer

Answer: P=16P = \frac{1}{6}

Add the column for 0: ∣α00∣2+∣α10∣2=16+0=16\abs{\alpha_{00}}^2 + \abs{\alpha_{10}}^2 = \tfrac{1}{6} + 0 = \tfrac{1}{6}.

The bottom qubit is the second label, so the result 0 covers ∣00⟩\ket{00} and ∣10⟩\ket{10}: P=16+0=16P = \tfrac{1}{6} + 0 = \tfrac{1}{6}. After that result only those terms remain, divided by 16\sqrt{\tfrac{1}{6}}: ∣00⟩|00\rangle.

Common slips

  • 13\frac{1}{3}: That total belongs to the top qubit: it adds the terms whose first label is 0. The bottom qubit is the second label, so add ∣α00∣2+∣α10∣2\abs{\alpha_{00}}^2 + \abs{\alpha_{10}}^2.
  • 56\frac{5}{6}: That is the probability of the other result, 1. For 0, add the squared magnitudes of the terms whose second label is 0.

13 / 15 · Explain

Explain it

Explain it

Why can’t a quantum computer apply the classical AND gate directly, and how does the Toffoli gate get around this?

Show a model answer

Quantum gates are unitary, so every gate has an inverse and different inputs must give different outputs. AND sends three inputs (00, 01 and 10) to the same output 0, so it destroys information and cannot be undone. Toffoli keeps aa and bb and writes c⊕abc\oplus ab into a third bit. That makes it a permutation of the eight basis strings, and its own inverse. With c=0c = 0 the third bit holds AND(aa, bb); the extra bit is an ancilla, and the kept inputs are garbage you may not need.

A good answer covers

  • Quantum gates are unitary, so reversible: each one has an inverse.
  • AND maps several inputs (00, 01, 10) to the same output, so it loses information.
  • Toffoli keeps aa and bb and writes c⊕abc\oplus ab into an extra bit, so it is a permutation of basis states; with c=0c = 0 that bit is AND(aa, bb).
  • Mentions the ancilla bit, or the leftover garbage outputs.

14 / 15 · Mastery check

Mastery check

Check yourself

A general state of 7 qubits: how many complex amplitudes does it take to write down, and how many bits do you get when you measure all 7 qubits in the 0/1 basis?

  1. A128 amplitudes; 128 bits
  2. B128 amplitudes; 7 bits
  3. C7 amplitudes; 7 bits
  4. D14 amplitudes; 7 bits
Show the answer

Answer: B. 128 amplitudes; 7 bits

Each of the 27=1282^{7} = 128 strings is a basis state with its own amplitude, but one measurement picks out one string: 7 bits.

Why not the others

  • A. A common idea is that every amplitude gets read out. One shot of the measurement returns one 7-bit string, so 7 bits. The 128 amplitudes set the odds of the 128 possible strings; they never come out as data.
  • C. One number per qubit would describe a classical register, where each bit has a definite value. A quantum register gives an amplitude to every string: 27=1282^{7} = 128 numbers. Even one qubit needs two, α\alpha and β\beta.
  • D. Adding 2 per qubit treats the qubits as separate lists. The basis states are the strings 0000000 to 1111111, and there are 27=1282^{7} = 128 of them, each with its own amplitude. Dimensions multiply under ⊗\tp.

Check yourself

Three qubits, top to bottom: 45∣0⟩−3i5∣1⟩\tfrac45\ket0 - \tfrac{3i}{5}\ket1, then 32∣0⟩+12∣1⟩\tfrac{\sqrt3}{2}\ket0 + \tfrac12\ket1, then 35∣0⟩+45∣1⟩\tfrac35\ket0 + \tfrac45\ket1. What is the amplitude of ∣100⟩\ket{100} in their product state?

Show the answer

Answer: −0.312 i-0.312\,i

One factor per qubit, in order: (−3i5)(32)(35)=−9350 i≈−0.312i\left(-\tfrac{3i}{5}\right)\left(\tfrac{\sqrt3}{2}\right)\left(\tfrac35\right) = -\tfrac{9\sqrt{3}}{50}\,i \approx -0.312i.

Common slips

  • 0.5540.554: That reads 100100 from the right, which is the amplitude of ∣001⟩\ket{001}. The first label is the top qubit, so take the top qubit’s ∣1⟩\ket{1} amplitude, the middle qubit’s ∣0⟩\ket{0} amplitude and the bottom qubit’s ∣0⟩\ket{0} amplitude.

Check yourself

Take ∣ψ⟩=12∣01⟩+i2∣10⟩−12∣11⟩\ket\psi = \tfrac{1}{\sqrt2}\ket{01} + \tfrac{i}{2}\ket{10} - \tfrac12\ket{11}. You measure only the bottom qubit, in the 0/1 basis. What is the probability that it gives 1?

Hints
  1. Which two basis states have the bottom (second) label equal to 1?
  2. The probability of a result on one qubit is the sum of ∣α∣2\abs{\alpha}^2 over every basis state that agrees with it.
  3. Add ∣α01∣2\abs{\alpha_{01}}^2 and ∣α11∣2\abs{\alpha_{11}}^2.
Show the answer

Answer: 34\frac{3}{4}

Add the column for 1: ∣α01∣2+∣α11∣2=12+14=34\abs{\alpha_{01}}^2 + \abs{\alpha_{11}}^2 = \tfrac{1}{2} + \tfrac{1}{4} = \tfrac{3}{4}.

The bottom qubit is the second label, so the result 1 covers ∣01⟩\ket{01} and ∣11⟩\ket{11}: P=12+14=34P = \tfrac{1}{2} + \tfrac{1}{4} = \tfrac{3}{4}. After that result only those terms remain, divided by 34\sqrt{\tfrac{3}{4}}: 26∣01⟩−13∣11⟩\frac{2}{\sqrt{6}}|01\rangle - \frac{1}{\sqrt{3}}|11\rangle.

Common slips

  • 12\frac{1}{2}: That total belongs to the top qubit: it adds the terms whose first label is 1. The bottom qubit is the second label, so add ∣α01∣2+∣α11∣2\abs{\alpha_{01}}^2 + \abs{\alpha_{11}}^2.
  • 14\frac{1}{4}: That is the probability of the other result, 0. For 1, add the squared magnitudes of the terms whose second label is 1.

Check yourself

Compute UCN (X⊗I)∣10⟩U_{CN}\,(X\tp I)\ket{10}, where UCNU_{CN} has its control on the top qubit and X⊗IX\tp I is XX on the top qubit.

  1. A∣00⟩\ket{00}
  2. B∣01⟩\ket{01}
  3. C∣10⟩\ket{10}
  4. D∣11⟩\ket{11}
Show the answer

Answer: A. ∣00⟩\ket{00}

X⊗IX\tp I acts first (it is next to the ket): ∣10⟩→∣00⟩\ket{10}\to\ket{00}. Then UCNU_{CN}: ∣00⟩→∣00⟩\ket{00}\to\ket{00}.

Why not the others

  • B. That applies the two gates in the order they are written, left to right. In a product of operators the rightmost acts first. X⊗IX\tp I acts first (it is next to the ket): ∣10⟩→∣00⟩\ket{10}\to\ket{00}. Then UCNU_{CN}: ∣00⟩→∣00⟩\ket{00}\to\ket{00}.
  • C. That is the input unchanged, as if the two gates cancelled. They don’t: X⊗IX\tp I acts first (it is next to the ket): ∣10⟩→∣00⟩\ket{10}\to\ket{00}. Then UCNU_{CN}: ∣00⟩→∣00⟩\ket{00}\to\ket{00}.
  • D. Trace it one gate at a time, starting from the right. X⊗IX\tp I acts first (it is next to the ket): ∣10⟩→∣00⟩\ket{10}\to\ket{00}. Then UCNU_{CN}: ∣00⟩→∣00⟩\ket{00}\to\ket{00}.

Check yourself

Every quantum gate is reversible. Can a quantum computer compute XOR(a,b)\mathrm{XOR}(a, b) of two bits?

  1. AYes. Apply an XOR gate to the two qubits, as in a classical chip.
  2. BNo. XOR is irreversible, so quantum circuits cannot compute it.
  3. CYes, if the circuit keeps aa and bb and writes the answer into an extra bit.
  4. DOnly approximately: the answer comes out right with some probability below 1.
Show the answer

Answer: C. Yes, if the circuit keeps aa and bb and writes the answer into an extra bit.

Keep aa and bb and write the answer into a third bit: (a,b,c)↦(a,b,c⊕XOR(a,b))(a, b, c)\mapsto(a, b, c\oplus \mathrm{XOR}(a, b)) is a permutation of the eight strings, built from two CNOTs, one from each input bit into the third. With c=0c = 0 the third bit ends up holding XOR(a,b)\mathrm{XOR}(a, b).

Why not the others

  • A. A classical XOR gate turns two bits into one and loses information: 00 and 11 both give 0, and 01 and 10 both give 1. A quantum gate is unitary, so it must be undoable, and no rule can undo a collision like that. Classical chips may lose information; quantum gates may not.
  • B. This takes "gates must be reversible" one step too far. The function XOR can still be computed: keep aa and bb and XOR the answer into an extra bit, (a,b,c)↦(a,b,c⊕XOR(a,b))(a, b, c)\mapsto(a, b, c\oplus \mathrm{XOR}(a, b)). That is a permutation of bit strings, so it is reversible. Only a gate that throws its inputs away is ruled out.
  • D. Nothing random is needed. On basis-state inputs a reversible circuit is a permutation of bit strings and gives the answer with certainty. Randomness only enters if you feed in superpositions and then measure.

15 / 15 · Recap

Recap

From memory

Before reading the summary, write down what you remember. Pulling it back from memory is what makes it last.

  1. How do you turn two one-qubit states into one two-qubit vector, and what happens when you measure just one of the qubits?

    Show the key points
    • Each amplitude is a product, αxy=axby\alpha_{xy} = a_x b_y (top amplitude times bottom amplitude).
    • Slots in the order 00, 01, 10, 11; the first label is the top wire.
    • nn qubits need 2n2^n amplitudes, but measuring them all in the 0/1 basis returns one nn⁠-bit string.
    • Measuring one qubit: add ∣α∣2\abs{\alpha}^2 over its row (or column), keep it, divide by P\sqrt{P}.
  2. What does CNOT do, and when can its control qubit change?

    Show the key points
    • On basis states, ∣A,B⟩→∣A,B⊕A⟩\ket{A,B}\to\ket{A, B\oplus A}: the target flips when the control is 1.
    • On superpositions, apply it term by term.
    • With target ∣−⟩\ket- the sign lands on the control: ∣+⟩∣−⟩→∣−⟩∣−⟩\ket+\ket-\to\ket-\ket-.
  3. Why must quantum gates be reversible, and how does Toffoli compute AND anyway?

    Show the key points
    • Unitary means invertible: no two inputs may share an output.
    • AND sends 00, 01 and 10 to 0, so it loses information.
    • Toffoli (a,b,c)↦(a,b,c⊕ab)(a, b, c)\mapsto(a, b, c\oplus ab): c=0c = 0 gives AND, c=1c = 1 gives NAND, and a=1a = 1, c=0c = 0 copies bb.

Key ideas

  1. Qubits in ∣a⟩\ket a and ∣b⟩\ket b together are in ∣a⟩⊗∣b⟩\ket a\tp\ket b, with amplitudes αxy=axby\alpha_{xy} = a_x b_y in the order 00, 01, 10, 11. The first label is the top wire.

  2. nn qubits need 2n2^n amplitudes; measuring all of them in the 0/1 basis returns one nn⁠-bit string.

  3. Measuring one qubit of two in the 0/1 basis: add ∣α∣2\abs{\alpha}^2 over the matching terms (its row or column of the grid), keep those terms, and divide by P\sqrt{P}.

  4. CNOT maps ∣A,B⟩→∣A,B⊕A⟩\ket{A,B}\to\ket{A, B\oplus A} on basis states. On superpositions apply it term by term; with target ∣−⟩\ket- the control picks up the sign, so ∣+⟩∣−⟩→∣−⟩∣−⟩\ket+\ket-\to\ket-\ket-.

  5. Circuits run left to right in time, but the operator is written right to left: AA then BB is BABA. Three CNOTs, the middle one reversed, swap two qubits.

  6. Gates are unitary, so reversible. AND is not; Toffoli (a,b,c)↦(a,b,c⊕ab)(a, b, c)\mapsto(a, b, c\oplus ab) is, and with fixed inputs it gives AND, NAND and FANOUT.

Go further

Free resources for when you want more than this lesson covers.

Math refreshers

The toolkit topics this lesson leans on.

Start the interactive lesson