Searching an unsorted list of items for a single marked entry takes queries classically — there is no way to do better than checking items one at a time. Grover's algorithm (Grover 1996) shows that a quantum computer solves the same problem in queries, a quadratic speedup that applies to any problem expressible as unstructured search over a black-box oracle (this includes brute-forcing NP-complete problems and inverting one-way functions, which is why post-quantum cryptography doubles key lengths to compensate). Unlike Shor's algorithm, Grover's algorithm is provably optimal: Bennett–Bernstein–Brassard–Vazirani (1997) showed queries are necessary for any quantum algorithm solving unstructured search, so the quadratic speedup is the best any quantum algorithm can achieve on this problem.
Model an -item database as the standard basis of (EuclideanSpace ℂ (Fin N)),
with inner product . Fix a marked index
. The algorithm starts in the uniform superposition
a unit vector assigning equal amplitude to every item. Two reflections drive the search:
One Grover iterate is . The algorithm applies some number of times to and measures; a measurement outcome equal to counts as success.
and are each reflections about a unit vector, hence isometries; their composition is therefore norm-preserving on the whole space, not just at — the minimal fact needed for to be a legitimate quantum operation.
The geometric heart of the algorithm (Nielsen & Chuang, Quantum Computation and Quantum Information, Section 6.1.2): restricted to the real two-dimensional subspace spanned by and the component of orthogonal to it, acts as rotation by a fixed angle . Each iterate therefore advances the amplitude on the marked state along , exactly as claimed, with the rotation's initial offset (since at ).
Some number of iterations drives the probability of measuring the marked item above . The goal is stated existentially, without fixing to a specific rounded formula: the rotation angle can be made to land within of by an appropriate integer , and at that point . Pinning down to an explicit closed form (e.g. the nearest integer to ) is one valid strategy, but is not required by the statement — any correct choice of , and any correct proof it works, closes the goal.
Grover's algorithm is the second landmark quantum algorithm after Shor's, and the one with the
widest applicability: because it treats the search space as a black box, it accelerates any
brute-force search — SAT solving, collision finding, and generic key search among them — which is
the concrete reason NIST's post-quantum cryptography standards double symmetric key lengths rather
than replacing them outright. The mathematics itself has been fully settled since 1996, including
matching optimality lower bounds; nothing here is open. What this mission adds is a machine-
checked derivation of the amplitude formula and success bound directly from the definitions of
the oracle and diffusion operators as concrete linear operators on EuclideanSpace ℂ (Fin N) —
Mathlib has the finite-dimensional inner product space and rank-one operator machinery this needs
(InnerProductSpace.rankOne, EuclideanSpace.single), but no existing formalization of the
algorithm itself.
The obvious first attempt tries to track the full -dimensional state vector through iterations. This is intractable in general: 's action on an arbitrary basis vector depends on its overlap with both and . The move that makes the problem tractable is recognizing that preserves the two-dimensional real subspace — everything orthogonal to this plane is fixed by both and , and inside the plane is exactly a rotation matrix by angle . Establishing this invariance and then tracking only the rotation angle (rather than the full vector) is the standard reduction, and the one this mission's milestones are built around; skipping it and attempting a direct -dimensional induction does not scale.
Works over a general together with a marked index — no
assumption that is a power of two, since the rotation argument is agnostic to how the basis
states are physically encoded into qubits (that encoding is a separate, unrelated concern from the
search dynamics proved here). Supplying w0 : Fin N already forces ; no separate
nonemptiness hypothesis is added. The oracle and diffusion operators are built directly from
Mathlib's InnerProductSpace.rankOne rather than an ad-hoc pointwise definition, so their
reflection structure (and hence unitarity) is visible from the definition itself. A trivializing
formalization is ruled out explicitly: the goal is stated as an existential over rather than a
fixed closed-form iteration count, so a correct proof must still exhibit a genuine successful
and establish the bound — it cannot be discharged by an unrelated or degenerate choice. Contributions
extending this to multiple marked items, or proving the matching lower bound
(Bennett–Bernstein–Brassard–Vazirani 1997), are welcome as follow-up missions.
namespace Grover
/-- **Grover's algorithm finds the marked item, in `O(√N)` iterations** (Goal). Starting from the
uniform superposition over `N` basis states, some number of applications of the Grover iterate,
bounded by `⌈π / (4·arcsin(1/√N))⌉` (which is `Θ(√N)`), produces a state in which the probability
of measuring the marked index `w0` is at least `1 - 1/N`. -/
theorem search_succeeds_bounded {N : ℕ} (w0 : Fin N) :
∃ k : ℕ, k ≤ ⌈Real.pi / (4 * Real.arcsin (1 / Real.sqrt N))⌉₊ ∧
(1 : ℝ) - 1 / (N : ℝ) ≤
‖inner (𝕜 := ℂ) (EuclideanSpace.single w0 (1 : ℂ))
((⇑(groverIterate w0))^[k] (uniformSuperposition N))‖ ^ 2 := by
sorry
end GroverThis is the goal theorem of the Grover's Algorithm mission, strengthened to give an explicit iteration-count bound, per moderator review feedback on the original goal.
Let N be at least 1 and fix a marked index w0 among the N basis states. Let |s> be the uniform superposition over the N basis states, and let G be the Grover iteration operator (oracle reflection about w0 followed by reflection about |s>) associated to w0. Set theta = arcsin(1/sqrt N).
There exists k, with k at most the ceiling of pi / (4*theta), such that 1 - 1/N is at most the squared norm of the inner product of the basis state |w0> with G^k |s>.
That is, applying the Grover iterate at most ceil(pi / (4*arcsin(1/sqrt N))) times -- a quantity that is Theta(sqrt N) -- already suffices to make the probability of measuring the marked index w0 at least 1 - 1/N. This makes explicit the headline claim of Grover's algorithm: the marked item is found using only O(sqrt N) oracle calls, in contrast to the O(N) needed classically.
Formalization Note This sharpens the mission's original goal search_succeeds, which asserted only the bare existence of a successful k with no bound on it; this version adds the explicit k <= ceil(pi / (4*theta)) bound, following in one line from the amplitude_rotation milestone by taking k = floor(pi / (4*theta)) <= ceil(pi / (4*theta)).
No open leaves. Every sub-goal is proved or awaiting decomposition.