Lean, informalized

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

Exercise 4.36 - A Toffoli gate and two controlled NOT gates on four qubits add xx to yy modulo 4

Three gates add two numbers modulo four.

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

Two numbers xx and yy from {0,1,2,3}\{0, 1, 2, 3\} are each held in two qubits, one qubit for each of their two binary digits. The exercise asks for a quantum circuit that adds xx to yy modulo 44 and keeps xx, taking the basis state |x,y⟩|x, y\rangle to |x,x+ymod⁡4⟩|x, x + y \bmod 4\rangle.

The library builds such a circuit on four qubits from one Toffoli gate and two controlled NOT (CNOT) gates.

Four Qubits

A quantum system SS is a physical object whose state space is a finite dimensional complex Hilbert space.✦ The composite system S⊗TS \otimes T of two quantum systems SS and TT is the quantum system whose state space is the tensor product of their state spaces.✦ The qubit is the two level quantum system with state space ℂ2\mathbb{C}^2.✦

A pure state |ψ⟩|\psi\rangle of a quantum system SS is a unit vector in the state space of SS, determined physically up to a global phase.✦ For a bit i∈{0,1}i \in \{0, 1\}, the basis state |i⟩|i\rangle of the qubit is the pure state whose vector is the standard basis vector eie_i of ℂ2\mathbb{C}^2.✦ Given pure states |ψ⟩|\psi\rangle of SS and |φ⟩|\varphi\rangle of TT, their product |ψ⟩⊗|φ⟩|\psi\rangle \otimes |\varphi\rangle is the pure state of S⊗TS \otimes T whose vector is the tensor product of the two vectors.✦

The low binary digit of a number x∈{0,1,2,3}x \in \{0, 1, 2, 3\} is x0=xmod⁡2x_0 = x \bmod 2 and its high binary digit is x1=⌊x/2⌋x_1 = \lfloor x/2 \rfloor, so that x=2x1+x0x = 2x_1 + x_0. The adder acts on four qubits, with state space ℂ2⊗ℂ2⊗ℂ2⊗ℂ2\mathbb{C}^2 \otimes \mathbb{C}^2 \otimes \mathbb{C}^2 \otimes \mathbb{C}^2, which hold in turn the low digits of xx and yy and then their high digits. The input of the adder for numbers xx and yy is the product of basis states |x,y⟩=|x0⟩⊗|y0⟩⊗|x1⟩⊗|y1⟩.|x, y\rangle = |x_0\rangle \otimes |y_0\rangle \otimes |x_1\rangle \otimes |y_1\rangle .(1)✦

Gates

A unitary UU of a quantum system SS is an operator on the state space of SS with U†U=UU†=1U^\dagger U = U U^\dagger = 1, a closed system evolution of SS.✦ A unitary UU of SS applied to a pure state |ψ⟩|\psi\rangle of SS gives the pure state U|ψ⟩U|\psi\rangle, whose vector is that of |ψ⟩|\psi\rangle acted on by UU.✦ For unitaries UU and VV of the same system, UU after VV is the unitary UVUV: first VV, then UU.✦ The identity evolution of SS is the unitary 11 of SS.✦

For unitaries UU of SS and VV of TT, the product unitary U⊗VU \otimes V is the unitary of S⊗TS \otimes T whose operator is the tensor product of the operators of UU and VV.✦ With the identity evolution as one factor it places a gate on part of the qubits, each qubit being a wire of the circuit: the gate UU on the first qubits is U⊗1U \otimes 1, and the gate VV on the last qubits is 1⊗V1 \otimes V.

The Pauli XX, the quantum NOT, is the unitary of the qubit whose matrix in the basis |0⟩,|1⟩|0\rangle, |1\rangle is 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 the composite of a control qubit and the target SS given by C(U)=|0⟩⟨0|⊗1+|1⟩⟨1|⊗U.C(U) = |0\rangle\langle 0| \otimes 1 + |1\rangle\langle 1| \otimes U .(3)✦ The CNOT gate is C(X)C(X), a unitary of two qubits that flips the second qubit exactly when the first, the control, is |1⟩|1\rangle.✦

The Adder Circuit

The four qubits are named by the digits they hold, x0,y0,x1,y1x_0, y_0, x_1, y_1. The carry Toffoli is Ucarry=C(C(1⊗X)),U_{\mathrm{carry}} = C\bigl(C(1 \otimes X)\bigr),(4)✦ a Toffoli gate controlled by x0x_0 and y0y_0, with XX on y1y_1 and the identity on x1x_1. The high CNOT is the CNOT gate on the last two wires, with control x1x_1 and target y1y_1, Uhigh=1⊗1⊗CNOT,U_{\mathrm{high}} = 1 \otimes 1 \otimes \mathrm{CNOT},(5) and the low CNOT is controlled by x0x_0, with XX on y0y_0: Ulow=C(X⊗1⊗1).U_{\mathrm{low}} = C(X \otimes 1 \otimes 1).(6) The mod 44 adder applies the three in this order: U+=UlowUhighUcarry.U_{+} = U_{\mathrm{low}}\, U_{\mathrm{high}}\, U_{\mathrm{carry}} .(7)✦

The Claim

Theorem 1. For numbers xx and yy in {0,1,2,3}\{0, 1, 2, 3\}, the mod 44 adder (7) acting on the input (1) gives U+|x,y⟩=|x,x+ymod⁡4⟩.U_{+}|x, y\rangle = |x, x + y \bmod 4\rangle .(8)✦

What Is Checked

The claim is stated over the four qubits and the products (1) of their basis states, and over the circuit (7), built from the Pauli XX by controlled gates, gates on part of the wires and composition. The two sides of (8) are equal as unit vectors, with no global phase between them.

The library proves that the controlled gate of a unitary UU is unitary, C(U)†C(U)=C(U)C(U)†=1C(U)^\dagger C(U) = C(U) C(U)^\dagger = 1; with the unitarity of the Pauli XX and of the products UVUV and U⊗VU \otimes V of unitaries, this makes each of the three gates and U+U_{+} a unitary of the four qubits. A unitary preserves norms, and the norm of a product vector is the product of the norms, so U|ψ⟩U|\psi\rangle and |ψ⟩⊗|φ⟩|\psi\rangle \otimes |\varphi\rangle are again pure states.