QuantumCore

Lesson 30 · 90 min · core

Grover's Search & Amplitude Amplification

Loading progress…

Grover's algorithm finds one of MM marked items among N=2nN=2^n with O(N/M)O(\sqrt{N/M}) oracle queries, quadratically fewer than the Θ(N/M)\Theta(N/M) queries of classical search. This lesson derives the phase oracle and the diffuser together with its gate form, proves that one Grover iteration is a rotation by 2θ2\theta in a two-dimensional invariant plane, derives the optimal iteration count k∗=⌊π/(4θ)⌋k^\ast=\lfloor\pi/(4\theta)\rfloor with success probability at least 1−M/N1-M/N, computes the case N=8N=8 exactly (2532\tfrac{25}{32}, 121128\tfrac{121}{128}, 169512\tfrac{169}{512}), proves the Bennett–Bernstein–Brassard–Vazirani lower bound Ω(N)\Omega(\sqrt N) with the hybrid argument, and generalises everything to amplitude amplification with an arbitrary state preparation AA.

Prerequisites: The Deutsch–Jozsa Algorithm

Objectives and key results
  • Write the phase oracle O=I−2∑w∈M∣w⟩⟨w∣O=I-2\sum_{w\in M}\lvert w\rangle\langle w\rvert and prove H⊗nX⊗n(Cn−1Z)X⊗nH⊗n=−(2∣s⟩⟨s∣−I)H^{\otimes n}X^{\otimes n}(C^{n-1}Z)X^{\otimes n}H^{\otimes n}=-(2\lvert s\rangle\langle s\rvert-I).

  • Prove that the Grover iterate G=DOG=DO acts on span{∣α⟩,∣β⟩}\mathrm{span}\{\lvert\alpha\rangle,\lvert\beta\rangle\} as a rotation by 2θ2\theta with sin⁡θ=M/N\sin\theta=\sqrt{M/N}, so the marked amplitude after kk iterations is sin⁡((2k+1)θ)\sin((2k+1)\theta).

  • Derive k∗=⌊π/(4θ)⌋≈π4N/Mk^\ast=\lfloor\pi/(4\theta)\rfloor\approx\tfrac\pi4\sqrt{N/M} and the success bound P≥1−M/NP\ge1-M/N.

  • Compute P1=2532P_1=\tfrac{25}{32}, P2=121128P_2=\tfrac{121}{128} and P3=169512≈0.330078P_3=\tfrac{169}{512}\approx0.330078 for N=8N=8, M=1M=1 by hand.

  • Reproduce the hybrid-argument proof that every quantum search algorithm needs Ω(N)\Omega(\sqrt N) queries.

  • State and prove the amplitude-amplification theorem for Q=−AS0A−1SχQ=-AS_0A^{-1}S_\chi.

definition · Phase oracle and diffuser
O=I−2∑w∈M∣w⟩⟨w∣,D=2∣s⟩⟨s∣−I=H⊗n(2∣0⟩⟨0∣−I)H⊗nO=I-2\sum_{w\in M}\lvert w\rangle\langle w\rvert,\qquad D=2\lvert s\rangle\langle s\rvert-I=H^{\otimes n}\big(2\lvert0\rangle\langle0\rvert-I\big)H^{\otimes n}
identity · Gate form of the diffuser
H⊗nX⊗n (Cn−1Z) X⊗nH⊗n=−DH^{\otimes n}X^{\otimes n}\,(C^{n-1}Z)\,X^{\otimes n}H^{\otimes n}=-D
theorem · Rotation picture
(DO)k∣s⟩=cos⁡((2k+1)θ)∣α⟩+sin⁡((2k+1)θ)∣β⟩,sin⁡θ=M/N(DO)^k\lvert s\rangle=\cos\big((2k+1)\theta\big)\lvert\alpha\rangle+\sin\big((2k+1)\theta\big)\lvert\beta\rangle,\qquad\sin\theta=\sqrt{M/N}
formula · Optimal iteration count
k∗=⌊π4θ⌋≈π4NM,Psucc≥1−MNk^\ast=\Big\lfloor\frac{\pi}{4\theta}\Big\rfloor\approx\frac\pi4\sqrt{\frac NM},\qquad P_{\mathrm{succ}}\ge1-\frac MN
theorem · BBBV lower bound
T queries with Psucc≥12 for all x ⟹ T=Ω(N)T\ \text{queries with}\ P_{\mathrm{succ}}\ge\tfrac12\ \text{for all } x\ \Longrightarrow\ T=\Omega(\sqrt N)
theorem · Amplitude amplification
Q=−AS0A−1Sχ,QkA∣0⟩=cos⁡((2k+1)θa)∣ψ0⟩+sin⁡((2k+1)θa)∣ψ1⟩Q=-AS_0A^{-1}S_\chi,\qquad Q^kA\lvert0\rangle=\cos\big((2k+1)\theta_a\big)\lvert\psi_0\rangle+\sin\big((2k+1)\theta_a\big)\lvert\psi_1\rangle

The phase oracle and the diffuser#

Definition

Phase oracle

Let N=2nN=2^n and let M⊆{0,1}nM\subseteq\{0,1\}^n be the set of marked items, ∣M∣=M\lvert M\rvert=M with 1≤M<N1\le M<N, i.e. f(x)=1f(x)=1 iff x∈Mx\in M. The phase oracle is the diagonal unitary O=∑x(−1)f(x)∣x⟩⟨x∣=I−2∑w∈M∣w⟩⟨w∣.O=\sum_x(-1)^{f(x)}\lvert x\rangle\langle x\rvert=I-2\sum_{w\in M}\lvert w\rangle\langle w\rvert. It is obtained from the bit oracle UfU_f of the Deutsch–Jozsa lesson by phase kickback, Uf∣x⟩∣−⟩=(−1)f(x)∣x⟩∣−⟩U_f\lvert x\rangle\lvert-\rangle=(-1)^{f(x)}\lvert x\rangle\lvert-\rangle. Since OO is diagonal with entries ±1\pm1, O†=OO^\dagger=O and O2=IO^2=I.

