Documentation

CsdLean4.Empirical.QM.Algorithms.Grover

Grover's search algorithm (R5+) — as an instance of amplitude amplification #

Category: 3-Local (QM-validity).

Grover's algorithm: search for a single marked item w : Fin n → Fin 2 in an unstructured database of N = 2ⁿ items. The search step is the composition of the oracle (phase flip on w, I - 2|w⟩⟨w|) and the diffusion operator (inversion about the mean, 2|s⟩⟨s| - I, where |s⟩ is the uniform superposition).

Rebuilt 2026-08-29 (plan specs/amplitude-amplification-plan.md, brick AA-3): the step operators are proved to be the BHMT amplification step of Mathlib/QuantumInfo/AmplitudeAmplification.leanoracle w = oracleFlip {w} (oracle_eq_oracleFlip) and diffusion = reflect uniformState (diffusion_eq_reflect) — and the headline is re-derived from the general theorem: the uniform state is the rotation-plane state at the Grover angle (uniformState_eq_ampState), so ampStep_iterate gives

grover_success : prob ((groverStep w)^[k] uniformState) w = sin²((2k+1)·θ),

sin θ = 1/√N. The file's previous self-contained rotation development (the symState coefficient family and its operator-action lemmas) is retired — the general two-reflection rotation now carries it, and keeping both would be exactly the parallel-development duplication the Algorithm Atlas assessment (RESULT 4) documents. New at the same stroke, free from the general theorem: the k-marked-items distribution grover_multi_success, which the single-marked file could not state.

Honest scope. QM-validity breadth: genuine reflection operators on the EuclideanSpace inner-product structure; amplitudes real, carried as -coercions. The optimal iteration count and the success bound live with the general theorem (amplitude_amplification_succeeds, amplification_query_bound) — the deferral the earlier version of this file recorded is closed there, not here. Round counting is abstract-step counting; no oracle model is claimed.

