Grover's algorithm #
Grover's algorithm finds the marked item among N ≥ 2 with O(√N) queries, matching the BBBV
lower bound (Cslib.Quantum.card_sub_two_le) up to a constant Grover. In the query
model of Cslib.Quantum.run, with a trivial workspace, it starts in the uniform superposition
|s⟩ of the query indices with control bit 1 (Cslib.Quantum.uniform) and alternates the
controlled phase oracle with the diffusion D = 2|s⟩⟨s| - I, the reflection about |s⟩
(Cslib.Quantum.diffusion, Cslib.Quantum.grover). The state never leaves the control-1
subspace, where the oracle acts as the phase oracle (-1)^{x_i}.
Let θ = arcsin(1 / √N). After k queries on the input marking z, the amplitude of z is
sin((2k + 1) θ) and every other amplitude with control bit 1 is cos((2k + 1) θ) / √(N - 1)
(Cslib.Quantum.run_grover): each round rotates the state by 2θ in the plane spanned by |z⟩
and the uniform superposition of the other items. So z is measured with probability
sin²((2k + 1) θ) (Cslib.Quantum.regProb_run_grover). With k = ⌊π / (4θ)⌋ ≤ π√N / 4 queries,
(2k + 1) θ lies within θ of π / 2, and the success probability is at least 1 - 1 / N
(Cslib.Quantum.grover_success).
Source mapping. The algorithm is Grover's (§3 of arXiv:quant-ph/9605043v3): it alternates the
inversion of the phase of the marked item with the diffusion transform D_ij = 2/N for i ≠ j,
D_ii = -1 + 2/N (equation (4.0)), the inversion about the average (§4). Grover takes N = 2^n
and implements D = WRW with Walsh–Hadamard transforms (Theorem 1 in §5); here D is the
reflection about |s⟩ for every N ≥ 2, and only queries are counted. Grover shows a success
probability of at least 1/2 after O(√N) iterations. The closed form sin((2k + 1) θ) and the
choice ⌊π / (4θ)⌋, with failure probability at most 1/N and at most π√N / 4 iterations, are
from Boyer, Brassard, Høyer, Tapp (numbering of
arXiv:quant-ph/9605034v1): §2, equation (2), and §3 with one solution. For N = 4 the angle is
π / 6 and one query succeeds with certainty, their §3.1.
The general marked-weight formula is shared with the unknown-count search analysis:
run_grover_of_weight handles all marked counts, and run_grover specializes it to one
marked item.
Main definitions #
Cslib.Quantum.searchAngle: the angle for an arbitrary number of marked items.Cslib.Quantum.uniform: the uniform superposition.Cslib.Quantum.diffusion: the reflection about the uniform superposition.Cslib.Quantum.grover: the isometries of Grover's algorithm.
Main results #
Cslib.Quantum.run_grover_of_weight: the state for any number of marked items.Cslib.Quantum.run_grover: the state of Grover's algorithm afterkqueries.Cslib.Quantum.regProb_run_grover: its success probabilitysin²((2k + 1) θ).Cslib.Quantum.grover_success:⌊π / (4θ)⌋ ≤ π√N / 4queries find the marked item with probability at least1 - 1 / N.
References #
The uniform superposition |s⟩ = N^{-1/2} ∑_i |i, 1⟩ with control bit 1.
The angle θ ∈ [0, π / 2] with sin² θ = t / N.
Grover's algorithm with any number of marked items Boyer, Brassard, Høyer,
Tapp: on an input with t marked items, after k queries, with
control bit 1, every marked item has amplitude sin((2k + 1) θ) / √t and every other item
cos((2k + 1) θ) / √(N - t), where sin² θ = t / N; with control bit 0, every amplitude is
0.
The state of Grover's algorithm after k queries on the input marking z: with control
bit 1, amplitude sin((2k + 1) θ) on z and cos((2k + 1) θ) / √(N - 1) elsewhere; with
control bit 0, amplitude 0.
Grover's success probability: after k queries on the input marking z, measuring the
query register gives z with probability sin²((2k + 1) θ).
Grover's algorithm Grover, with the analysis of Boyer, Brassard, Høyer,
Tapp: for N ≥ 2 and every z, with
T = ⌊π / (4θ)⌋ queries, where θ = arcsin(1 / √N), the algorithm outputs the marked item z
with probability at least 1 - 1 / N, and T ≤ π √N / 4.