Lecture 6 · Dr Ittoop Puthoor · about 60 min

Multiple-qubit systems and two-qubit gates

Gates that act on more than one qubit. CNOT, its matrix and linearity, building a Bell pair from scratch, SWAP from three CNOTs, the Toffoli gate, and applying gates to one qubit of many.

How much help?
How well do you know this?
By the end you can
  • Apply CNOT to basis states and, by linearity, to superpositions
  • Write the 4×4 matrices for CNOT and SWAP
  • Build ∣Φ+⟩\ket{\Phi^+} with H and CNOT and track the state at each step
  • Explain the Toffoli gate and why it matters
  • Apply a single-qubit gate to one qubit of a register using U⊗IU\otimes I

Builds on: Lecture 4, Lecture 5

Recap in one breath

Single qubits: ∣ψ⟩=α∣0⟩+β∣1⟩\ket\psi = \alpha\ket0+\beta\ket1. Two qubits: tensor product, four amplitudes in the order ∣00⟩,∣01⟩,∣10⟩,∣11⟩\ket{00},\ket{01},\ket{10},\ket{11}; the vector for ∣01⟩\ket{01} is (0,1,0,0)T(0,1,0,0)^T. Some states (like 12(∣01⟩+∣10⟩)\tfrac1{\sqrt2}(\ket{01}+\ket{10})) are entangled. Single-qubit gates (X, H, …) are 2×2 unitaries. Now we need gates that act on two qubits at once; without them we could never create entanglement.

From logic gates to quantum gates

Classical NOT maps 0↔1 and is reversible (you can tell the input from the output). Classical NAND maps two bits to one, so it loses information: output 1 could come from 00, 01 or 10. Quantum gates are unitary, so they are always reversible: same number of qubits in and out, and nothing forgotten.

CNOT: controlled-NOT

CNOT has a control qubit and a target qubit. It flips the target if and only if the control is 1:

CNOT∣q0,q1⟩=∣q0, q0⊕q1⟩.\mathrm{CNOT}\ket{q_0, q_1} = \ket{q_0,\ q_0\oplus q_1}.
InputOutput
∣00⟩\ket{00}∣00⟩\ket{00}
∣01⟩\ket{01}∣01⟩\ket{01}
∣10⟩\ket{10}∣11⟩\ket{11}
∣11⟩\ket{11}∣10⟩\ket{10}

In a circuit it is drawn as a dot (●) on the control wire joined to a ⊕ on the target. As a matrix (columns = images of ∣00⟩,∣01⟩,∣10⟩,∣11⟩\ket{00},\ket{01},\ket{10},\ket{11}):

CNOT=(1000010000010010)=(I00X).\mathrm{CNOT} = \begin{pmatrix}1&0&0&0\\0&1&0&0\\0&0&0&1\\0&0&1&0\end{pmatrix} = \begin{pmatrix} I & 0 \\ 0 & X\end{pmatrix}.

The block form says it all: if the first qubit is 0 do II, if it is 1 do XX. Equivalently CNOT=∣0⟩⟨0∣⊗I+∣1⟩⟨1∣⊗X\mathrm{CNOT} = \ket0\bra0\otimes I + \ket1\bra1\otimes X.

Linearity: CNOT on superpositions

CNOT is linear, so apply it to each term:

CNOT(12(∣00⟩+∣01⟩))=12(∣00⟩+∣01⟩)(control is 0 in both terms: nothing happens)\mathrm{CNOT}\Big(\tfrac1{\sqrt2}(\ket{00}+\ket{01})\Big) = \tfrac1{\sqrt2}(\ket{00}+\ket{01}) \quad\text{(control is 0 in both terms: nothing happens)} CNOT(12(∣0⟩+∣1⟩)⊗∣0⟩)=12(CNOT∣00⟩+CNOT∣10⟩)=12(∣00⟩+∣11⟩).\mathrm{CNOT}\Big(\tfrac1{\sqrt2}(\ket{0}+\ket{1})\otimes\ket0\Big) = \tfrac1{\sqrt2}\big(\mathrm{CNOT}\ket{00} + \mathrm{CNOT}\ket{10}\big) = \tfrac1{\sqrt2}(\ket{00}+\ket{11}).

A product state went in; an entangled state came out. That is CNOT’s superpower.

Lock it in · answer in your head, then reveal
CNOT action
CNOT∣a,b⟩=∣a,a⊕b⟩\mathrm{CNOT}\ket{a,b} = \ket{a, a\oplus b}: flip the target if the control is 1.
CNOT matrix (control first)
(1000010000010010)\begin{pmatrix}1&0&0&0\\0&1&0&0\\0&0&0&1\\0&0&1&0\end{pmatrix}

Building an EPR (Bell) pair

