Synthesizing Multi-Qubit Gates
The Toffoli (CCX) gate is the quantum AND: it flips its target only when both controls are . It is indispensable for oracles, arithmetic, and error correction — yet no superconducting or trapped-ion device implements a native three-qubit gate. Every Toffoli that runs on hardware has first been synthesized out of one- and two-qubit gates.
From CCX to CCZ
The first move is a conjugation identity you met earlier:
Sandwiching the target between Hadamards converts the doubly-controlled into a doubly-controlled . CCZ is symmetric and phase-only: it applies a exactly to . That phase can be distributed among the three qubits as controlled rotations, which is where the gates enter.
The seven-T construction
The textbook decomposition realizes the interior CCZ with six CNOTs and seven -phase gates ( and its inverse ):
The alternating CNOT ladder routes the parity of the two controls onto the target, the and gates imprint the phases so they constructively combine only on , and the final –/– block cancels the unwanted relative phase between the two control qubits.
Why the order is delicate
Unlike a uniform superposition, this circuit cannot be reordered freely: the CNOTs and gates share qubits, so adjacent operations do not commute. Each must land between the right pair of CNOTs for the phases to interfere correctly. Get one gate out of place and the circuit still produces some unitary — just not the Toffoli. This is exactly why the grader checks the full matrix rather than a single output state.
Try it
Synthesize with controls 0, 1 and target 2 using only h, t,
tdg, and cx. The grader compares the complete three-qubit unitary up to
global phase.
Sign in on the full site to ask questions and join the discussion.