Documentation

CslibFrontier.Computability.QueryComplexity.Quantum.UnknownSearch

Quantum search with an unknown number of marked items #

Grover's algorithm (Cslib.Quantum.grover) finds one of t marked items among N with O(√(N / t)) queries when t is known, but a fixed number of iterations can fail badly for an unknown t. Boyer, Brassard, Høyer and Tapp choose the number of iterations at random Boyer, Brassard, Høyer, Tapp. This file formalizes their analysis in the query model of Cslib.Quantum.run, the resulting fixed-budget search algorithm, and an algorithm computing OR_N with error 1/3 and O(√N) queries.

Shared Grover analysis. The general marked-weight analysis is provided by CslibFrontier.Computability.QueryComplexity.Quantum.Grover. Let θ = searchAngle N t, so sin² θ = t / N. After k queries every marked item has amplitude sin((2k + 1) θ) / √t and every other item cos((2k + 1) θ) / √(N - t) (Cslib.Quantum.run_grover_of_weight), so a marked item is measured with probability sin²((2k + 1) θ) (Cslib.Quantum.sum_regProb_run_grover).

A random number of iterations. If the number j of iterations is uniform below m, a marked item is found with probability P_m = 1/2 - sin(4mθ) / (4m sin 2θ) (Cslib.Quantum.sum_sin_sq_div, from the cosine sum Cslib.Quantum.two_mul_sin_mul_sum_cos), so P_m ≥ 1/4 when m ≥ 1 / sin 2θ (Cslib.Quantum.le_sum_sin_sq). If N ≤ m², then m ≥ 1 / sin 2θ for every 1 ≤ t < N (Cslib.Quantum.le_mul_sin_two_mul_searchAngle), and t = N succeeds with certainty.

The algorithm. Cslib.Quantum.randomGrover realizes the random choice inside the query model: its workspace holds a classical register j < m, prepared in uniform superposition (Cslib.Quantum.randomGroverInit); on the slice where the register holds j, Grover's algorithm runs j iterations and is then parked (Cslib.Quantum.controlled, Cslib.Quantum.park). Every outcome probability is then the average over j (Cslib.Quantum.sum_regProb_run_randomGrover). With m = ⌊√N⌋ + 1 it makes ⌊√N⌋ ≤ √N queries from a unit initial state and measures a marked item with probability at least 1/4 on every input with at least one marked item (Cslib.Quantum.randomGrover_search), whatever their number.

Deciding OR_N. With the larger range m = 4 (⌊√N⌋ + 1) (Cslib.Quantum.orRange), so that m sin 2θ ≥ 4, a marked item is found with probability at least 7/16. A stage (Cslib.Quantum.orStage) runs randomGrover and then checks the measured index with one more query (Cslib.Quantum.check), so it accepts with exactly the success probability P, which is 0 on the all-zero input. Running the stage twice (Cslib.Quantum.orSearch, Cslib.Quantum.twice) and accepting when either check succeeds gives acceptance probability 1 - (1 - P)² (Cslib.Quantum.measureProb_run_orSearch): 0 if OR_N(x) = 0, and at least 1 - (9/16)² > 2/3 if OR_N(x) = 1. So 8 (⌊√N⌋ + 1) ≤ 8√N + 8 queries compute OR_N with error at most 1/3 (Cslib.Quantum.orSearch_spec), matching the polynomial-method lower bound N ≤ 16 T² (Cslib.Quantum.card_le_sixteen_mul_sq_of_threshold_one_right) up to a constant.

Source mapping (numbering of arXiv:quant-ph/9605034v1). The closed form is equation (3) of §3, where k_j and ℓ_j are the amplitudes of a marked and an unmarked item after j iterations and sin² θ = t / N; here it is proved for every 0 ≤ t ≤ N. Queries are counted as in Cslib.Quantum.run, one application of the phase oracle per Grover iteration, whereas BBHT count two table look-ups per iteration with a bit oracle (§3.1). In §4, Lemma 1 is the sum ∑_{j < m} cos(α + 2βj), of which two_mul_sin_mul_sum_cos is the special case α = β stated there, multiplied out by 2 sin α. Lemma 2 is sum_sin_sq_div, and its bound P_m ≥ 1/4 for m ≥ 1 / sin 2θ follows from le_sum_sin_sq. BBHT then search with a range m growing by a factor λ = 6/5 after each failed round, observe and check the outcome, and prove an expected O(√(N / t)) time for 1 ≤ t ≤ 3N/4 (Theorem 3); they dispose of t > 3N/4 by classical sampling and of t = 0 by a time-out. Here the range is fixed, which gives a single algorithm with a fixed query budget ⌊√N⌋, and its success probability is bounded for every t ≥ 1 at once, including t > 3N/4. This fixed-budget packaging, the bound for 1 ≤ t < N from c² N ≤ m², the realization of the random j by a classical register in the workspace, and the decision algorithm for OR_N (a check query and two independent stages, with its constants) are not from the source; they are original here.

