Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Grover's algorithm finds the marked item with probability ≥1−1/N\ge 1 - 1/N≥1−1/N within ⌈π4N⌉\lceil\frac{\pi}{4}\sqrt N\rceil⌈4π​N​⌉ iterations

Proved
GroverWiki.grover_search

by Lucas · Oct 13, 2026 · Mathlib 0df444a (Lean v4.33.1)

grover-algorithmquantum-computingquantum-search

Let N≥1N \ge 1N≥1 and let f ⁣:{0,1,…,N−1}→{0,1}f\colon\{0,1,\dots,N-1\}\to\{0,1\}f:{0,1,…,N−1}→{0,1} have exactly one index ω\omegaω with f(ω)=1f(\omega) = 1f(ω)=1. Let Uω∣x⟩=(−1)f(x)∣x⟩U_\omega|x\rangle = (-1)^{f(x)}|x\rangleUω​∣x⟩=(−1)f(x)∣x⟩ be the oracle, ∣s⟩=1N∑x∣x⟩|s\rangle = \frac{1}{\sqrt N}\sum_x |x\rangle∣s⟩=N​1​∑x​∣x⟩ the uniform superposition and Us=2∣s⟩⟨s∣−IU_s = 2|s\rangle\langle s| - IUs​=2∣s⟩⟨s∣−I the Grover diffusion operator. Then there is a number of iterations rrr with

r≤⌈π4N⌉and∣⟨ω∣(UsUω)r∣s⟩∣2≥1−1N.r \le \left\lceil \frac{\pi}{4}\sqrt N\right\rceil \qquad\text{and}\qquad \bigl|\langle\omega|(U_sU_\omega)^r|s\rangle\bigr|^2 \ge 1 - \frac1N .r≤⌈4π​N​⌉and​⟨ω∣(Us​Uω​)r∣s⟩​2≥1−N1​.

That is, Grover's algorithm — prepare ∣s⟩|s\rangle∣s⟩, apply the Grover iteration UsUωU_sU_\omegaUs​Uω​ rrr times, measure in the computational basis — outputs ω\omegaω with probability at least 1−1/N1 - 1/N1−1/N (in particular at least 1/21/21/2 for N≥2N \ge 2N≥2, and approaching 111 for N≫1N \gg 1N≫1) using r=O(N)r = O(\sqrt N)r=O(N​) applications of UωU_\omegaUω​, compared with the Θ(N)\Theta(N)Θ(N) evaluations needed classically.

Preamble
import Mathlib
import Definitions.Def_GroverWiki_Defs

open Matrix
Formal statement
namespace GroverWiki

/-- Grover's algorithm: with at most `⌈(π/4)√N⌉` Grover iterations (hence `O(√N)` applications of
`U_ω`), measuring the state yields the unique marked index `ω` with probability at least
`1 - 1/N`. -/
theorem grover_search {N : ℕ} (f : Fin N → Fin 2) (ω : Fin N)
    (hω : ∀ x, f x = 1 ↔ x = ω) :
    ∃ r : ℕ, r ≤ ⌈Real.pi / 4 * Real.sqrt N⌉₊ ∧
      1 - 1 / (N : ℝ) ≤ measureProb (groverState f r) ω := by sorry

end GroverWiki
Source
Wikipedia, "Grover's algorithm", revision oldid=1373498442, https://en.wikipedia.org/w/index.php?title=Grover%27s_algorithm&oldid=1373498442, lead section (PDF p. 1), section "Problem description" (PDF pp. 2–3) and section "Algorithm" (PDF p. 4)
Human review
  • Endorsed by Shuze Chen · Oct 13, 2026

    Confirmed by the moderator at approval.

  • Endorsed by Lucas · Oct 13, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paper
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me