Building a quantum oracle for some classical function f often means implementing ordinary logic gates — AND, OR, NOT — inside a quantum circuit. The catch: every quantum gate has to be reversible (Ch. 4: unitary), and a plain classical AND gate genuinely isn't — given the output, you can't recover the two inputs. The Toffoli gate is the fix: a reversible version of AND, and the single gate this entire problem reduces to.
The definition
Toffoli, also written CCX (controlled-controlled-X), acts on 3 bits: two controls a, b and a target c. It flips c if and only if both a and b are 1, and leaves a and b completely untouched:
CCX: (a, b, c) ↦ (a, b, c ⊕ (a AND b))
Why reversibility matters here specifically
Ch. 4 established that every quantum gate must be unitary, and unitary matrices are always invertible — quantum circuits can never destroy information the way a classical AND gate does (two 1-bit inputs collapsing to one bit of output, with no way back). Toffoli sidesteps this by keeping a and b around unchanged and only ever flipping c, which makes the whole operation its own perfect inverse: applying CCX twice returns exactly the original state.
AdvancedUniversality: Toffoli alone can build anything reversible
The deeper reason this chapter exists at all: the Toffoli gate, together with simple bit preparation and discarding, is universal for classical reversible computation — any classical reversible circuit, of any size, can be built entirely out of Toffoli gates. Set c=0 as an ancilla and CCX literally computes ordinary AND; wire a NOT gate in front of an input and you get NAND, which is itself classically universal. This is exactly why oracle circuits for upcoming algorithms (Grover's, Ch. 28, in particular) get built from Toffoli gates: any classical function f can be compiled into Toffoli-based reversible logic, then wrapped with Ch. 23's phase-kickback trick to become a proper quantum phase oracle.
- ArticleWikipedia — Toffoli gateConfirms the universality-for-reversible-computation claim with further references.
- TextbookNielsen & Chuang, §1.4.1Reversible classical computation as a bridge to quantum circuits.