Definition

Diffuser (inversion about the mean)

With ∣s⟩=H⊗n∣0n⟩=1N∑x∣x⟩\lvert s\rangle=H^{\otimes n}\lvert0^n\rangle=\tfrac1{\sqrt N}\sum_x\lvert x\rangle, the diffuser is the reflection D=2∣s⟩⟨s∣−ID=2\lvert s\rangle\langle s\rvert-I. Its action on a state ∑xax∣x⟩\sum_xa_x\lvert x\rangle is ∑x(2aˉ−ax)∣x⟩\sum_x(2\bar a-a_x)\lvert x\rangle with the mean aˉ=1N∑xax\bar a=\tfrac1N\sum_xa_x, because 2∣s⟩⟨s∣ψ⟩=2⋅1N∑yay⋅1N∑x∣x⟩=∑x2aˉ∣x⟩2\lvert s\rangle\langle s\vert\psi\rangle=2\cdot\tfrac1{\sqrt N}\sum_ya_y\cdot\tfrac1{\sqrt N}\sum_x\lvert x\rangle=\sum_x2\bar a\lvert x\rangle.

Proposition

Gate form of the diffuser

D=H⊗n(2∣0n⟩⟨0n∣−I)H⊗nD=H^{\otimes n}(2\lvert0^n\rangle\langle0^n\rvert-I)H^{\otimes n} and H⊗nX⊗n(Cn−1Z)X⊗nH⊗n=−DH^{\otimes n}X^{\otimes n}(C^{n-1}Z)X^{\otimes n}H^{\otimes n}=-D, where Cn−1Z=I−2∣1n⟩⟨1n∣C^{n-1}Z=I-2\lvert1^n\rangle\langle1^n\rvert is the nn-qubit controlled-ZZ (CZ\mathrm{CZ} for n=2n=2, CCZ\mathrm{CCZ} for n=3n=3). Hence the gate sequence implements DD up to the unobservable global phase −1-1.

Proof (5 steps)
  1. Step 1:
    H⊗n(2∣0n⟩⟨0n∣−I)H⊗n=2(H⊗n∣0n⟩)(⟨0n∣H⊗n)−H⊗nH⊗nH^{\otimes n}\big(2\lvert0^n\rangle\langle0^n\rvert-I\big)H^{\otimes n}=2\big(H^{\otimes n}\lvert0^n\rangle\big)\big(\langle0^n\rvert H^{\otimes n}\big)-H^{\otimes n}H^{\otimes n}
    Distribute the product over the difference.
  2. Step 2:
    =2∣s⟩⟨s∣−I=D=2\lvert s\rangle\langle s\rvert-I=D
    H⊗n∣0n⟩=∣s⟩H^{\otimes n}\lvert0^n\rangle=\lvert s\rangle, (H⊗n)†=H⊗n(H^{\otimes n})^\dagger=H^{\otimes n} so ⟨0n∣H⊗n=⟨s∣\langle0^n\rvert H^{\otimes n}=\langle s\rvert, and H2=IH^2=I on every qubit.
  3. Step 3:
    X⊗n∣1n⟩=∣0n⟩ ⇒ X⊗n(I−2∣1n⟩⟨1n∣)X⊗n=I−2∣0n⟩⟨0n∣X^{\otimes n}\lvert1^n\rangle=\lvert0^n\rangle\ \Rightarrow\ X^{\otimes n}\big(I-2\lvert1^n\rangle\langle1^n\rvert\big)X^{\otimes n}=I-2\lvert0^n\rangle\langle0^n\rvert
    X⊗nX^{\otimes n} is self-inverse and maps the all-ones string to the all-zeros string, so conjugation moves the projector.
  4. Step 4:
    I−2∣0n⟩⟨0n∣=−(2∣0n⟩⟨0n∣−I)I-2\lvert0^n\rangle\langle0^n\rvert=-\big(2\lvert0^n\rangle\langle0^n\rvert-I\big)
    Factor out −1-1.
  5. Step 5:
    H⊗nX⊗n(Cn−1Z)X⊗nH⊗n=−H⊗n(2∣0n⟩⟨0n∣−I)H⊗n=−DH^{\otimes n}X^{\otimes n}(C^{n-1}Z)X^{\otimes n}H^{\otimes n}=-H^{\otimes n}\big(2\lvert0^n\rangle\langle0^n\rvert-I\big)H^{\otimes n}=-D
    Combine the previous three lines.

∎

Dxy=2N−δxy=14−δxy(N=8)D_{xy}=\frac2N-\delta_{xy}=\frac14-\delta_{xy}\quad(N=8)
Diffuser for n = 3 (entries 2/N − δ_xy)8×8

Unitary verified: U†U=IU^\dagger U = I (max deviation 0.0e+0)

The invariant plane and the rotation by 2θ#

Definition

Marked and unmarked states

Define the orthonormal pair ∣α⟩=1N−M∑x∉M∣x⟩\lvert\alpha\rangle=\tfrac1{\sqrt{N-M}}\sum_{x\notin M}\lvert x\rangle and ∣β⟩=1M∑x∈M∣x⟩\lvert\beta\rangle=\tfrac1{\sqrt M}\sum_{x\in M}\lvert x\rangle. Then ∣s⟩=N−MN∣α⟩+MN∣β⟩=cos⁡θ∣α⟩+sin⁡θ∣β⟩\lvert s\rangle=\sqrt{\tfrac{N-M}N}\lvert\alpha\rangle+\sqrt{\tfrac MN}\lvert\beta\rangle=\cos\theta\lvert\alpha\rangle+\sin\theta\lvert\beta\rangle with θ∈(0,π2)\theta\in(0,\tfrac\pi2) defined by sin⁡θ=M/N\sin\theta=\sqrt{M/N}.