Extraction cost record (the atlas assessment's priced pilot, AA-3): the rebuild of this file on the general theorem — bridge lemmas, plane instantiation, re-derived headlines, deleted parallel development — took ≈25 minutes wall-clock including two build-fix iterations (2026-08-29, 14:22–14:47 session segment). The full AA-1..AA-3 session (general module written and debugged + this refactor) was ≈90 minutes. See specs/amplitude-amplification-plan.md.

The database size N = 2ⁿ as a real number.

Equations
Instances For

    The all-ones vector J = ∑ z |z⟩: amplitude 1 on every basis state.

    Equations
    Instances For
      theorem CSD.Empirical.QM.Grover.J_coord {n : } (z : Fin nFin 2) :
      (J n).ofLp z = x : Fin nFin 2, (QuantumInfo.basisState x).ofLp z
      @[simp]
      theorem CSD.Empirical.QM.Grover.J_apply {n : } (z : Fin nFin 2) :
      (J n).ofLp z = 1

      The uniform superposition |s⟩ = (1/√N) ∑ z |z⟩.

      Equations
      Instances For

        √(2ⁿ) = (√2)ⁿ (the principal root commutes with the nonnegative power).

        The Grover entry point is the Hadamard output: uniformState = H^⊗n |0ⁿ⟩. This ties the uniform superposition (defined here as the normalized all-ones vector) to the R2 Hadamard layer, where Hn_apply_zero gives the same amplitude (√2⁻¹)ⁿ = (√(2ⁿ))⁻¹ on every basis state.

        noncomputable def CSD.Empirical.QM.Grover.oracle {n : } (w : Fin nFin 2) (ψ : QuantumInfo.QReg n) :

        The oracle O_w = I - 2|w⟩⟨w|: a phase flip on the marked item w.

        Equations
        Instances For

          The diffusion operator 2|s⟩⟨s| - I: inversion about the mean.

          Equations
          Instances For
            noncomputable def CSD.Empirical.QM.Grover.groverStep {n : } (w : Fin nFin 2) (ψ : QuantumInfo.QReg n) :

            One Grover step: oracle then diffusion.

            Equations
            Instances For

              The bridge: Grover's operators ARE the BHMT amplification step #

              The oracle is the good-set reflection at G = {w}.

              The diffusion is the reflection about the uniform state.

              One Grover step is one amplification step at φ = uniformState, G = {w}.

              The rotation plane: |w⟩ and the normalized rest #

              1 ≤ 2ⁿ as a real, hence 0 ≤ 2ⁿ - 1.

              theorem CSD.Empirical.QM.Grover.two_le_two_pow {n : } (hn : 1 n) :
              2 2 ^ n

              For n ≥ 1, 2 ≤ 2ⁿ as a real, hence 1 ≤ 2ⁿ - 1.

              theorem CSD.Empirical.QM.Grover.sqrt_sub_one_mul_self {n : } :
              (2 ^ n - 1) * (2 ^ n - 1) = 2 ^ n - 1

              √(N-1) · √(N-1) = N - 1.

              theorem CSD.Empirical.QM.Grover.sqrt_sub_one_ne {n : } (hn : 1 n) :
              (2 ^ n - 1) 0
              noncomputable def CSD.Empirical.QM.Grover.restState {n : } (w : Fin nFin 2) :

              The normalized rest state (√(N-1))⁻¹ (J − |w⟩): the bad unit component of the uniform state against {w}.

              Equations
              Instances For
                theorem CSD.Empirical.QM.Grover.restState_apply {n : } (w z : Fin nFin 2) :
                (restState w).ofLp z = (↑(2 ^ n - 1))⁻¹ * (1 - if z = w then 1 else 0)
                theorem CSD.Empirical.QM.Grover.sum_ite_single {n : } (w : Fin nFin 2) (a b : ) :
                (∑ z : Fin nFin 2, if z = w then a else b) = a + (2 ^ n - 1) * b

                ∑ z, (if z = w then a else b) = a + (N-1)·b.

                theorem CSD.Empirical.QM.Grover.basisState_supp {n : } (w z : Fin nFin 2) :
                z{w}(QuantumInfo.basisState w).ofLp z = 0

                The marked basis state is supported on {w}.

                theorem CSD.Empirical.QM.Grover.restState_supp {n : } (w z : Fin nFin 2) :
                z {w}(restState w).ofLp z = 0

                The rest state vanishes on {w}.

                theorem CSD.Empirical.QM.Grover.inner_rest_self {n : } (hn : 1 n) (w : Fin nFin 2) :

                ⟨rest, rest⟩ = 1 for n ≥ 1.

                ⟨|w⟩, rest⟩ = 0.

                theorem CSD.Empirical.QM.Grover.uniformState_eq_ampState {n : } (hn : 1 n) (w : Fin nFin 2) {θ : } (hsin : Real.sin θ = ((2 ^ n))⁻¹) (hcos : Real.cos θ = (2 ^ n - 1) / (2 ^ n)) :

                The uniform state is the rotation-plane state at the Grover angle: given sin θ = 1/√N, cos θ = √(N-1)/√N, uniformState = ampState |w⟩ rest θ.

                theorem CSD.Empirical.QM.Grover.basisState_weight {n : } (w : Fin nFin 2) :
                z{w}, (QuantumInfo.basisState w).ofLp z ^ 2 = 1

                ∑ z ∈ {w}, ‖(basisState w) z‖² = 1.

                The headline, re-derived from the general theorem #

                theorem CSD.Empirical.QM.Grover.grover_success {n : } (hn : 1 n) (w : Fin nFin 2) (k : ) (θ : ) (hsin : Real.sin θ = ((2 ^ n))⁻¹) (hcos : Real.cos θ = (2 ^ n - 1) / (2 ^ n)) :

                Grover success probability (headline): after k Grover steps from the uniform superposition, the probability of measuring the marked item w is sin²((2k+1)·θ), where θ is the Grover rotation half-angle (sin θ = 1/√N, cos θ = √(N-1)/√N). Re-derived from ampStep_iterate (BHMT) via the operator identity groverStep_eq_ampStep.

                theorem CSD.Empirical.QM.Grover.grover_certain {n : } (hn : 1 n) (w : Fin nFin 2) (k : ) (θ : ) (hsin : Real.sin θ = ((2 ^ n))⁻¹) (hcos : Real.cos θ = (2 ^ n - 1) / (2 ^ n)) (hopt : (2 * k + 1) * θ = Real.pi / 2) :

                Optimal iteration gives certainty: when the accumulated angle hits π/2, i.e. (2k+1)·θ = π/2, the marked item is measured with probability 1. (The general closest-integer bound is amplitude_amplification_succeeds in Mathlib/QuantumInfo/AmplitudeAmplification.lean.)

                The k-marked generalisation — free from the general theorem #

                Each uniform amplitude has squared norm N⁻¹.

                The uniform state is a unit vector.

                The uniform success probability against a good set of size k is k/N.

                theorem CSD.Empirical.QM.Grover.grover_multi_success {n : } (G : Finset (Fin nFin 2)) (hG0 : 0 < G.card) (hG1 : G.card < 2 ^ n) (j : ) :

                The k-marked-items Grover distribution. For a good set G of size strictly between 0 and N on the uniform start, j amplification rounds give success probability exactly sin²((2j+1)·arcsin √(|G|/N)) — the generalisation the single-marked development could not state, obtained as a direct instance of amplitude_amplification.