Start with ∣00⟩\ket{00}, apply H to the first qubit, then CNOT. Track the state at each stage:

ψ1=∣0⟩A∣0⟩B=∣00⟩\psi_1 = \ket0_A\ket0_B = \ket{00} ψ2=(H⊗I)∣00⟩=12(∣0⟩+∣1⟩)∣0⟩=12(∣00⟩+∣10⟩)\psi_2 = (H\otimes I)\ket{00} = \tfrac1{\sqrt2}(\ket0+\ket1)\ket0 = \tfrac1{\sqrt2}(\ket{00} + \ket{10}) ψ3=CNOT ψ2=12(∣00⟩+∣11⟩)=∣Φ+⟩.\psi_3 = \mathrm{CNOT}\,\psi_2 = \tfrac1{\sqrt2}(\ket{00} + \ket{11}) = \ket{\Phi^+}.
Explore · two qubits, tensor products and entanglement

Reproduce the Bell-pair circuit: H on q0, then CNOT q0→q1. Then Reset, press X on q1 first, and repeat: you get a different Bell state. Try all four starting points |00⟩, |01⟩, |10⟩, |11⟩.

Gates (applied left to right in time):

Circuit so far: (none)

Amplitudes and probabilities (order |q0 q1⟩)

Different inputs give the four Bell states, an orthonormal basis of two-qubit space made entirely of maximally entangled states:

InputOutput
∣00⟩\ket{00}∣Φ+⟩=12(∣00⟩+∣11⟩)\ket{\Phi^+} = \tfrac1{\sqrt2}(\ket{00}+\ket{11})
∣01⟩\ket{01}∣Ψ+⟩=12(∣01⟩+∣10⟩)\ket{\Psi^+} = \tfrac1{\sqrt2}(\ket{01}+\ket{10})
∣10⟩\ket{10}∣Φ−⟩=12(∣00⟩−∣11⟩)\ket{\Phi^-} = \tfrac1{\sqrt2}(\ket{00}-\ket{11})
∣11⟩\ket{11}∣Ψ−⟩=12(∣01⟩−∣10⟩)\ket{\Psi^-} = \tfrac1{\sqrt2}(\ket{01}-\ket{10})

Entanglement has been demonstrated over more than 1000 km (the Micius satellite, 2017), and its foundations won the 2022 Nobel Prize in Physics (Aspect, Clauser, Zeilinger).

Lock it in · answer in your head, then reveal
Circuit that makes ∣Φ+⟩\ket{\Phi^+} from ∣00⟩\ket{00}
H on qubit 0, then CNOT (control 0, target 1): 12(∣00⟩+∣11⟩)\tfrac1{\sqrt2}(\ket{00}+\ket{11}).
The four Bell states
∣Φ±⟩=12(∣00⟩±∣11⟩)\ket{\Phi^\pm}=\tfrac1{\sqrt2}(\ket{00}\pm\ket{11}), ∣Ψ±⟩=12(∣01⟩±∣10⟩)\ket{\Psi^\pm}=\tfrac1{\sqrt2}(\ket{01}\pm\ket{10}).

SWAP

SWAP exchanges two qubits: ∣ab⟩→∣ba⟩\ket{ab}\to\ket{ba}. So ∣01⟩↔∣10⟩\ket{01}\leftrightarrow\ket{10} and ∣00⟩,∣11⟩\ket{00}, \ket{11} are unchanged:

SWAP=(1000001001000001).\mathrm{SWAP} = \begin{pmatrix}1&0&0&0\\0&0&1&0\\0&1&0&0\\0&0&0&1\end{pmatrix}.

It can be built from three CNOTs, alternating direction: CNOT(0→1), CNOT(1→0), CNOT(0→1). Trace ∣10⟩\ket{10}: → ∣11⟩\ket{11} → ∣01⟩\ket{01} → ∣01⟩\ket{01} ✓.

Toffoli (CCNOT)

Three qubits: two controls and a target. The target flips only when both controls are 1: ∣P,Q,R⟩→∣P,Q,R⊕(P⋅Q)⟩\ket{P,Q,R}\to\ket{P,Q,R\oplus(P\cdot Q)}. Its 8×8 matrix is the identity except that the last two rows are swapped (∣110⟩↔∣111⟩\ket{110}\leftrightarrow\ket{111}).

Toffoli is reversible and universal for classical reversible logic: with R=1R = 1 it computes NAND, and any classical circuit can be made from NANDs. So a quantum computer can run any classical computation. Toffolis appear in Shor’s arithmetic, Grover’s oracles and error-correction syndrome checks.