Theorem

One Grover iteration is a rotation by 2θ

On the plane P=span{∣α⟩,∣β⟩}\mathcal P=\mathrm{span}\{\lvert\alpha\rangle,\lvert\beta\rangle\}, OO is the reflection about ∣α⟩\lvert\alpha\rangle and DD is the reflection about ∣s⟩\lvert s\rangle; their product G=DOG=DO is the rotation by 2θ2\theta. Consequently Gk∣s⟩=cos⁡((2k+1)θ)∣α⟩+sin⁡((2k+1)θ)∣β⟩G^k\lvert s\rangle=\cos((2k+1)\theta)\lvert\alpha\rangle+\sin((2k+1)\theta)\lvert\beta\rangle and the probability of measuring a marked item after kk iterations is sin⁡2((2k+1)θ)\sin^2((2k+1)\theta).

Proof (7 steps)
  1. Step 1:
    O∣α⟩=∣α⟩,O∣β⟩=−∣β⟩O\lvert\alpha\rangle=\lvert\alpha\rangle,\qquad O\lvert\beta\rangle=-\lvert\beta\rangle
    ∣α⟩\lvert\alpha\rangle only contains unmarked xx (sign +1+1), ∣β⟩\lvert\beta\rangle only marked xx (sign −1-1). So OO maps P\mathcal P into itself and acts there as 2∣α⟩⟨α∣−IP2\lvert\alpha\rangle\langle\alpha\rvert-I_{\mathcal P}.
  2. Step 2:
    D∣v⟩=2⟨s∣v⟩∣s⟩−∣v⟩∈P∀ ∣v⟩∈PD\lvert v\rangle=2\langle s\vert v\rangle\lvert s\rangle-\lvert v\rangle\in\mathcal P\quad\forall\,\lvert v\rangle\in\mathcal P
    ∣s⟩∈P\lvert s\rangle\in\mathcal P; on P\mathcal P the operator DD is 2∣s⟩⟨s∣−IP2\lvert s\rangle\langle s\rvert-I_{\mathcal P}, the reflection about ∣s⟩\lvert s\rangle.
  3. Step 3:
    Rϕ:=2∣uϕ⟩⟨uϕ∣−I=(cos⁡2ϕsin⁡2ϕsin⁡2ϕ−cos⁡2ϕ),∣uϕ⟩=cos⁡ϕ∣α⟩+sin⁡ϕ∣β⟩R_\phi:=2\lvert u_\phi\rangle\langle u_\phi\rvert-I=\begin{pmatrix}\cos2\phi&\sin2\phi\\\sin2\phi&-\cos2\phi\end{pmatrix},\quad\lvert u_\phi\rangle=\cos\phi\lvert\alpha\rangle+\sin\phi\lvert\beta\rangle
    In the basis (∣α⟩,∣β⟩)(\lvert\alpha\rangle,\lvert\beta\rangle): 2∣uϕ⟩⟨uϕ∣=(2cos⁡2ϕ2sin⁡ϕcos⁡ϕ2sin⁡ϕcos⁡ϕ2sin⁡2ϕ)2\lvert u_\phi\rangle\langle u_\phi\rvert=\begin{pmatrix}2\cos^2\phi&2\sin\phi\cos\phi\\2\sin\phi\cos\phi&2\sin^2\phi\end{pmatrix}, then use the double-angle formulas.
  4. Step 4:
    O=R0,D=RθO=R_0,\qquad D=R_\theta
    ∣α⟩=∣u0⟩\lvert\alpha\rangle=\lvert u_0\rangle and ∣s⟩=∣uθ⟩\lvert s\rangle=\lvert u_\theta\rangle.
  5. Step 5:
    RθR0=(cos⁡2θsin⁡2θsin⁡2θ−cos⁡2θ)(100−1)=(cos⁡2θ−sin⁡2θsin⁡2θcos⁡2θ)R_\theta R_0=\begin{pmatrix}\cos2\theta&\sin2\theta\\\sin2\theta&-\cos2\theta\end{pmatrix}\begin{pmatrix}1&0\\0&-1\end{pmatrix}=\begin{pmatrix}\cos2\theta&-\sin2\theta\\\sin2\theta&\cos2\theta\end{pmatrix}
    Matrix multiplication: the second column is negated. The result is the rotation matrix by angle 2θ2\theta.
  6. Step 6:
    Gk∣uθ⟩=∣uθ+2kθ⟩=cos⁡((2k+1)θ)∣α⟩+sin⁡((2k+1)θ)∣β⟩G^k\lvert u_\theta\rangle=\lvert u_{\theta+2k\theta}\rangle=\cos\big((2k+1)\theta\big)\lvert\alpha\rangle+\sin\big((2k+1)\theta\big)\lvert\beta\rangle
    Rotations compose by adding angles and ∣s⟩=∣uθ⟩\lvert s\rangle=\lvert u_\theta\rangle.
  7. Step 7:
    Pk=∑w∈M∣⟨w∣Gk∣s⟩∣2=sin⁡2((2k+1)θ)∑w∈M1M=sin⁡2((2k+1)θ)P_k=\sum_{w\in M}\lvert\langle w\vert G^k\vert s\rangle\rvert^2=\sin^2\big((2k+1)\theta\big)\sum_{w\in M}\frac1M=\sin^2\big((2k+1)\theta\big)
    Born rule: ⟨w∣α⟩=0\langle w\vert\alpha\rangle=0 and ⟨w∣β⟩=1/M\langle w\vert\beta\rangle=1/\sqrt M for w∈Mw\in M.

∎

The optimal number of iterations#

Theorem

Optimal iteration count and success probability

