Lean, informalized

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

Exercise 4.26 - A circuit of seven gates agrees with the Toffoli gate on every basis input up to relative phases

Rotations and controlled NOTs give the Toffoli gate up to phases.

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 Toffoli gate acts on three qubits. It flips the third qubit, the target, exactly when the first two, the controls, are both |1⟩\lvert 1 \rangle.✦ The exercise is to show that a circuit of seven gates implements the Toffoli gate up to relative phases: four rotations of the target about the yy axis, by angles ±π/4\pm\pi/4, alternating with three controlled NOT (CNOT) gates whose target is the third qubit. The library states this for each computational basis input in turn.

Three Qubits

A quantum system SS is a physical system described by its state space, a finite dimensional complex Hilbert space.✦ Two systems AA and BB form the composite system A⊗BA \otimes B, whose state space is the tensor product of theirs.✦ The qubit QQ is the two level system with state space ℂ2\mathbb{C}^2, and three qubits form the composite system Q⊗(Q⊗Q)Q \otimes (Q \otimes Q).

A pure state |ψ⟩\lvert\psi\rangle of a system SS is a unit vector in the state space of SS.✦ For pure states |ψ⟩\lvert\psi\rangle of AA and |φ⟩\lvert\varphi\rangle of BB, the product state |ψ⟩⊗|φ⟩\lvert\psi\rangle \otimes \lvert\varphi\rangle is the pure state of A⊗BA \otimes B whose vector is the tensor product of the two vectors.✦ The basis states |0⟩\lvert 0 \rangle and |1⟩\lvert 1 \rangle of the qubit are the pure states given by the standard basis vectors (1,0)(1, 0) and (0,1)(0, 1) of ℂ2\mathbb{C}^2.✦ For bits q1q_1, q2q_2 and q3q_3, the basis state of three qubits is the product |q1q2q3⟩=|q1⟩⊗(|q2⟩⊗|q3⟩),\lvert q_1 q_2 q_3 \rangle = \lvert q_1 \rangle \otimes \bigl( \lvert q_2 \rangle \otimes \lvert q_3 \rangle \bigr),(1)✦ and the eight of them form the computational basis of the three qubits.

Two pure states |ψ⟩\lvert\psi\rangle and |φ⟩\lvert\varphi\rangle of SS differ by a relative phase with respect to a family of pure states |ek⟩\lvert e_k \rangle of SS, such as an orthonormal basis, if for every index kk there is a real number θk\theta_k, which may depend on kk, with ⟨ek|ψ⟩=eiθk⟨ek|φ⟩\langle e_k \vert \psi \rangle = e^{i\theta_k} \langle e_k \vert \varphi \rangle.✦

Gates

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; it carries a pure state |ψ⟩\lvert\psi\rangle of SS to the pure state U|ψ⟩U \lvert\psi\rangle. The composite UVUV of unitaries UU and VV of SS is the unitary of SS that applies first VV and then UU.✦ For unitaries UU of AA and VV of BB, the product unitary U⊗VU \otimes V is the unitary of A⊗BA \otimes B whose operator is the tensor product of theirs.✦ For a system AA and a unitary VV of BB, the unitary 1⊗V1 \otimes V of A⊗BA \otimes B, with the identity 11 of AA as first factor, applies VV to BB and leaves AA alone.✦

For a unitary UU of a system SS, the controlled gate C(U)C(U) is the unitary of Q⊗SQ \otimes S, with the qubit as control and SS as target, whose operator is 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 .(2)✦ 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 in which the first qubit controls the two qubit gate C(U)C(U) on the other two.✦