Main definitions #

Main results #

References #

theorem Cslib.Quantum.sum_regProb_run_grover {N : ℕ} (hN : 0 < N) (x : Fin N → Bool) (k : ℕ) :
∑ i : Fin N with x i = true, regProb (run (grover N) (uniform N) x k) i = Real.sin ((2 * ↑k + 1) * searchAngle N (BitString.weight x)) ^ 2

The success probability of Grover's algorithm with any number of marked items Boyer, Brassard, Høyer, Tapp: after k queries, a marked item is measured with probability sin²((2k + 1) θ), where sin² θ = t / N for t marked items.

Random iteration counts #

theorem Cslib.Quantum.two_mul_sin_mul_sum_cos (α : ℝ) (m : ℕ) :
2 * Real.sin α * ∑ j ∈ Finset.range m, Real.cos ((2 * ↑j + 1) * α) = Real.sin (2 * ↑m * α)

The cosine sum of Boyer, Brassard, Høyer, Tapp (Lemma 1 with α = β): 2 sin α ∑_{j < m} cos((2j + 1) α) = sin(2mα).

theorem Cslib.Quantum.sum_sin_sq_div (θ : ℝ) {m : ℕ} (hm : 0 < m) (hθ : Real.sin (2 * θ) ≠ 0) :
(∑ j ∈ Finset.range m, Real.sin ((2 * ↑j + 1) * θ) ^ 2) / ↑m = 1 / 2 - Real.sin (4 * ↑m * θ) / (4 * ↑m * Real.sin (2 * θ))

The average success probability of a random number of iterations Boyer, Brassard, Høyer, Tapp (Lemma 2): for j uniform below m, a marked item is found with probability P_m = 1/2 - sin(4mθ) / (4m sin 2θ), where sin² θ = t / N.

theorem Cslib.Quantum.le_sum_sin_sq (θ : ℝ) (m : ℕ) (hθ : 0 < Real.sin (2 * θ)) :
↑m / 2 - 1 / (4 * Real.sin (2 * θ)) ≤ ∑ j ∈ Finset.range m, Real.sin ((2 * ↑j + 1) * θ) ^ 2

A lower bound on the average success probability Boyer, Brassard, Høyer, Tapp (Lemma 2): if sin 2θ > 0, then ∑_{j < m} sin²((2j + 1) θ) ≥ m / 2 - 1 / (4 sin 2θ). In particular P_m ≥ 1/4 when m ≥ 1 / sin 2θ.

theorem Cslib.Quantum.le_mul_sin_two_mul_searchAngle {N t m : ℕ} {c : ℝ} (ht : 1 ≤ t) (htN : t < N) (hc : 0 ≤ c) (hm : c ^ 2 * ↑N ≤ ↑m ^ 2) :
c ≤ ↑m * Real.sin (2 * searchAngle N t)

For 1 ≤ t < N marked items and c² N ≤ m², the range m is at least c / sin 2θ.

Searching with an unknown number of marked items #

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

The isometries of search with a random number of Grover iterations below m, after Boyer, Brassard, Høyer, Tapp: a classical register j < m holds the number of iterations; on the slice where it holds j, Grover's algorithm runs j iterations and is then parked.

noncomputable def Cslib.Quantum.randomGroverInit (N m : ℕ) :

The initial state of randomGrover: the uniform superposition of the query indices, with control bit 1, and of the iteration counts j < m.

theorem Cslib.Quantum.norm_randomGroverInit {N : ℕ} (hN : 0 < N) {m : ℕ} (hm : 0 < m) :
theorem Cslib.Quantum.slice_run_randomGrover {N : ℕ} (hN : 0 < N) {m T : ℕ} (hT : m ≤ T + 1) (x : Fin N → Bool) (j : Fin m) :
slice j (run (randomGrover N m) (randomGroverInit N m) x T) = ↑(√↑m)⁻¹ • flipCtrl (run (grover N) (uniform N) x ↑j)

After T ≥ m - 1 queries, the slice of randomGrover where the register holds j is the state of Grover's algorithm after j queries, parked and scaled by 1 / √m.

