Ch. 22 waved a magic wand and said "query an oracle." This chapter opens the box. An oracle is a black-box circuit implementing some function f — you don't get to look inside it or simplify it, only query it — and there are two completely standard ways to wire one up, which turn out to be secretly the same thing.
Convention 1: the bit-flip oracle
The most literal version: an extra "answer" qubit y, and the oracle computes Uf|x⟩|y⟩ = |x⟩|y⊕f(x)⟩ — XOR the function's output into y. This is exactly how Ch. 18's CZ-style construction and ordinary classical-logic-as-a-circuit intuitions work.
Convention 2: the phase oracle
The version every algorithm in this book actually uses: Uf|x⟩ = (−1)^f(x)|x⟩ — no extra qubit, just a sign flip on the basis state itself, depending on f(x). This is exactly the oracle from Fig. 22.1.
IntermediatePhase kickback: how convention 1 becomes convention 2
Prepare the answer qubit y in the state |−⟩ = (|0⟩−|1⟩)/√2 instead of |0⟩, then apply the bit-flip oracle. Work through what happens to |x⟩|−⟩: if f(x)=0, |−⟩ is untouched; if f(x)=1, XOR flips it to (|1⟩−|0⟩)/√2 = −|−⟩. Either way, |−⟩ comes back completely unchanged — and the sign it would have flipped lands instead on the x register as a phase:
Uf|x⟩|−⟩ = (−1)^f(x)|x⟩|−⟩
This is called phase kickback, and it's the single most important trick in this part of the book: it converts any bit-flip oracle into exactly the phase oracle every algorithm needs, just by preparing the ancilla differently.
Why oracle complexity is the right way to compare algorithms
Treating f as a black box isn't a simplification for teaching purposes — it's the actual standard for comparing quantum and classical algorithms fairly. "Query complexity" counts only oracle calls, deliberately ignoring how f itself is implemented, which isolates exactly the quantum advantage being claimed. Ch. 26's Deutsch–Jozsa algorithm needs exactly 1 oracle query no matter how large n gets; the best possible classical algorithm needs up to 2^(n−1)+1 queries in the worst case. That comparison is only meaningful because both sides agree on what counts as "one query" — which is precisely the oracle abstraction this chapter just built.
- TextbookNielsen & Chuang, §1.4.4The original phase-kickback derivation this chapter follows.
- ToolQiskit textbook (qiskit.org)Worked examples building oracle circuits explicitly with ancilla qubits.