Let k∗=⌊π/(4θ)⌋k^\ast=\lfloor\pi/(4\theta)\rfloor. Then Pk∗=sin⁡2((2k∗+1)θ)≥1−MNP_{k^\ast}=\sin^2((2k^\ast+1)\theta)\ge1-\tfrac MN, and k∗≤π4N/Mk^\ast\le\tfrac\pi4\sqrt{N/M}.

Proof (5 steps)
  1. Step 1:
    (2k+1)θ=π2  ⟺  k=π4θ−12(2k+1)\theta=\frac\pi2\iff k=\frac{\pi}{4\theta}-\frac12
    The amplitude sin⁡((2k+1)θ)\sin((2k+1)\theta) is 11 exactly when the angle is π/2\pi/2; this real kk is in general not an integer.
  2. Step 2:
    π4θ−1<k∗≤π4θ ⇒ ∣k∗−(π4θ−12)∣≤12\frac\pi{4\theta}-1<k^\ast\le\frac\pi{4\theta}\ \Rightarrow\ \Big\lvert k^\ast-\Big(\frac\pi{4\theta}-\frac12\Big)\Big\rvert\le\frac12
    Definition of the floor function.
  3. Step 3:
    ∣(2k∗+1)θ−π2∣=2θ ∣k∗−(π4θ−12)∣≤θ\Big\lvert(2k^\ast+1)\theta-\frac\pi2\Big\rvert=2\theta\,\Big\lvert k^\ast-\Big(\frac\pi{4\theta}-\frac12\Big)\Big\rvert\le\theta
    Multiply the previous inequality by 2θ2\theta.
  4. Step 4:
    Pk∗=cos⁡2((2k∗+1)θ−π2)≥cos⁡2θ=1−sin⁡2θ=1−MNP_{k^\ast}=\cos^2\Big((2k^\ast+1)\theta-\frac\pi2\Big)\ge\cos^2\theta=1-\sin^2\theta=1-\frac MN
    sin⁡x=cos⁡(x−π/2)\sin x=\cos(x-\pi/2) and cos⁡2\cos^2 is decreasing in ∣y∣\lvert y\rvert on [0,π2][0,\tfrac\pi2], with ∣y∣≤θ<π2\lvert y\rvert\le\theta<\tfrac\pi2.
  5. Step 5:
    θ≥sin⁡θ=MN ⇒ k∗≤π4θ≤π4NM\theta\ge\sin\theta=\sqrt{\frac MN}\ \Rightarrow\ k^\ast\le\frac\pi{4\theta}\le\frac\pi4\sqrt{\frac NM}
    sin⁡θ≤θ\sin\theta\le\theta for θ≥0\theta\ge0. For M≪NM\ll N, θ≈sin⁡θ\theta\approx\sin\theta and the bound is tight: k∗≈π4N/Mk^\ast\approx\tfrac\pi4\sqrt{N/M}.

∎

Worked example: N = 8, M = 1#

Derivation

Closed form via the Chebyshev recursion

  1. Step 1:
    sin⁡θ=18,cos⁡2θ=1−2sin⁡2θ=1−28=34\sin\theta=\frac1{\sqrt8},\qquad\cos2\theta=1-2\sin^2\theta=1-\frac28=\frac34
    M/N=1/8M/N=1/8 and the double-angle formula.
  2. Step 2:
    sin⁡((m+2)θ)=2cos⁡2θ sin⁡(mθ)−sin⁡((m−2)θ)\sin\big((m+2)\theta\big)=2\cos2\theta\,\sin(m\theta)-\sin\big((m-2)\theta\big)
    Sum-to-product: sin⁡(a+b)+sin⁡(a−b)=2sin⁡acos⁡b\sin(a+b)+\sin(a-b)=2\sin a\cos b with a=mθa=m\theta, b=2θb=2\theta.
  3. Step 3:
    sin⁡3θ=3sin⁡θ−4sin⁡3θ=38−488=528\sin3\theta=3\sin\theta-4\sin^3\theta=\frac3{\sqrt8}-\frac4{8\sqrt8}=\frac{5}{2\sqrt8}
    Triple-angle formula (equivalently the recursion with m=1m=1: 2⋅34⋅18−sin⁡(−θ)=328+182\cdot\tfrac34\cdot\tfrac1{\sqrt8}-\sin(-\theta)=\tfrac{3}{2\sqrt8}+\tfrac1{\sqrt8}).
  4. Step 4:
    P1=sin⁡23θ=254⋅8=2532=0.78125P_1=\sin^23\theta=\frac{25}{4\cdot8}=\frac{25}{32}=0.78125
    Square.
  5. Step 5:
    sin⁡5θ=2⋅34⋅528−18=1548−448=1148\sin5\theta=2\cdot\frac34\cdot\frac{5}{2\sqrt8}-\frac1{\sqrt8}=\frac{15}{4\sqrt8}-\frac{4}{4\sqrt8}=\frac{11}{4\sqrt8}
    Recursion with m=3m=3.
  6. Step 6:
    P2=sin⁡25θ=12116⋅8=121128=0.9453125P_2=\sin^25\theta=\frac{121}{16\cdot8}=\frac{121}{128}=0.9453125
    Square; this is the optimum k∗=⌊π/(4θ)⌋=⌊2.17⌋=2k^\ast=\lfloor\pi/(4\theta)\rfloor=\lfloor2.17\rfloor=2 since θ=arcsin⁡(1/8)≈0.3614\theta=\arcsin(1/\sqrt8)\approx0.3614.
  7. Step 7:
    sin⁡7θ=2⋅34⋅1148−528=3388−2088=1388\sin7\theta=2\cdot\frac34\cdot\frac{11}{4\sqrt8}-\frac{5}{2\sqrt8}=\frac{33}{8\sqrt8}-\frac{20}{8\sqrt8}=\frac{13}{8\sqrt8}
    Recursion with m=5m=5.
  8. Step 8:
    P3=sin⁡27θ=16964⋅8=169512≈0.330078P_3=\sin^27\theta=\frac{169}{64\cdot8}=\frac{169}{512}\approx0.330078
    Square: the third iteration overshoots (7θ≈2.53>π/27\theta\approx2.53>\pi/2).
