The Exercise
Figure 4.9 of the book draws a circuit on three qubits made of sixteen gates: two Hadamards on the target wire, six CNOTs, seven gates or , and one . Exercise 4.24, on page 182, asks the reader to verify that this circuit is the Toffoli gate. The point of the figure is that the Toffoli gate, which is not in the standard set, can be assembled from gates that are, and the Toffoli gate in turn gives universal classical computation on a quantum computer.
The library has no figure. It has the circuit as a term, cut into two blocks the way the figure reads, and the exercise as an equation between two unitaries. These notes write out the gates, the two blocks and the equation.
Gates and Wires
Four single-qubit gates occur. The Hadamard and the Pauli are the usual ones. The others are phase gates: the library has one definition , the unitary that leaves alone and multiplies by , and the book’s gates are three values of it, (1)✦
The register is , bracketed to the right, and a gate sits on a wire by being tensored with the identity on the others. We write the wire as a subscript, so the gates on this register are (2) A CNOT is the controlled , written for the gate controlled by the first qubit, and which two wires it joins is again read off the tensor structure, (3) Composition is written and means first, then , so in a chain the rightmost gate acts first, the opposite of reading the figure from left to right.✦
The Two Blocks
The figure splits naturally at the Hadamards. Between them lie eight gates, all on the target wire or ending on it, (4)✦ read right to left: a CNOT from the second control, a , a CNOT from the first control, a , and the same four once more. After the second Hadamard come six gates on the two control wires alone, (5)✦ This block never touches the target; its job is to put the right relative phases on the controls.
The Circuit
The whole figure is a Hadamard on the target, the block , a second Hadamard on the target, then the block : (6)✦ Only , , and CNOT occur in it, which is what the construction is for.
The Claim
The exercise is the statement that this unitary is the Toffoli gate, (7)✦= where flips the third qubit exactly when the first two are both . The standard way to see it is to follow a basis state through the circuit and collect the phases: the Hadamards turn a phase flip of the target into a bit flip, supplies the phase on the target up to a phase on the controls, and removes that leftover. The library does not contain this calculation.
Theorem 1. On three qubits, .✦
What Is Checked
Lean has checked that the two blocks and the circuit are well-typed unitaries on the three-qubit register, built from the phase gate, the Hadamard, the controlled gates and the wire placements above, and that the equation is well typed. It has checked nothing about a proof, since there is none. The subscripted names on this page are the page’s own notation, declared in the displays with ; the matcher unfolds them before it compares a formula with the Lean term, so a wrong wire in one of them would break the certification of every formula that uses it. What it cannot check is that the term is the figure on page 182: that the sixteen gates are in the book’s order and on the book’s wires. The two block definitions and the circuit each carry a drawing derived from the term, which is the material for that judgement.