theorem Cslib.Quantum.run_randomGrover_ctrl {N : ℕ} (hN : 0 < N) {m T : ℕ} (hT : m ≤ T + 1) (x : Fin N → Bool) (i : Fin N) (w : Unit × Fin m) :

After T ≥ m - 1 queries every branch of randomGrover is parked: the control bit is 0.

theorem Cslib.Quantum.sum_regProb_run_randomGrover {N : ℕ} (hN : 0 < N) {m T : ℕ} (hT : m ≤ T + 1) (x : Fin N → Bool) :
∑ i : Fin N with x i = true, regProb (run (randomGrover N m) (randomGroverInit N m) x T) i = (∑ j ∈ Finset.range m, Real.sin ((2 * ↑j + 1) * searchAngle N (BitString.weight x)) ^ 2) / ↑m

The success probability of a random number of iterations: after T ≥ m - 1 queries, randomGrover measures a marked item with probability (1 / m) ∑_{j < m} sin²((2j + 1) θ), the average over j < m of the success probability of j Grover iterations.

theorem Cslib.Quantum.le_sum_regProb_run_randomGrover {N : ℕ} (hN : 0 < N) {m : ℕ} {c : ℝ} (hc : 0 < c) (hm : c ^ 2 * ↑N ≤ ↑m ^ 2) (x : Fin N → Bool) (hx : ∃ (i : Fin N), x i = true) :
1 / 2 - 1 / (4 * c) ≤ ∑ i : Fin N with x i = true, regProb (run (randomGrover N m) (randomGroverInit N m) x (m - 1)) i

Quantum search with an unknown number of marked items Boyer, Brassard, Høyer, Tapp: if c² N ≤ m² with c > 0, then on every input with at least one marked item, randomGrover measures a marked item with probability at least 1/2 - 1/(4c) after m - 1 queries.

Deciding OR_N with error 1/3 #

The range of iteration counts for deciding OR_N: m = 4 (⌊√N⌋ + 1), so that 16 N ≤ m².

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

One stage for OR_N: randomGrover with range orRange N for orRange N - 1 queries, then a check of the measured index, which writes its queried bit into the control bit. It makes orRange N queries.

The algorithm for OR_N: two independent stages (Cslib.Quantum.twice), making 2 orRange N queries.

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

The initial state of orSearch: two copies of the initial state of randomGrover.

The accepting outcomes of orSearch: the check bit of either stage is 1.

theorem Cslib.Quantum.measureProb_run_orStage {N : ℕ} (hN : 0 < N) (x : Fin N → Bool) :
measureProb (run (orStage N) (randomGroverInit N (orRange N)) x (orRange N)) {x : Fin N × Bool × Unit × Fin (orRange N) | match x with | (fst, b, snd) => b = true} = ∑ i : Fin N with x i = true, regProb (run (randomGrover N (orRange N)) (randomGroverInit N (orRange N)) x (orRange N - 1)) i

A stage accepts with the average success probability of randomGrover.

The initial state of orSearch is a unit vector.

theorem Cslib.Quantum.measureProb_run_orSearch {N : ℕ} (hN : 0 < N) (x : Fin N → Bool) :
measureProb (run (orSearch N) (orSearchInit N) x (orRange N + orRange N)) (orAccept N) = 1 - (1 - (∑ j ∈ Finset.range (orRange N), Real.sin ((2 * ↑j + 1) * searchAngle N (BitString.weight x)) ^ 2) / ↑(orRange N)) ^ 2

The acceptance probability of orSearch: 1 - (1 - P)², where P is the average success probability of randomGrover with range orRange N.

Deciding OR_N with O(√N) queries after Boyer, Brassard, Høyer, Tapp: orSearch accepts every input x with probability within 1/3 of OR_N(x). It accepts the all-zero input with probability 0, and every other input with probability at least 1 - (9/16)².

theorem Cslib.Quantum.orSearch_spec {N : ℕ} (hN : 0 < N) :
‖orSearchInit N‖ = 1 ∧ ↑(orRange N + orRange N) ≤ 8 * √↑N + 8 ∧ ∀ (x : Fin N → Bool), |measureProb (run (orSearch N) (orSearchInit N) x (orRange N + orRange N)) (orAccept N) - BitString.bitVal ℝ (threshold N 1 x)| ≤ 1 / 3

An O(√N)-query algorithm for OR_N with error 1/3, matching the polynomial-method lower bound N ≤ 16 T² up to a constant: orSearch starts from a unit state, makes 8 (⌊√N⌋ + 1) ≤ 8 √N + 8 queries, and accepts every input x with probability within 1/3 of OR_N(x).