Lean, informalized

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

Exercise 4.39 - A doubly controlled gate between two routings of three CNOTs, written in one qubit gates and CNOTs

Building a two level unitary on three qubits.

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

Three qubits have the computational basis states |q0q1q2⟩|q_0 q_1 q_2\rangle, with q0,q1,q2∈{0,1}q_0, q_1, q_2 \in \{0, 1\}. Let Ũ\tilde U be a unitary of a single qubit, with matrix Ũ=(acbd)\tilde U = \begin{pmatrix} a & c \\ b & d \end{pmatrix}(1) in the basis |0⟩,|1⟩|0\rangle, |1\rangle. The exercise asks for a circuit of one qubit gates and controlled NOT gates (CNOTs) that implements the two level unitary of three qubits built from Ũ\tilde U on the states |010⟩|010\rangle and |111⟩|111\rangle. On their span it acts as Ũ\tilde U, with |010⟩|010\rangle in the place of |0⟩|0\rangle and |111⟩|111\rangle in the place of |1⟩|1\rangle; the other six basis states stay fixed.

The library builds one such circuit: the doubly controlled gate C2(Ũ)C^2(\tilde U) between two copies of a routing unitary WW made of three CNOTs.

Three Qubits

A quantum system SS is a physical system whose state space is a finite dimensional complex Hilbert space.✦ The composite system S⊗TS \otimes T of two systems SS and TT is the system whose state space is the tensor product of their state spaces.✦ A pure state ψ\psi of SS is a unit vector in the state space of SS, and for pure states ψ\psi of SS and φ\varphi of TT the product ψ⊗φ\psi \otimes \varphi is the pure state of S⊗TS \otimes T whose vector is the tensor product of the two vectors.

The qubit is the two level system with state space ℂ2\mathbb{C}^2.✦ Its basis states |0⟩|0\rangle and |1⟩|1\rangle are the pure states whose vectors are the standard basis vectors e0e_0 and e1e_1.✦ Three qubits form the composite system qubit⊗(qubit⊗qubit)\mathrm{qubit} \otimes (\mathrm{qubit} \otimes \mathrm{qubit}), and its basis state |q0q1q2⟩=|q0⟩⊗(|q1⟩⊗|q2⟩)|q_0 q_1 q_2\rangle = |q_0\rangle \otimes \bigl(|q_1\rangle \otimes |q_2\rangle\bigr)(2) is a product of three basis states of the qubit. In a circuit the three qubits sit on wires 00, 11 and 22, from the top.

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 ψ\psi of SS to the pure state UψU\psi. For two unitaries UU and VV of SS, UU after VV is the unitary UVUV of SS, first VV and then UU, and the identity evolution of SS is the unitary 11. 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 theirs.✦ Placed on the first wires of S⊗TS \otimes T, a unitary UU of SS becomes U⊗1U \otimes 1; placed on the last wires, a unitary VV of TT becomes 1⊗V1 \otimes V. The SWAP of two copies of SS is the unitary of S⊗SS \otimes S that exchanges the factors, SWAP(x⊗y)=y⊗x\mathrm{SWAP}(x \otimes y) = y \otimes x.✦

The Gates

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, with operator C(U)=|0⟩⟨0|⊗1+|1⟩⟨1|⊗U.C(U) = |0\rangle\langle 0| \otimes 1 + |1\rangle\langle 1| \otimes U .(3)✦ The Pauli XX is the unitary of the qubit with matrix (0110)\begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}, and the CNOT gate is C(X)C(X) on two qubits: it flips the second qubit when the first is |1⟩|1\rangle. With the control below, CNOTrev=SWAPCNOTSWAP\mathrm{CNOT}^{\mathrm{rev}} = \mathrm{SWAP}\,\mathrm{CNOT}\,\mathrm{SWAP}(4)✦ is the CNOT controlled by the second qubit with the first as target. On three qubits the doubly controlled gate C2(U)=C(C(U))C^2(U) = C\bigl(C(U)\bigr) of a unitary UU of the qubit applies UU to the qubit on wire 22 exactly when the qubits on wires 00 and 11 are both |1⟩|1\rangle.✦

A gate GG of a three qubit circuit is either a one qubit gate, a unitary gg of the qubit on a chosen wire, or a CNOT with a chosen control wire and target wire; its evolution UGU_G is a unitary of the three qubits.✦ A one qubit gate gg on wire 00, 11 or 22 has the evolution g⊗1g \otimes 1, 1⊗(g⊗1)1 \otimes (g \otimes 1) or 1⊗(1⊗g)1 \otimes (1 \otimes g).✦ A CNOT with control wire 00 and target wire 11 or 22 is C(X⊗1)C(X \otimes 1) or C(1⊗X)C(1 \otimes X), conditioned on wire 00 with XX on the target wire; with control wire 11 and target wire 22 it is 1⊗CNOT1 \otimes \mathrm{CNOT}, and every other pair of wires gives the identity.✦ The evolution of a list G1,…,GkG_1, \dots, G_k of gates is the product of their evolutions in the order given, UG1UG2⋯UGk.U_{G_1} U_{G_2} \cdots U_{G_k} .(5)✦