Derivation

The same numbers by inversion about the mean

  1. Step 1:
    a(0)=(18,…,18) →O aw=−18, aˉ=7−188=348a^{(0)}=\Big(\tfrac1{\sqrt8},\dots,\tfrac1{\sqrt8}\Big)\ \xrightarrow{O}\ a_w=-\tfrac1{\sqrt8},\ \bar a=\frac{7-1}{8\sqrt8}=\frac{3}{4\sqrt8}
    The oracle flips the marked sign; seven entries +18+\tfrac1{\sqrt8} and one −18-\tfrac1{\sqrt8}.
  2. Step 2:
    aw(1)=2aˉ−aw=648+448=528,ay(1)=648−448=128a^{(1)}_w=2\bar a-a_w=\frac{6}{4\sqrt8}+\frac{4}{4\sqrt8}=\frac{5}{2\sqrt8},\qquad a^{(1)}_y=\frac{6}{4\sqrt8}-\frac{4}{4\sqrt8}=\frac{1}{2\sqrt8}
    Diffuser a↦2aˉ−aa\mapsto2\bar a-a. Check: 2532+7⋅132=1\tfrac{25}{32}+7\cdot\tfrac1{32}=1.
  3. Step 3:
    →O aw=−528, aˉ=7⋅12−5288=188\xrightarrow{O}\ a_w=-\frac{5}{2\sqrt8},\ \bar a=\frac{7\cdot\frac12-\frac52}{8\sqrt8}=\frac{1}{8\sqrt8}
    Second oracle call.
  4. Step 4:
    aw(2)=288+2088=1148,ay(2)=288−488=−148a^{(2)}_w=\frac{2}{8\sqrt8}+\frac{20}{8\sqrt8}=\frac{11}{4\sqrt8},\qquad a^{(2)}_y=\frac{2}{8\sqrt8}-\frac{4}{8\sqrt8}=-\frac{1}{4\sqrt8}
    So P(w)=121128P(w)=\tfrac{121}{128} and P(y)=1128P(y)=\tfrac1{128} for each of the 77 other yy: 121+7128=1\tfrac{121+7}{128}=1.
  5. Step 5:
    →O aw=−1148, aˉ=−74−11488=−9168\xrightarrow{O}\ a_w=-\frac{11}{4\sqrt8},\ \bar a=\frac{-\frac74-\frac{11}4}{8\sqrt8}=-\frac{9}{16\sqrt8}
    Third oracle call.
  6. Step 6:
    aw(3)=−18168+44168=1388,ay(3)=−18168+4168=−788a^{(3)}_w=-\frac{18}{16\sqrt8}+\frac{44}{16\sqrt8}=\frac{13}{8\sqrt8},\qquad a^{(3)}_y=-\frac{18}{16\sqrt8}+\frac{4}{16\sqrt8}=-\frac{7}{8\sqrt8}
    P(w)=169512P(w)=\tfrac{169}{512}, P(y)=49512P(y)=\tfrac{49}{512}, and 169+7⋅49=512169+7\cdot49=512.

Result

P1=2532,P2=121128,P3=169512≈0.330078\boxed{P_1=\tfrac{25}{32},\quad P_2=\tfrac{121}{128},\quad P_3=\tfrac{169}{512}\approx0.330078}

Circuit · 3 qubits

Quantum circuit on 3 qubitsH on q0; H on q1; H on q2; O_101 on q0, q1, q2; H on q0; H on q1; H on q2; X on q0; X on q1; X on q2; Z on q2 controlled by q0, q1; X on q0; X on q1; X on q2; H on q0; H on q1; H on q2; O_101 on q0, q1, q2; H on q0; H on q1; H on q2; X on q0; X on q1; X on q2; Z on q2 controlled by q0, q1; X on q0; X on q1; X on q2; H on q0; H on q1; H on q2q0q1q2HHHO101HHHXXXXXXHHHO101HHHXXXXXXHHH

Two Grover iterations for N=8N=8 with the oracle for w=101w=101 substituted; the histogram shows P(101)=121128P(101)=\tfrac{121}{128} and 1128\tfrac1{128} for each other outcome.

∣ψ⟩=−0.0884∣000⟩−0.0884∣001⟩−0.0884∣010⟩−0.0884∣011⟩−0.0884∣100⟩+0.9723∣101⟩−0.0884∣110⟩−0.0884∣111⟩\lvert\psi\rangle = -0.0884\lvert 000\rangle - 0.0884\lvert 001\rangle - 0.0884\lvert 010\rangle - 0.0884\lvert 011\rangle - 0.0884\lvert 100\rangle + 0.9723\lvert 101\rangle - 0.0884\lvert 110\rangle - 0.0884\lvert 111\rangle
  • |000⟩0.0078
  • |001⟩0.0078
  • |010⟩0.0078
  • |011⟩0.0078
  • |100⟩0.0078
  • |101⟩0.9453
  • |110⟩0.0078
  • |111⟩0.0078

Quick check

For N=8N=8, M=1M=1, what is the success probability after three Grover iterations? Give a decimal.

tolerance ±0.001

Quick check

For N=4N=4, M=1M=1, how many iterations maximise the success probability and what is it?

Select one answer
TypeScriptrunnable
import { Statevector, matrix } from '@/lib/quantum-simulator';