Lock it in · answer in your head, then reveal
How many CNOTs make a SWAP?
Three: CNOT(a→b), CNOT(b→a), CNOT(a→b).
What does the Toffoli (CCNOT) gate do?
Flips the target only when both controls are 1. It is reversible and universal for classical reversible logic.
∣0⟩⊗∣1⟩\ket0\otimes\ket1 as a column vector
(0,1,0,0)T=∣01⟩(0,1,0,0)^T = \ket{01}

Gates on one qubit of many

To apply UU to the first qubit and nothing to the second, use the tensor product of operators:

(A⊗B)(∣a⟩⊗∣b⟩)=A∣a⟩⊗B∣b⟩.(A\otimes B)(\ket a\otimes\ket b) = A\ket a\otimes B\ket b.

So “H on qubit 0” is H⊗IH\otimes I, a 4×4 matrix:

H⊗I=12(1⋅I1⋅I1⋅I−1⋅I)=12(1010010110−10010−1).H\otimes I = \tfrac1{\sqrt2}\begin{pmatrix}1\cdot I & 1\cdot I\\ 1\cdot I & -1\cdot I\end{pmatrix} = \tfrac1{\sqrt2}\begin{pmatrix}1&0&1&0\\0&1&0&1\\1&0&-1&0\\0&1&0&-1\end{pmatrix}.

Worked exercises

6.1 · ⊗ of two superpositions

Lecture 6: try this out

Compute 12(∣0⟩+∣1⟩)⊗12(∣0⟩+∣1⟩)\tfrac{1}{\sqrt2}(\ket0+\ket1)\otimes\tfrac1{\sqrt2}(\ket0+\ket1).

Worked solution
  1. Vectors: 12(11)⊗12(11)\tfrac1{\sqrt2}\begin{pmatrix}1\\1\end{pmatrix}\otimes\tfrac1{\sqrt2}\begin{pmatrix}1\\1\end{pmatrix}.
  2. Multiply the prefactors: 12⋅12=12\tfrac1{\sqrt2}\cdot\tfrac1{\sqrt2} = \tfrac12.
  3. Each top entry times the whole second vector: (1⋅(1,1)1⋅(1,1))=(1,1,1,1)T\begin{pmatrix}1\cdot(1,1)\\1\cdot(1,1)\end{pmatrix} = (1,1,1,1)^T.
Answer: 12(1,1,1,1)T=12(∣00⟩+∣01⟩+∣10⟩+∣11⟩)\tfrac12(1,1,1,1)^T = \tfrac12(\ket{00}+\ket{01}+\ket{10}+\ket{11}): a superposition of all 2-bit strings, built from two independent qubits.

6.2 · CNOT on the uniform superposition

Lecture 6: try it out

Compute CNOT(12(∣00⟩+∣01⟩+∣10⟩+∣11⟩))\mathrm{CNOT}\big(\tfrac12(\ket{00}+\ket{01}+\ket{10}+\ket{11})\big).

Worked solution
  1. By linearity, apply CNOT to each term: ∣00⟩→∣00⟩\ket{00}\to\ket{00}, ∣01⟩→∣01⟩\ket{01}\to\ket{01}, ∣10⟩→∣11⟩\ket{10}\to\ket{11}, ∣11⟩→∣10⟩\ket{11}\to\ket{10}.
  2. Sum: 12(∣00⟩+∣01⟩+∣11⟩+∣10⟩)\tfrac12(\ket{00}+\ket{01}+\ket{11}+\ket{10}).
  3. That is the same set of terms as before.
Answer: Unchanged: 12(∣00⟩+∣01⟩+∣10⟩+∣11⟩)\tfrac12(\ket{00}+\ket{01}+\ket{10}+\ket{11}). CNOT only permutes the terms, and here they all have equal amplitude. (In other words ∣++⟩\ket{++} is an eigenstate of CNOT.)

6.3 · SWAP by matrix

Lecture 6: try this out

Use the SWAP matrix to compute SWAP∣01⟩\mathrm{SWAP}\ket{01}.

Worked solution
  1. ∣01⟩=(0,1,0,0)T\ket{01} = (0,1,0,0)^T.
  2. Multiply: row 1 (1,0,0,0)⋅=0(1,0,0,0)\cdot = 0; row 2 (0,0,1,0)⋅=0(0,0,1,0)\cdot = 0; row 3 (0,1,0,0)⋅=1(0,1,0,0)\cdot = 1; row 4 =0= 0.
  3. Result (0,0,1,0)T=∣10⟩(0,0,1,0)^T = \ket{10}.
Answer: SWAP∣01⟩=∣10⟩\mathrm{SWAP}\ket{01} = \ket{10}.

6.4 · Bell state from |11⟩

Problem set style

Apply H to the first qubit of ∣11⟩\ket{11}, then CNOT. Which Bell state results?

