A Hoare Proof of Grover Search
A Hoare Proof of Grover Search
Combine initialization, amplitude rotation, counter-loop termination and final measurement into a correctness proof of Grover search.
Chapter 6 §6.6, printed pages 127–130 (PDF pages 37–40), including Figures 6.6–6.7 and equations 6.35–6.38, were checked visually. We distinguish general success probability from the exact-success special case used to illustrate the textbook derivation.
Registers, specification and angle
There are candidates and solutions. Let and be uniform superpositions of solutions and nonsolutions. Define . The prepared search state is
One Grover iteration rotates by in this plane. After iterations,
Choosing the nearest integer to gives . Printed page 127 displays , which can exceed 1. We use denominator , derived from normalization, rather than silently reproducing this apparent printing error.
The success effect is , extended by identities on auxiliary registers. The goal is , not certain success for arbitrary parameters.
Program and loop body
Initialize the search register, auxiliary qubit and integer counter to zero, then prepare . The oracle acts as ; the auxiliary minus state converts this into phase marking.
The loop measurement has and . Body applies the oracle, diffusion and . On the integer space, increment is a bilateral shift unitary. Finally measure the search register in the computational basis.
Invariant and body proof
Write , where is the Grover iteration. Define
Orthogonal counter blocks make a bounded effect. With , rotation and increment give . The unitary and sequential rules yield . The initialized state lies in the eigenvalue-one subspace of .
Termination and a general ranking function
On initialized executions the counter starts at zero and exits after exactly iterations. Applying (R.LT) on its entire state domain requires more than this reachable-state observation.
A threshold ranking avoids taking a maximum over an infinite counter support. Let and . For every , define
Finite trace implies that the negative-integer tail has vanishing mass. Each iteration shifts that tail rightward, so continuing mass tends to zero and the set is nonempty. Removing the first step cannot increase the rank; when current assertion mass reaches the threshold, the rank strictly decreases. Together with the total-correctness premise for the body, (R.LT) gives . This establishes almost-sure termination, not a uniform finite bound for arbitrary inputs.
Success probability and final measurement
The final measurement preserves the diagonal success effect: . Initialization erases the original input, and the loop produces a fixed final state of success weight . Trace semantics and wp duality therefore give , proving the specification.
For its illustrative qTD proof, the textbook additionally assumes and that is an integer. Then the final search state is the unique solution and ; the consequence rule completes the probability-one proof. That extra integer assumption must not be generalized into an unconditional exact-success theorem.
Source and scope
Chapter 6 DOI, §6.6. This entry uses the formal Hoare rules. The threshold ranking replaces boundary-sensitive counter-support expressions and separates the textbook special case from the general probability specification. The model assumes ideal gates and a correct oracle; noise, approximate gates and faulty oracle implementations are outside this proof.