The Pauli matrices are X=(0110),Y=(0−ii0),Z=(100−1),X = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}, \qquad Y = \begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix}, \qquad Z = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix},(3) and the Pauli XX gate, the quantum NOT, is the unitary of the qubit whose matrix in the basis |0⟩\lvert 0 \rangle, |1⟩\lvert 1 \rangle is XX. For a real vector n→=(nx,ny,nz)\vec{n} = (n_x, n_y, n_z) and a real angle θ\theta, the rotation Rn→(θ)R_{\vec n}(\theta) is the 2×22 \times 2 matrix built from the Pauli matrices (3) as Rn→(θ)=exp⁡(−iθ2n→⋅σ→),n→⋅σ→=nxX+nyY+nzZ,R_{\vec n}(\theta) = \exp\Bigl( -\frac{i\theta}{2}\, \vec{n} \cdot \vec{\sigma} \Bigr), \qquad \vec{n} \cdot \vec{\sigma} = n_x X + n_y Y + n_z Z ,(4)✦ written Rnˆ(θ)R_{\hat n}(\theta) when the axis is a unit vector nˆ\hat{n}. For the unit vector yˆ=(0,1,0)\hat{y} = (0, 1, 0), the rotation Ryˆ(θ)=Ry(θ)=e−iθY/2R_{\hat y}(\theta) = R_y(\theta) = e^{-i\theta Y/2} is the rotation about the yy axis, and the yy rotation gate is the unitary of the qubit with matrix Ry(θ)R_y(\theta).

The Circuit

The Toffoli gate TT is the unitary C2(X)C^2(X) of three qubits, the doubly controlled NOT.✦ The CNOT gate is the unitary C(X)C(X) of two qubits, with the first as control; in the circuit 1⊗CNOT1 \otimes \mathrm{CNOT} acts on the second and third qubits.✦ The CNOT from the first qubit to the third is CNOT13=C(1⊗X)\mathrm{CNOT}_{13} = C(1 \otimes X), in which the first qubit controls the Pauli XX on the third and the second is left alone.✦ A rotation of the third qubit alone is R3(θ)=1⊗(1⊗Ry(θ))R_3(\theta) = 1 \otimes \bigl( 1 \otimes R_y(\theta) \bigr).✦ The relative phase Toffoli circuit T̃\tilde{T} is the product T̃=R3(−π4)(1⊗CNOT)R3(−π4)CNOT13R3(π4)(1⊗CNOT)R3(π4),\tilde{T} = R_3(-\tfrac{\pi}{4})\, (1 \otimes \mathrm{CNOT})\, R_3(-\tfrac{\pi}{4})\, \mathrm{CNOT}_{13}\, R_3(\tfrac{\pi}{4})\, (1 \otimes \mathrm{CNOT})\, R_3(\tfrac{\pi}{4}),(5)✦ a unitary of three qubits.

The Claim

Theorem 1. Let c1c_1, c2c_2 and tt be bits. Then the states T̃|c1c2t⟩\tilde{T} \lvert c_1 c_2 t \rangle and T|c1c2t⟩T \lvert c_1 c_2 t \rangle differ by a relative phase with respect to the computational basis of three qubits, that is, for every basis state |q1q2q3⟩\lvert q_1 q_2 q_3 \rangle there is a real θq1q2q3\theta_{q_1 q_2 q_3} with ⟨q1q2q3|T̃|c1c2t⟩=eiθq1q2q3⟨q1q2q3|T|c1c2t⟩.\langle q_1 q_2 q_3 \vert\, \tilde{T}\, \vert c_1 c_2 t \rangle = e^{i\theta_{q_1 q_2 q_3}}\, \langle q_1 q_2 q_3 \vert\, T\, \vert c_1 c_2 t \rangle .(6)✦

What Is Checked

The claim is stated over two unitaries of three qubits, the circuit T̃\tilde{T} of (5) and the Toffoli gate T=C2(X)T = C^2(X), applied to the basis states (1) and compared by the relation of a relative phase in the computational basis.

The library proves that the controlled gate C(U)C(U) of (2) is unitary for every unitary UU, and that the matrices XX and Ry(θ)R_y(\theta) are unitary. Composites and tensor products of unitaries are again unitary. A unitary takes a pure state to a unit vector, since it preserves norms, and the product of two pure states is a unit vector, since the norm of a product vector is the product of the norms.