Case Study 1: The Oracle That Cost More Than the Algorithm Saved
The proposal
A team has a constraint-satisfaction problem over a 20-bit search space — roughly a million candidates — and a classical checker that verifies a candidate in microseconds.
They propose Grover's algorithm. The reasoning is textbook and correct as far as it goes:
- Classical brute force: $\mathcal{O}(N) = 10^6$ checks.
- Grover: $\mathcal{O}(\sqrt N) \approx 1{,}000$ oracle queries.
- A thousandfold reduction in queries.
The theorem is real. The lower bound is proved. And the proposal is still wrong, for reasons that only appear when you price the oracle.
Pricing the oracle
Their predicate is a conjunction of constraints over 20 bits. Even the simplest possible 20-input oracle — recognizing a single marked state — requires a 20-controlled operation. Extrapolating §19.5's measured Clifford+T costs:
n CX T
2 6 7
4 36 2,605
6 136 12,002
8 264 26,978
10 464 30,816
With no ancillas, the cost at $n = 20$ is far beyond any of these. With ancillas it is far better — §19.6's V-chain is linear — so take the favourable case:
$$\text{T count} \approx 14(n-1) \approx 266 \text{ T gates per oracle call}$$
And that is for the trivial predicate. A real constraint checker composes many such conjunctions, each with its own ancillas and uncomputation, so a few thousand T gates per query is optimistic.
Now multiply:
$$1{,}000 \text{ queries} \times \sim 3{,}000 \text{ T gates} \approx 3 \times 10^6 \text{ T gates}$$
Feed that to Chapter 15's estimator and the answer is a fault-tolerant machine running for a long time. The classical alternative is a million microsecond checks — about one second on one core, or milliseconds if you parallelize.
The quantum algorithm needs a machine that does not exist to beat a second of laptop time.
Where the reasoning went wrong
Not in the theorem. In the units.
Query complexity counts oracle invocations. It does not count what an invocation costs.
The comparison "$10^6$ classical operations versus $10^3$ quantum queries" silently compares two different things: a classical operation — one microsecond of a real CPU — against a quantum query, which is thousands of fault-tolerant T gates.
The ratio that matters is not $10^6 / 10^3$. It is
$$\frac{10^6 \times (\text{cost of one classical check})}{10^3 \times (\text{cost of one oracle call})}$$
and the second cost is enormous.
The three gaps, in this case
§19.7 listed three gaps between "one query" and "one operation." All three are present here.
The oracle is not free. Thousands of T gates per call, and Chapter 15 §15.8 measured that T gates are essentially the entire cost of a fault-tolerant computation — one T gate takes a machine from 450 to 2,882 physical qubits.
The oracle must exist as a reversible circuit. Their classical checker is a few hundred lines of ordinary code with early exits, lookup tables, and short-circuit evaluation. None of that survives reversibility. Every branch must be computed, every intermediate stored in ancillas, and every ancilla uncomputed (§19.4). The reversible version is not a translation of the classical checker; it is a substantially larger object.
The classical bound is over query-only algorithms. $\Omega(N)$ is a lower bound for a classical algorithm that can only ask the oracle "is this one the answer?" Their classical checker is not query-only — it inspects structure, prunes, and short-circuits. Constraint propagation on 20 bits is not a million blind checks; it is a search tree that a decent solver prunes to a tiny fraction.
Against the actual classical algorithm, the quadratic speedup is over a straw man.
What would make it work
The analysis is not "quantum never helps." It is a set of conditions, and they are checkable in advance.
The oracle must be cheap relative to the query count. If a query costs $c$ T gates and you make $\sqrt N$ of them, the quantum cost goes as $c\sqrt N$ against classical $N$. The crossover needs $c \ll \sqrt N$ — so large $N$ helps and expensive oracles hurt, and both scale.
The problem should be one where the classical algorithm really is close to brute force. Grover's advantage is largest exactly where structure is absent, which is also where the problem is least likely to be one anyone cares about. This tension is real and Chapter 21 §21.7 takes it seriously.
And $N$ must be large enough that $\sqrt N$ matters more than the constant factors. A thousandfold query reduction against a several-thousandfold per-query cost is not a speedup; it is a rounding error with extra steps.
What they should have measured first
Three numbers, none of which requires writing the algorithm:
1. The T count of one oracle call. oracle_cost(circuit) from §19.6's checkpoint, with rz
excluded from the basis so the number means something (§19.5's trap).
2. The total: queries × per-query T count. Then Chapter 15's estimator on that total.
3. The wall-clock time of the actual classical algorithm — not the theoretical brute-force bound, but the solver they would really use.
That is an afternoon's work, and it is the difference between a two-year project and a decision.
The lessons
Price the oracle before believing the speedup. Query complexity is rigorous and it measures queries. The cost of a query is a separate question with a separate answer, and for anything fault-tolerant that answer is measured in T gates.
A reversible implementation is not a translation. Early exits, lookup tables, and short-circuit evaluation — the things that make classical checkers fast — do not survive reversibility. Every branch is computed, every intermediate stored, every ancilla uncomputed.
Compare against the classical algorithm you would actually run. The $\Omega(N)$ lower bound holds for query-only classical algorithms, and real solvers are not query-only. A speedup over a straw man is not a speedup.
The conditions are checkable in advance and cheaply. Three measurements, one afternoon. Chapter 15 §15.9's recommendation — learn the resource estimator without adopting the language — exists for exactly this kind of decision.
And the recurring theme, in a new register: the theorem was correct, the arithmetic was correct, and the conclusion was wrong, because the two sides of the comparison were measured in different units. A number can be precise, reproducible, and about something other than what you think — which is now the seventh chapter in which that has been the lesson.
Reproduce it: code/example-03-what-an-oracle-costs.py for the T counts and the rotation trap;
code/example-04-ancilla-tradeoff.py for the favourable case; oracle_cost() in
code/project-checkpoint.py for your own predicate.