// Grover search on n = 3 qubits (N = 8, qubit 0 = MSB) with one marked item w = 5 = |101>.
// Oracle O = I - 2|w><w| (diagonal), diffuser gate form H X CCZ X H = -(2|s><s| - I).
const w = 5;
const phaseFlip = (m) => matrix.fromRows(Array.from({ length: 8 }, (_, i) => Array.from({ length: 8 }, (_, j) => (i === j ? (i === m ? -1 : 1) : 0))));
const oracle = phaseFlip(w);
const ccz = phaseFlip(7); // CCZ = I - 2|111><111|
const theta = Math.asin(1 / Math.sqrt(8));
let sv = Statevector.zero(3).applyGate('H', [0]).applyGate('H', [1]).applyGate('H', [2]);
for (let k = 0; k <= 4; k++) {
  const a = sv.amplitudes();
  const pw = a[w].re ** 2 + a[w].im ** 2;
  const formula = Math.sin((2 * k + 1) * theta) ** 2;
  console.log('k = ' + k + '  P(101) = ' + pw.toFixed(7) + '  sin^2((2k+1)theta) = ' + formula.toFixed(7));
  sv = sv.applyMatrix(oracle, [0, 1, 2]);
  for (const q of [0, 1, 2]) sv = sv.applyGate('H', [q]);
  for (const q of [0, 1, 2]) sv = sv.applyGate('X', [q]);
  sv = sv.applyMatrix(ccz, [0, 1, 2]);
  for (const q of [0, 1, 2]) sv = sv.applyGate('X', [q]);
  for (const q of [0, 1, 2]) sv = sv.applyGate('H', [q]);
}

Expected output

k = 0  P(101) = 0.1250000  sin^2((2k+1)theta) = 0.1250000
k = 1  P(101) = 0.7812500  sin^2((2k+1)theta) = 0.7812500
k = 2  P(101) = 0.9453125  sin^2((2k+1)theta) = 0.9453125
k = 3  P(101) = 0.3300781  sin^2((2k+1)theta) = 0.3300781
k = 4  P(101) = 0.0122070  sin^2((2k+1)theta) = 0.0122070

Optimality: the BBBV lower bound#

Model: a quantum query algorithm on H=CN⊗W\mathcal H=\mathbb C^N\otimes\mathcal W (index register and workspace) applies ∣ψTx⟩=UTOxUT−1Ox⋯U1Ox∣ψ0⟩\lvert\psi^x_T\rangle=U_TO_xU_{T-1}O_x\cdots U_1O_x\lvert\psi_0\rangle, where Ox=I−2∣x⟩⟨x∣⊗IWO_x=I-2\lvert x\rangle\langle x\rvert\otimes I_{\mathcal W} marks the single item xx and the UtU_t do not depend on xx. Let ∣ψt⟩=Ut⋯U1∣ψ0⟩\lvert\psi_t\rangle=U_t\cdots U_1\lvert\psi_0\rangle be the run with the identity in place of every oracle call (no marked item).

Theorem

Bennett–Bernstein–Brassard–Vazirani lower bound

If for every x∈{0,…,N−1}x\in\{0,\dots,N-1\} the measurement of the index register of ∣ψTx⟩\lvert\psi^x_T\rangle yields xx with probability at least 12\tfrac12, then T≥cN2NT\ge\tfrac{\sqrt{c_N}}{2}\sqrt N with cN→(2−2−2)2≈0.42c_N\to(\sqrt2-\sqrt{2-\sqrt2})^2\approx0.42, in particular T=Ω(N)T=\Omega(\sqrt N).