Worked solution
  1. (H⊗I)∣11⟩=∣−⟩∣1⟩=12(∣0⟩−∣1⟩)∣1⟩=12(∣01⟩−∣11⟩)(H\otimes I)\ket{11} = \ket-\ket1 = \tfrac1{\sqrt2}(\ket0 - \ket1)\ket1 = \tfrac1{\sqrt2}(\ket{01} - \ket{11}).
  2. CNOT each term: ∣01⟩→∣01⟩\ket{01}\to\ket{01}, ∣11⟩→∣10⟩\ket{11}\to\ket{10}.
  3. Result: 12(∣01⟩−∣10⟩)\tfrac1{\sqrt2}(\ket{01} - \ket{10}).
Answer: ∣Ψ−⟩\ket{\Psi^-}, the singlet: the state used in Lecture 8’s Bell test.

6.5 · A circuit, step by step

Problem set style

Start in ∣00⟩\ket{00}. Apply X to qubit 1 (the second), then H to qubit 0, then CNOT (0 → 1), then H to qubit 0. Find the final state and the probabilities of each outcome.

Worked solution
  1. XX on qubit 1: ∣01⟩\ket{01}.
  2. HH on qubit 0: 12(∣01⟩+∣11⟩)\tfrac1{\sqrt2}(\ket{01} + \ket{11}).
  3. CNOT: ∣01⟩→∣01⟩\ket{01}\to\ket{01}, ∣11⟩→∣10⟩\ket{11}\to\ket{10}, giving 12(∣01⟩+∣10⟩)\tfrac1{\sqrt2}(\ket{01}+\ket{10}).
  4. HH on qubit 0: ∣01⟩→12(∣01⟩+∣11⟩)\ket{01}\to\tfrac1{\sqrt2}(\ket{01}+\ket{11}) and ∣10⟩→12(∣00⟩−∣10⟩)\ket{10}\to\tfrac1{\sqrt2}(\ket{00}-\ket{10}).
  5. Total: 12(∣00⟩+∣01⟩−∣10⟩+∣11⟩)\tfrac12(\ket{00} + \ket{01} - \ket{10} + \ket{11}).
Answer: 12(∣00⟩+∣01⟩−∣10⟩+∣11⟩)\tfrac12(\ket{00}+\ket{01}-\ket{10}+\ket{11}); each outcome has probability 14\tfrac14. Is it entangled? α00α11=14\alpha_{00}\alpha_{11} = \tfrac14 but α01α10=−14\alpha_{01}\alpha_{10} = -\tfrac14, so yes.
Check yourself

Which matrix acts as H on the second qubit only?

↧ Go deeper: Controlled-U and phase kickback MSc

Any gate can be controlled: C-U=∣0⟩⟨0∣⊗I+∣1⟩⟨1∣⊗UC\text{-}U = \ket0\bra0\otimes I + \ket1\bra1\otimes U. If the target is an eigenstate U∣u⟩=eiϕ∣u⟩U\ket u = e^{i\phi}\ket u, then C-U(∣+⟩∣u⟩)=12(∣0⟩+eiϕ∣1⟩)∣u⟩C\text{-}U(\ket+\ket u) = \tfrac1{\sqrt2}(\ket0 + e^{i\phi}\ket1)\ket u: the phase has “kicked back” onto the control. This trick drives the Deutsch–Jozsa, Bernstein–Vazirani and phase-estimation algorithms (and hence Shor’s). Simplest example: CNOT on ∣+⟩∣−⟩\ket+\ket- gives ∣−⟩∣−⟩\ket-\ket-, so the control flipped even though the “target” was the one being NOT-ed.

↧ Go deeper: CNOT is symmetric in the ± basis MSc

(H⊗H) CNOT0→1 (H⊗H)=CNOT1→0(H\otimes H)\,\mathrm{CNOT}_{0\to1}\,(H\otimes H) = \mathrm{CNOT}_{1\to0}: in the +/− basis, control and target swap roles. And CZ is symmetric: CZ=(I⊗H)CNOT(I⊗H)\mathrm{CZ} = (I\otimes H)\mathrm{CNOT}(I\otimes H) treats both qubits equally. This is why “which one is the control” is a basis-dependent statement.

↧ Go deeper: Entangling power and the Cartan (KAK) decomposition PhD

Every two-qubit unitary can be written (A1⊗B1) ei(c1XX+c2YY+c3ZZ) (A2⊗B2)(A_1\otimes B_1)\,e^{i(c_1 XX + c_2 YY + c_3 ZZ)}\,(A_2\otimes B_2). The three numbers (c1,c2,c3)(c_1, c_2, c_3) capture all its non-local power, and any two-qubit gate needs at most 3 CNOTs (Vidal & Dawson 2004; Kraus & Cirac 2001). SWAP needs all 3; CNOT is “half” of it in this geometry.