Documentation

CslibFrontier.Computability.QueryComplexity.Quantum.Grover

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 #

Main results #

References #

@[reducible, inline]

Control-bit component p.2.1 of a Grover basis state p : Fin N × Bool × Unit.

@[simp]
theorem Cslib.Quantum.groverControl_mk {N : ℕ} (i : Fin N) (b : Bool) (u : Unit) :
noncomputable def Cslib.Quantum.uniform (N : ℕ) :

The uniform superposition |s⟩ = N^{-1/2} ∑_i |i, 1⟩ with control bit 1.

theorem Cslib.Quantum.norm_uniform {N : ℕ} (hN : 0 < N) :

The diffusion D = 2|s⟩⟨s| - I: the reflection about the uniform superposition.

theorem Cslib.Quantum.diffusion_apply {N : ℕ} (hN : 0 < N) (ψ : State N Unit) (p : Fin N × Bool × Unit) :
((diffusion N) ψ).ofLp p = (2 * if groverControl p = true then (↑N)⁻¹ * ∑ q : Fin N × Bool × Unit, if groverControl q = true then ψ.ofLp q else 0 else 0) - ψ.ofLp p

The diffusion inverts every control-1 amplitude about their mean: (Dψ)(i, b) = 2 b · mean_j ψ(j, 1) - ψ(i, b).

noncomputable def Cslib.Quantum.grover (N a✝ : ℕ) :

The isometries of Grover's algorithm: the identity, then the diffusion after every query. Its initial state is uniform N.

noncomputable def Cslib.Quantum.groverAngle (N : ℕ) :

The Grover angle θ = arcsin(1 / √N).

noncomputable def Cslib.Quantum.searchAngle (N t : ℕ) :

The angle θ ∈ [0, π / 2] with sin² θ = t / N.

theorem Cslib.Quantum.sin_searchAngle {N t : ℕ} (ht : t ≤ N) :
Real.sin (searchAngle N t) = √(↑t / ↑N)
theorem Cslib.Quantum.cos_searchAngle {N : ℕ} (t : ℕ) :
Real.cos (searchAngle N t) = √(1 - ↑t / ↑N)
theorem Cslib.Quantum.run_grover_of_weight {N : ℕ} (hN : 0 < N) (x : Fin N → Bool) (k : ℕ) (p : Fin N × Bool × Unit) :
(run (grover N) (uniform N) x k).ofLp p = if groverControl p = true then ↑(if x p.1 = true then Real.sin ((2 * ↑k + 1) * searchAngle N (BitString.weight x)) / √↑(BitString.weight x) else Real.cos ((2 * ↑k + 1) * searchAngle N (BitString.weight x)) / √(↑N - ↑(BitString.weight x))) else 0

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.

theorem Cslib.Quantum.run_grover {N : ℕ} [DecidableEq (Fin N)] (hN : 2 ≤ N) (z : Fin N) (k : ℕ) (p : Fin N × Bool × Unit) :
(run (grover N) (uniform N) (marked z) k).ofLp p = if groverControl p = true then ↑(if p.1 = z then Real.sin ((2 * ↑k + 1) * groverAngle N) else Real.cos ((2 * ↑k + 1) * groverAngle N) / √(↑N - 1)) else 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.

theorem Cslib.Quantum.regProb_run_grover {N : ℕ} [DecidableEq (Fin N)] (hN : 2 ≤ N) (z : Fin N) (k : ℕ) :
regProb (run (grover N) (uniform N) (marked z) k) z = Real.sin ((2 * ↑k + 1) * groverAngle N) ^ 2

Grover's success probability: after k queries on the input marking z, measuring the query register gives z with probability sin²((2k + 1) θ).

theorem Cslib.Quantum.grover_success {N : ℕ} [DecidableEq (Fin N)] (hN : 2 ≤ N) (z : Fin N) :

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.