Proof (13 steps)
  1. Step 1:
    Dk:=∑x∥ψkx−ψk∥2D_k:=\sum_x\big\lVert\psi^x_k-\psi_k\big\rVert^2
    Hybrid quantity (Nielsen–Chuang §6.6): total squared distance between the run with oracle OxO_x and the oracle-free run after kk steps.
  2. Step 2:
    ψk+1x−ψk+1=Uk+1(Oxψkx−ψk)=Uk+1(Ox(ψkx−ψk)+(Ox−I)ψk)\psi^x_{k+1}-\psi_{k+1}=U_{k+1}\big(O_x\psi^x_k-\psi_k\big)=U_{k+1}\big(O_x(\psi^x_k-\psi_k)+(O_x-I)\psi_k\big)
    Add and subtract OxψkO_x\psi_k.
  3. Step 3:
    ∥ψk+1x−ψk+1∥≤∥ψkx−ψk∥+2∣αk,x∣,∣αk,x∣:=∥(⟨x∣⊗I)ψk∥\big\lVert\psi^x_{k+1}-\psi_{k+1}\big\rVert\le\big\lVert\psi^x_k-\psi_k\big\rVert+2\big\lvert\alpha_{k,x}\big\rvert,\qquad\lvert\alpha_{k,x}\rvert:=\big\lVert(\langle x\rvert\otimes I)\psi_k\big\rVert
    Unitaries preserve norms, triangle inequality, and (Ox−I)ψk=−2(∣x⟩⟨x∣⊗I)ψk(O_x-I)\psi_k=-2(\lvert x\rangle\langle x\rvert\otimes I)\psi_k.
  4. Step 4:
    Dk+1≤∑x(∥ψkx−ψk∥2+4∥ψkx−ψk∥∣αk,x∣+4∣αk,x∣2)D_{k+1}\le\sum_x\Big(\lVert\psi^x_k-\psi_k\rVert^2+4\lVert\psi^x_k-\psi_k\rVert\lvert\alpha_{k,x}\rvert+4\lvert\alpha_{k,x}\rvert^2\Big)
    Square the previous line and sum over xx.
  5. Step 5:
    ∑x∥ψkx−ψk∥∣αk,x∣≤Dk∑x∣αk,x∣2=Dk,∑x∣αk,x∣2=∥ψk∥2=1\sum_x\lVert\psi^x_k-\psi_k\rVert\lvert\alpha_{k,x}\rvert\le\sqrt{D_k}\sqrt{\textstyle\sum_x\lvert\alpha_{k,x}\rvert^2}=\sqrt{D_k},\qquad\textstyle\sum_x\lvert\alpha_{k,x}\rvert^2=\lVert\psi_k\rVert^2=1
    Cauchy–Schwarz; the ∣αk,x∣2\lvert\alpha_{k,x}\rvert^2 are the index-register probabilities of a normalised state.
  6. Step 6:
    Dk+1≤Dk+4Dk+4=(Dk+2)2 ⇒ Dk+1≤Dk+2D_{k+1}\le D_k+4\sqrt{D_k}+4=\big(\sqrt{D_k}+2\big)^2\ \Rightarrow\ \sqrt{D_{k+1}}\le\sqrt{D_k}+2
    Insert into the previous bound and take square roots.
  7. Step 7:
    D0=0 ⇒ DT≤4T2D_0=0\ \Rightarrow\ D_T\le4T^2
    Induction on kk: Dk≤2k\sqrt{D_k}\le2k.
  8. Step 8:
    Ex:=∥ψTx−∣x⟩⊗∣ωx⟩∥2=2−2 Re⟨x,ωx∣ψTx⟩≤2−212E_x:=\big\lVert\psi^x_T-\lvert x\rangle\otimes\lvert\omega_x\rangle\big\rVert^2=2-2\,\mathrm{Re}\langle x,\omega_x\vert\psi^x_T\rangle\le2-2\sqrt{\tfrac12}
    Choose the workspace state ∣ωx⟩\lvert\omega_x\rangle and a global phase so that ⟨x,ωx∣ψTx⟩=∥(⟨x∣⊗I)ψTx∥≥1/2\langle x,\omega_x\vert\psi^x_T\rangle=\lVert(\langle x\rvert\otimes I)\psi^x_T\rVert\ge\sqrt{1/2} (success probability at least 12\tfrac12).
  9. Step 9:
    Fx:=∥ψT−∣x⟩∣ωx⟩∥2,∑xFx≥2N−2NF_x:=\big\lVert\psi_T-\lvert x\rangle\lvert\omega_x\rangle\big\rVert^2,\qquad\sum_xF_x\ge2N-2\sqrt N
    Fx=2−2Re⟨x,ωx∣ψT⟩F_x=2-2\mathrm{Re}\langle x,\omega_x\vert\psi_T\rangle and ∑x∣⟨x,ωx∣ψT⟩∣≤N∑x∥(⟨x∣⊗I)ψT∥2=N\sum_x\lvert\langle x,\omega_x\vert\psi_T\rangle\rvert\le\sqrt N\sqrt{\sum_x\lVert(\langle x\rvert\otimes I)\psi_T\rVert^2}=\sqrt N by Cauchy–Schwarz.
  10. Step 10:
    DT=∑x∥(ψTx−∣x⟩∣ωx⟩)−(ψT−∣x⟩∣ωx⟩)∥2≥∑x(Fx−Ex)2D_T=\sum_x\lVert(\psi^x_T-\lvert x\rangle\lvert\omega_x\rangle)-(\psi_T-\lvert x\rangle\lvert\omega_x\rangle)\rVert^2\ge\sum_x\big(\sqrt{F_x}-\sqrt{E_x}\big)^2
    Reverse triangle inequality ∥a−b∥≥∥b∥−∥a∥\lVert a-b\rVert\ge\lVert b\rVert-\lVert a\rVert.
  11. Step 11:
    ∑x(Fx−Ex)2≥∑xFx−2∑xFx∑xEx+∑xEx\sum_x\big(\sqrt{F_x}-\sqrt{E_x}\big)^2\ge\sum_xF_x-2\sqrt{\textstyle\sum_xF_x}\sqrt{\textstyle\sum_xE_x}+\sum_xE_x
    Expand and apply Cauchy–Schwarz to the cross term ∑xFxEx\sum_x\sqrt{F_xE_x}.
  12. Step 12:
    DT≥(∑xFx−∑xEx)2≥(2N−2N−(2−2)N)2=cNND_T\ge\Big(\sqrt{\textstyle\sum_xF_x}-\sqrt{\textstyle\sum_xE_x}\Big)^2\ge\Big(\sqrt{2N-2\sqrt N}-\sqrt{(2-\sqrt2)N}\Big)^2=c_NN
    ∑xEx≤(2−2)N\sum_xE_x\le(2-\sqrt2)N and ∑xFx≥2N−2N\sum_xF_x\ge2N-2\sqrt N (valid once 2N−2N≥(2−2)N2N-2\sqrt N\ge(2-\sqrt2)N, i.e. N≥2N\ge2); as N→∞N\to\infty, cN→(2−2−2)2≈0.42>0c_N\to(\sqrt2-\sqrt{2-\sqrt2})^2\approx0.42>0.
  13. Step 13:
    4T2≥DT≥cNN ⇒ T≥cN2N=Ω(N)4T^2\ge D_T\ge c_NN\ \Rightarrow\ T\ge\frac{\sqrt{c_N}}{2}\sqrt N=\Omega(\sqrt N)
    Combine the upper and lower bounds on DTD_T. Grover's π4N\tfrac\pi4\sqrt N is therefore optimal up to a constant factor.

∎

Amplitude amplification#

Definition

Amplitude amplification setting

Let AA be any unitary (a quantum algorithm without measurements) and χ:{0,1}n→{0,1}\chi:\{0,1\}^n\to\{0,1\} a "good" predicate. Write A∣0⟩=cos⁡θa∣ψ0⟩+sin⁡θa∣ψ1⟩A\lvert0\rangle=\cos\theta_a\lvert\psi_0\rangle+\sin\theta_a\lvert\psi_1\rangle with ∣ψ1⟩\lvert\psi_1\rangle the normalised projection onto good basis states, ∣ψ0⟩\lvert\psi_0\rangle onto bad ones, so a=sin⁡2θaa=\sin^2\theta_a is the success probability of AA. Define Sχ=I−2ΠgoodS_\chi=I-2\Pi_{\mathrm{good}} and S0=I−2∣0⟩⟨0∣S_0=I-2\lvert0\rangle\langle0\rvert, and the iterate Q=−AS0A−1SχQ=-AS_0A^{-1}S_\chi.

