Lean, informalized

Nielsen & Chuang · Chapter 4, Quantum circuits · p. 182

Exercise 4.25 - The controlled swap as three Toffoli gates, as two CNOTs around one, and as six or five two qubit gates

The Fredkin gate from Toffoli gates and two qubit gates.

Hover over a blue or green term in the text, or a node in the graph, to find it in the other. Select it to read its declaration both in Lean and in words.

The Exercise

The Fredkin gate is the controlled swap on three qubits.✦ The first qubit is the control, and the gate acts on the three qubits by |0,x,y⟩↦|0,x,y⟩,|1,x,y⟩↦|1,y,x⟩.\lvert 0, x, y \rangle \mapsto \lvert 0, x, y \rangle, \qquad \lvert 1, x, y \rangle \mapsto \lvert 1, y, x \rangle .(1) Three Toffoli gates (the NOT on the third qubit controlled by the first two) make it, and the first and last of them can be replaced by controlled NOT (CNOT) gates with control on the second qubit and target on the third. Going further, the Fredkin gate is a circuit of six two qubit gates, and also of only five.

Three Qubits

A quantum system SS is a physical system whose state space is a finite dimensional complex Hilbert space, and the composite system S⊗TS \otimes T of two systems SS and TT is the system whose state space is the tensor product of theirs. A pure state |ψ⟩\lvert \psi \rangle of SS is a unit vector in the state space of SS.✦ The qubit is the system with state space ℂ2\mathbb{C}^2; its basis states |0⟩\lvert 0 \rangle and |1⟩\lvert 1 \rangle are the pure states given by the standard basis vectors (1,0)(1, 0) and (0,1)(0, 1). Three qubits form the composite qubit⊗(qubit⊗qubit)\mathrm{qubit} \otimes (\mathrm{qubit} \otimes \mathrm{qubit}), whose factors are the first, second and third qubit from the left.

A unitary UU of a system SS is an operator on the state space of SS with U†U=UU†=1U^\dagger U = U U^\dagger = 1.✦ The identity 11 is a unitary, and for two unitaries UU and VV of SS, UU after VV is the unitary UVUV, first VV then UU. For unitaries UU of SS and VV of TT, the product unitary U⊗VU \otimes V of S⊗TS \otimes T is the tensor product of the two operators; U⊗1U \otimes 1 is the gate UU on the first factor and 1⊗V1 \otimes V the gate VV on the last.

The Gates

The Pauli XX, the quantum NOT, is the unitary of the qubit with matrix X=(0110).X = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}.(2)✦ For a unitary UU of a system SS, the controlled gate C(U)C(U) is the unitary of qubit⊗S\mathrm{qubit} \otimes S, a control qubit and the target SS, given by C(U)=|0⟩⟨0|⊗1+|1⟩⟨1|⊗U.C(U) = \lvert 0 \rangle\langle 0 \rvert \otimes 1 + \lvert 1 \rangle\langle 1 \rvert \otimes U .(3) The CNOT gate is the controlled gate C(X)C(X) of two qubits.✦

The SWAP of two copies of a system SS is the unitary of S⊗SS \otimes S given by the isometry |ϕ⟩⊗|χ⟩↦|χ⟩⊗|ϕ⟩\lvert \phi \rangle \otimes \lvert \chi \rangle \mapsto \lvert \chi \rangle \otimes \lvert \phi \rangle. The CNOT with control below, CNOTrev=SWAPCNOTSWAP\mathrm{CNOT}^{\mathrm{rev}} = \mathrm{SWAP}\,\mathrm{CNOT}\,\mathrm{SWAP}, has its control on the second qubit and its target on the first.✦

For a unitary UU of the qubit, the doubly controlled gate C2(U)=C(C(U))C^2(U) = C(C(U)) is the unitary of three qubits that applies UU to the third when the first two are both |1⟩\lvert 1 \rangle.✦ The Toffoli gate TT is the doubly controlled NOT, and the Fredkin gate FF and the middle Toffoli gate MM are the controlled SWAP and the controlled CNOTrev\mathrm{CNOT}^{\mathrm{rev}}: T=C2(X)=C(CNOT),F=C(SWAP),M=C(CNOTrev).T = C^2(X) = C(\mathrm{CNOT}), \qquad F = C(\mathrm{SWAP}), \qquad M = C(\mathrm{CNOT}^{\mathrm{rev}}).(4) The middle Toffoli gate flips the second qubit when the first and third are both |1⟩\lvert 1 \rangle.✦

Circuits of Two Qubit Gates

