Lean, informalized

Nielsen & Chuang · Chapter 10, Quantum error-correction · p. 487

Exercise 10.67 - Pauli errors moving through a Toffoli gate

Two circuit identities for the Toffoli gate.

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

Exercise 10.67, on page 487, shows two circuit diagrams and asks the reader to verify them. In the first, a Pauli XX sits on the top control line just before a Toffoli gate. The claim is that the same thing happens if the Toffoli acts first and is followed by an XX on that control together with a CNOT from the second control onto the target. In the second, a ZZ sits on the target line before the Toffoli, and the claim is that this equals the Toffoli followed by a ZZ on the target and a controlled-ZZ between the two controls.

These are the rules for pushing a Pauli error through a Toffoli, and the book uses them in the fault-tolerant constructions of Section 10.6: an error that arrives before the gate comes out the other side as a known pattern of Paulis and controlled gates, which can be corrected. There are no diagrams in the library. Each identity is an equation between two gates on three qubits, and these notes write the equations out.

Gates on Three Qubits

A qubit is the two-level system, and three qubits form the composite qubit⊗(qubit⊗qubit)\mathrm{qubit} \otimes (\mathrm{qubit} \otimes \mathrm{qubit}), bracketed to the right. A gate is a unitary on the whole register.✦ Composition is written U∘VU \circ V and means VV first, then UU, the operator product UVUV; in a chain the rightmost gate acts first, the opposite of reading a drawn circuit from left to right.✦ A single-qubit gate GG is put on the first wire as G⊗idG \otimes \mathrm{id}, the identity on the other two, and on the third wire as id⊗(id⊗G)\mathrm{id} \otimes (\mathrm{id} \otimes G). Which wire a gate sits on is read off its position in the tensor product.

The controlled gate C(U)C(U) acts on a qubit and a system: it does nothing when the control is |0⟩|0\rangle and applies UU when it is |1⟩|1\rangle.✦ The control is always the first factor. Controlling twice gives the doubly controlled gate on three qubits, C2(U)=C(C(U)),C^{2}(U) = C\bigl(C(U)\bigr) ,(1)✦q1q2q3AxQM.controlledUnitaryAxQM.controlledUnitaryUU with the outer control on the first qubit and the inner one on the second. The Toffoli is the doubly controlled NOT, Toffoli=C2(X),\mathrm{Toffoli} = C^{2}(X) ,(2)✦q1q2q3AxQM.ccontrolledUnitaryAxQM.pauliXGate flipping the third qubit exactly when the first two are both |1⟩|1\rangle. The CNOT is the singly controlled NOT, CNOT=C(X).\mathrm{CNOT} = C(X) .(3)✦q1q2AxQM.controlledUnitaryAxQM.pauliXGate The book’s second identity needs a controlled-ZZ between the first two qubits of the register with the third left alone. The library defines it as a controlled gate whose target is ZZ on the second qubit, CZ12=C(Z⊗id),\mathrm{CZ}_{12} = C(Z \otimes \mathrm{id}) ,(4)✦q1q2q3AxQM.controlledUnitaryAxQM.pauliZGate which on a basis state is the sign (−1)q1q2(-1)^{q_1 q_2}.

The Identities

An XX on the first control, followed by the Toffoli, equals the Toffoli followed by a CNOT from the second control to the target and then the XX: Toffoli∘(X⊗id)=(X⊗id)∘(id⊗CNOT)∘Toffoli.\mathrm{Toffoli} \circ (X \otimes \mathrm{id}) = (X \otimes \mathrm{id}) \circ (\mathrm{id} \otimes \mathrm{CNOT}) \circ \mathrm{Toffoli} .(5)✦q1q2q3AxQM.pauliXGateAxQM.toffoliGateAxQM.pauliXGate=q1q2q3AxQM.toffoliGateAxQM.pauliXGateAxQM.cnotGateAxQM.pauliXGateAxQM.pauliXGate

A ZZ on the target, followed by the Toffoli, equals the Toffoli followed by a controlled-ZZ on the two controls and then the ZZ: Toffoli∘(id⊗(id⊗Z))=(id⊗(id⊗Z))∘CZ12∘Toffoli.\mathrm{Toffoli} \circ \bigl(\mathrm{id} \otimes (\mathrm{id} \otimes Z)\bigr) = \bigl(\mathrm{id} \otimes (\mathrm{id} \otimes Z)\bigr) \circ \mathrm{CZ}_{12} \circ \mathrm{Toffoli} .(6)✦q1q2q3AxQM.pauliZGateZAxQM.toffoliGateAxQM.pauliXGate=q1q2q3AxQM.toffoliGateAxQM.pauliXGateAxQM.controlledZLeftGateAxQM.pauliZGateAxQM.pauliZGateZ

Theorem 1. On three qubits, Toffoli∘(X⊗id)=(X⊗id)∘(id⊗CNOT)∘Toffoli\mathrm{Toffoli} \circ (X \otimes \mathrm{id}) = (X \otimes \mathrm{id}) \circ (\mathrm{id} \otimes \mathrm{CNOT}) \circ \mathrm{Toffoli} and Toffoli∘(id⊗(id⊗Z))=(id⊗(id⊗Z))∘CZ12∘Toffoli\mathrm{Toffoli} \circ (\mathrm{id} \otimes (\mathrm{id} \otimes Z)) = (\mathrm{id} \otimes (\mathrm{id} \otimes Z)) \circ \mathrm{CZ}_{12} \circ \mathrm{Toffoli}.

What Is Checked

Lean has checked that both equations are well typed: the two sides are gates on the same three-qubit register, built from the controlled gates, the Paulis and the placements defined above, and each of those definitions elaborates. It has checked nothing about a proof, since there is none. What it cannot check is that the equations are the book’s diagrams. The library has no diagrams; the formalisers read Figure 10.67 and wrote these terms, and whether, for instance, CZ12\mathrm{CZ}_{12} is the controlled-ZZ the drawing shows is a judgement for the reader, made easier by the fact that every gate here is one named definition.