Theorem

Amplitude amplification (Brassard–Høyer–Mosca–Tapp)

QkA∣0⟩=cos⁡((2k+1)θa)∣ψ0⟩+sin⁡((2k+1)θa)∣ψ1⟩Q^kA\lvert0\rangle=\cos((2k+1)\theta_a)\lvert\psi_0\rangle+\sin((2k+1)\theta_a)\lvert\psi_1\rangle. With k=⌊π/(4θa)⌋=O(1/a)k=\lfloor\pi/(4\theta_a)\rfloor=O(1/\sqrt a) applications of AA, A−1A^{-1} and SχS_\chi, a good state is measured with probability at least 1−a1-a; classical repetition of AA needs O(1/a)O(1/a) runs.

Proof (5 steps)
  1. Step 1:
    Sχ∣P=2∣ψ0⟩⟨ψ0∣−IP,P=span{∣ψ0⟩,∣ψ1⟩}S_\chi\big\vert_{\mathcal P}=2\lvert\psi_0\rangle\langle\psi_0\rvert-I_{\mathcal P},\qquad\mathcal P=\mathrm{span}\{\lvert\psi_0\rangle,\lvert\psi_1\rangle\}
    Sχ∣ψ0⟩=∣ψ0⟩S_\chi\lvert\psi_0\rangle=\lvert\psi_0\rangle and Sχ∣ψ1⟩=−∣ψ1⟩S_\chi\lvert\psi_1\rangle=-\lvert\psi_1\rangle, exactly as for OO.
  2. Step 2:
    −AS0A−1=A(2∣0⟩⟨0∣−I)A−1=2 A∣0⟩⟨0∣A†−I=2∣Ψ⟩⟨Ψ∣−I-AS_0A^{-1}=A\big(2\lvert0\rangle\langle0\rvert-I\big)A^{-1}=2\,A\lvert0\rangle\langle0\rvert A^\dagger-I=2\lvert\Psi\rangle\langle\Psi\rvert-I
    A−1=A†A^{-1}=A^\dagger and ∣Ψ⟩:=A∣0⟩\lvert\Psi\rangle:=A\lvert0\rangle; this is the reflection about ∣Ψ⟩∈P\lvert\Psi\rangle\in\mathcal P, which maps P\mathcal P to itself.
  3. Step 3:
    Q∣P=RθaR0=(cos⁡2θa−sin⁡2θasin⁡2θacos⁡2θa)Q\big\vert_{\mathcal P}=R_{\theta_a}R_0=\begin{pmatrix}\cos2\theta_a&-\sin2\theta_a\\\sin2\theta_a&\cos2\theta_a\end{pmatrix}
    Same computation as for Grover with ∣α⟩→∣ψ0⟩\lvert\alpha\rangle\to\lvert\psi_0\rangle, ∣β⟩→∣ψ1⟩\lvert\beta\rangle\to\lvert\psi_1\rangle, θ→θa\theta\to\theta_a.
  4. Step 4:
    QkA∣0⟩=cos⁡((2k+1)θa)∣ψ0⟩+sin⁡((2k+1)θa)∣ψ1⟩Q^kA\lvert0\rangle=\cos\big((2k+1)\theta_a\big)\lvert\psi_0\rangle+\sin\big((2k+1)\theta_a\big)\lvert\psi_1\rangle
    Rotation by 2kθa2k\theta_a of the angle-θa\theta_a vector ∣Ψ⟩\lvert\Psi\rangle.
  5. Step 5:
    A=H⊗n, χ=f ⇒ sin⁡2θa=MN, Sχ=O, Q=−H⊗nS0H⊗nO=DOA=H^{\otimes n},\ \chi=f\ \Rightarrow\ \sin^2\theta_a=\frac MN,\ S_\chi=O,\ Q=-H^{\otimes n}S_0H^{\otimes n}O=DO
    Grover search is the special case A=H⊗nA=H^{\otimes n}, and the success bound follows from the optimal-kk theorem with M/NM/N replaced by aa.

∎

References

  1. L. K. Grover, A fast quantum mechanical algorithm for database search, Proceedings of the 28th ACM Symposium on Theory of Computing, 212–219 (1996).doi:10.1145/237814.237866
  2. C. H. Bennett, E. Bernstein, G. Brassard and U. Vazirani, Strengths and weaknesses of quantum computing, SIAM Journal on Computing 26, 1510–1523 (1997).doi:10.1137/S0097539796300933
  3. G. Brassard, P. Høyer, M. Mosca and A. Tapp, Quantum amplitude amplification and estimation, Contemporary Mathematics 305, 53–74 (2002).doi:10.1090/conm/305/05215
  4. M. A. Nielsen and I. L. Chuang, Quantum Computation and Quantum Information, 10th anniversary ed., Cambridge University Press (2010), §6.1–§6.6.doi:10.1017/CBO9780511976667

Hands-on labs

  • Grover search on three qubits

    1 step · auto-graded

    Build Grover's algorithm for N=8N=8 items and one marked item ww: the uniform superposition ∣s⟩=H⊗3∣000⟩\lvert s\rangle=H^{\otimes3}\lvert000\rangle followed by two iterations of the phase oracle Of=I−2∣w⟩⟨w∣O_f=I-2\lvert w\rangle\langle w\rvert and the diffuser D=2∣s⟩⟨s∣−ID=2\lvert s\rangle\langle s\rvert-I. The grader substitutes three different oracles (w=101w=101, 010010, 111111) into the placeholder and requires the distribution P(w)=sin⁡2(5θ)=121128P(w)=\sin^2(5\theta)=\tfrac{121}{128} with sin⁡θ=18\sin\theta=\tfrac1{\sqrt8}, every other outcome having probability 1128\tfrac1{128}.

    Open lab