The Circuit

The routing WW is a product of three CNOTs, each with its control below its target: the outer two are 1⊗CNOTrev1 \otimes \mathrm{CNOT}^{\mathrm{rev}} and the middle one is the CNOT RR with its control on wire 11 and its target on wire 00, W=(1⊗CNOTrev)R(1⊗CNOTrev).W = \bigl(1 \otimes \mathrm{CNOT}^{\mathrm{rev}}\bigr)\, R\, \bigl(1 \otimes \mathrm{CNOT}^{\mathrm{rev}}\bigr) .(6)✦ The outer two act as |q0q1q2⟩↦|q0,q1⊕q2,q2⟩|q_0 q_1 q_2\rangle \mapsto |q_0,\, q_1 \oplus q_2,\, q_2\rangle, where ⊕\oplus is addition modulo 22, and the middle one as |q0q1q2⟩↦|q0⊕q1,q1,q2⟩|q_0 q_1 q_2\rangle \mapsto |q_0 \oplus q_1,\, q_1,\, q_2\rangle.

To define the middle CNOT RR one regroups the three qubits, since CNOTrev⊗1\mathrm{CNOT}^{\mathrm{rev}} \otimes 1 acts on (qubit⊗qubit)⊗qubit(\mathrm{qubit} \otimes \mathrm{qubit}) \otimes \mathrm{qubit}. 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, and its inverse e−1e^{-1} identifies TT with SS. Along ee a unitary UU of SS becomes the unitary eUe−1e\,U\,e^{-1} of TT.✦ The regrouping of three systems AA, BB and CC identifies A⊗(B⊗C)A \otimes (B \otimes C) with (A⊗B)⊗C(A \otimes B) \otimes C by u⊗(v⊗w)↦(u⊗v)⊗wu \otimes (v \otimes w) \mapsto (u \otimes v) \otimes w.✦ The middle CNOT RR is CNOTrev⊗1\mathrm{CNOT}^{\mathrm{rev}} \otimes 1, a unitary of (qubit⊗qubit)⊗qubit(\mathrm{qubit} \otimes \mathrm{qubit}) \otimes \mathrm{qubit}, carried along the inverse of the regrouping to qubit⊗(qubit⊗qubit)\mathrm{qubit} \otimes (\mathrm{qubit} \otimes \mathrm{qubit}).✦

The two level unitary circuit is WC2(Ũ)WW\,C^2(\tilde U)\,W.✦

The Claim

Theorem 1. Let Ũ\tilde U be a unitary of the qubit with matrix (1). There is a list G1,…,GkG_1, \dots, G_k of one qubit gates and CNOTs of a three qubit circuit whose evolution is the two level unitary circuit, UG1UG2⋯UGk=WC2(Ũ)W.U_{G_1} U_{G_2} \cdots U_{G_k} = W\,C^2(\tilde U)\,W .(7)✦ This circuit sends |010⟩|010\rangle and |111⟩|111\rangle to WC2(Ũ)W|010⟩=a|010⟩+b|111⟩,W\,C^2(\tilde U)\,W\,|010\rangle = a\,|010\rangle + b\,|111\rangle ,(8)✦ WC2(Ũ)W|111⟩=c|010⟩+d|111⟩,W\,C^2(\tilde U)\,W\,|111\rangle = c\,|010\rangle + d\,|111\rangle ,(9)✦ and fixes every other basis state: for |q0q1q2⟩|q_0 q_1 q_2\rangle neither |010⟩|010\rangle nor |111⟩|111\rangle, WC2(Ũ)W|q0q1q2⟩=|q0q1q2⟩.W\,C^2(\tilde U)\,W\,|q_0 q_1 q_2\rangle = |q_0 q_1 q_2\rangle .(10)✦

What Is Checked

The claim is stated over the evolution (5) of a list of gates of a three qubit circuit and over the two level unitary circuit WC2(Ũ)WW\,C^2(\tilde U)\,W, built from the controlled gate (3), the reversed CNOT (4) and the routing (6), acting on the product basis states (2).

The library proves that the controlled gate is unitary: for every unitary UU of a system SS, the operator (3) satisfies C(U)†C(U)=C(U)C(U)†=1C(U)^\dagger C(U) = C(U)\,C(U)^\dagger = 1. It proves too that products and tensor products of unitaries are unitary, as is a unitary carried along an identification, so that the gates and the circuit WC2(Ũ)WW\,C^2(\tilde U)\,W are unitaries of the three qubits.