A two qubit gate gg on three qubits is a gate of one of four kinds, each with its unitary UgU_g of the three qubits: an arbitrary two qubit unitary VV on the second and third qubits, Ug=1⊗VU_g = 1 \otimes V; a unitary WW of the qubit acting on the second or the third qubit, controlled by the first, Ug=C(W⊗1)U_g = C(W \otimes 1) or Ug=C(1⊗W)U_g = C(1 \otimes W); an arbitrary two qubit unitary VV on the first and second qubits, the third idle; and one on the first and third, the second idle.✦

The last two kinds act on qubits that the bracketing qubit⊗(qubit⊗qubit)\mathrm{qubit} \otimes (\mathrm{qubit} \otimes \mathrm{qubit}) does not group together, and they are placed by identifications of systems. An identification ee of a system SS with a system TT is a linear isometric bijection from the state space of SS onto that of TT.✦ An identification ee of SS with TT carries a unitary UU of SS to the unitary eUe−1e\,U e^{-1} of TT, the relabelling of UU along ee.✦ For three systems AA, BB and CC, the regrouping αA,B,C\alpha_{A,B,C} identifies A⊗(B⊗C)A \otimes (B \otimes C) with (A⊗B)⊗C(A \otimes B) \otimes C by |u⟩⊗(|v⟩⊗|w⟩)↦(|u⟩⊗|v⟩)⊗|w⟩\lvert u \rangle \otimes (\lvert v \rangle \otimes \lvert w \rangle) \mapsto (\lvert u \rangle \otimes \lvert v \rangle) \otimes \lvert w \rangle, and the swap swapA,B\mathrm{swap}_{A,B} identifies A⊗BA \otimes B with B⊗AB \otimes A by |u⟩⊗|v⟩↦|v⟩⊗|u⟩\lvert u \rangle \otimes \lvert v \rangle \mapsto \lvert v \rangle \otimes \lvert u \rangle. Together they interchange the first two factors: λA,B,C=αB,A,C−1∘(swapA,B⊗1C)∘αA,B,C:A⊗(B⊗C)→B⊗(A⊗C),\lambda_{A,B,C} = \alpha_{B,A,C}^{-1} \circ (\mathrm{swap}_{A,B} \otimes 1_C) \circ \alpha_{A,B,C} \colon A \otimes (B \otimes C) \to B \otimes (A \otimes C),(5)✦ where α−1\alpha^{-1} is the inverse identification, ∘\circ composes identifications, the right one first, and swapA,B⊗1C\mathrm{swap}_{A,B} \otimes 1_C is the product of the swap with the identity of CC, acting factor by factor.

For three qubits, the gate of the third kind is Ug=α−1(V⊗1)αU_g = \alpha^{-1} (V \otimes 1)\, \alpha, the relabelling of V⊗1V \otimes 1 along α−1\alpha^{-1}, and the gate of the fourth kind is Ug=λ−1(1⊗V)λU_g = \lambda^{-1} (1 \otimes V)\, \lambda.

A circuit of two qubit gates on three qubits is a sequence g1,…,gng_1, \dots, g_n of such gates; its number of gates is nn, and its unitary is the product of the unitaries of its gates, U(g1,…,gn)=Ug1Ug2⋯Ugn.U(g_1, \dots, g_n) = U_{g_1} U_{g_2} \cdots U_{g_n}.(6)

The Claim

Theorem 1. On three qubits, the Fredkin gate is the middle Toffoli gate between two Toffoli gates, F=TMT,F = T\, M\, T,(7)✦ and the middle Toffoli gate between two CNOT gates on the second and third qubits, F=(1⊗CNOT)M(1⊗CNOT).F = (1 \otimes \mathrm{CNOT})\, M\, (1 \otimes \mathrm{CNOT}).(8)✦ There is a circuit g1,…,g6g_1, \dots, g_6 of six two qubit gates whose unitary is the Fredkin gate, U(g1,…,g6)=F,U(g_1, \dots, g_6) = F,(9)✦ and there is a circuit h1,…,h5h_1, \dots, h_5 of five, U(h1,…,h5)=F.U(h_1, \dots, h_5) = F.(10)✦

What Is Checked

The four equalities are stated over the Fredkin gate F=C(SWAP)F = C(\mathrm{SWAP}) of three qubits, the Toffoli gate, the middle Toffoli gate, the CNOT gate on the second and third qubits, and, for the last two, the unitary (6) of a circuit of two qubit gates together with its number of gates.

About these constructions the library proves that each is a unitary. For every unitary UU of a system SS, the controlled gate (3) satisfies C(U)†C(U)=C(U)C(U)†=1C(U)^\dagger C(U) = C(U)\, C(U)^\dagger = 1; the matrix (2) is unitary; and products UVUV, tensor products U⊗VU \otimes V and relabellings eUe−1e\,U e^{-1} of unitaries are again unitary.