Quantum Searching
Searching

Quantum Searching

Published on November 6, 2017

Imagine a shuffled deck of 52 cards, and you are asked to find the ace of spades. The most natural thing to do is to take the top most card, see if it's the ace of spades. If not, put it aside, take the top most and repeat the process until you find the ace of spades. If you are lucky, the ace of spades is the top most then we're done. If you're not so lucky, the ace of spades is at the bottom and it will take you 52 peeks before you find the card.

If we scatter the cards face down on the floor and randomly pick a card, then on the average, we will need 52/252/2 peeks before we can find the ace of spades.

With quantum computing we can do even better!

For the sake of demonstration, let's say we have 8 cards as shown in the figure below. We want to find the ace of spades.

Here are the steps:

  1. Label each card from 0 to 7 in random order. The positions of the cards will represent the states of cards. The state ∣6⟩\left\vert 6\right\rangle will therefore represent the ace of spades.

  2. Let ∣ϕ⟩\left\vert\phi\right\rangle be the superposition of states:

∣ϕ⟩=12n/2∑k=02n−1∣x⟩=12n/2(∣0⟩+…+∣7⟩)=18[11111111]\displaystyle \left|\phi\right\rangle = \frac{1}{2^{n/2}} \sum_{k=0}^{2^n-1} \left|x\right\rangle = \frac{1}{2^{n/2}} \Big( \left|0\right\rangle + \ldots + \left|7\right\rangle \Big) = \frac{1}{\sqrt{8}} \left[ \begin{array}{c} 1\\ 1\\ 1\\ 1\\ 1\\ 1\\ 1\\ 1 \end{array} \right]
  1. Let ff be a function such that
f(x)={1x corresponds to ace of spades0 otherwisef(x) = \begin{cases} 1 & x \text{ corresponds to ace of spades}\\ 0 & \text{ otherwise} \end{cases}

Define the operator V\mathbf{V}

V=I−2∣a⟩⟨a∣\mathbf{V} = \mathbf{I} - 2\left|a\right\rangle \left\langle a\right|

where a is the unique value where

f(a)=1f(a) = 1

In our example, the value of a is 6. Therefore,

V=[1.000.000.000.000.000.000.000.000.001.000.000.000.000.000.000.000.000.001.000.000.000.000.000.000.000.000.001.000.000.000.000.000.000.000.000.001.000.000.000.000.000.000.000.000.001.000.000.000.000.000.000.000.000.00−1.000.000.000.000.000.000.000.000.001.00]\mathbf{V} = \begin{bmatrix} 1.00 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 \\ 0.00 & 1.00 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 \\ 0.00 & 0.00 & 1.00 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 \\ 0.00 & 0.00 & 0.00 & 1.00 & 0.00 & 0.00 & 0.00 & 0.00 \\ 0.00 & 0.00 & 0.00 & 0.00 & 1.00 & 0.00 & 0.00 & 0.00 \\ 0.00 & 0.00 & 0.00 & 0.00 & 0.00 & 1.00 & 0.00 & 0.00 \\ 0.00 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 & -1.00 & 0.00 \\ 0.00 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 & 1.00 \\ \end{bmatrix}

Observe that the matrix element V6,6=−1\mathbf{V}_{6,6} = -1

  1. Define the operator W:
W=2∣ϕ⟩⟨ϕ∣−I=[−0.750.250.250.250.250.250.250.250.25−0.750.250.250.250.250.250.250.250.25−0.750.250.250.250.250.250.250.250.25−0.750.250.250.250.250.250.250.250.25−0.750.250.250.250.250.250.250.250.25−0.750.250.250.250.250.250.250.250.25−0.750.250.250.250.250.250.250.250.25−0.75]\mathbf{W} = 2\left|\phi\right\rangle \left\langle\phi\right| - \mathbf{I} = \begin{bmatrix} -0.75 & 0.25 & 0.25 & 0.25 & 0.25 & 0.25 & 0.25 & 0.25 \\ 0.25 & -0.75 & 0.25 & 0.25 & 0.25 & 0.25 & 0.25 & 0.25 \\ 0.25 & 0.25 & -0.75 & 0.25 & 0.25 & 0.25 & 0.25 & 0.25 \\ 0.25 & 0.25 & 0.25 & -0.75 & 0.25 & 0.25 & 0.25 & 0.25 \\ 0.25 & 0.25 & 0.25 & 0.25 & -0.75 & 0.25 & 0.25 & 0.25 \\ 0.25 & 0.25 & 0.25 & 0.25 & 0.25 & -0.75 & 0.25 & 0.25 \\ 0.25 & 0.25 & 0.25 & 0.25 & 0.25 & 0.25 & -0.75 & 0.25 \\ 0.25 & 0.25 & 0.25 & 0.25 & 0.25 & 0.25 & 0.25 & -0.75 \\ \end{bmatrix}
  1. Compute the operator WV\mathbf{WV}:
WV=[−0.750.250.250.250.250.25−0.250.250.25−0.750.250.250.250.25−0.250.250.250.25−0.750.250.250.25−0.250.250.250.250.25−0.750.250.25−0.250.250.250.250.250.25−0.750.25−0.250.250.250.250.250.250.25−0.75−0.250.250.250.250.250.250.250.250.750.250.250.250.250.250.250.25−0.25−0.75]\mathbf{WV} = \begin{bmatrix} -0.75 & 0.25 & 0.25 & 0.25 & 0.25 & 0.25 & -0.25 & 0.25 \\ 0.25 & -0.75 & 0.25 & 0.25 & 0.25 & 0.25 & -0.25 & 0.25 \\ 0.25 & 0.25 & -0.75 & 0.25 & 0.25 & 0.25 & -0.25 & 0.25 \\ 0.25 & 0.25 & 0.25 & -0.75 & 0.25 & 0.25 & -0.25 & 0.25 \\ 0.25 & 0.25 & 0.25 & 0.25 & -0.75 & 0.25 & -0.25 & 0.25 \\ 0.25 & 0.25 & 0.25 & 0.25 & 0.25 & -0.75 & -0.25 & 0.25 \\ 0.25 & 0.25 & 0.25 & 0.25 & 0.25 & 0.25 & 0.75 & 0.25 \\ 0.25 & 0.25 & 0.25 & 0.25 & 0.25 & 0.25 & -0.25 & -0.75 \\ \end{bmatrix}
  1. Multiply WV\mathbf{WV} to ∣ϕ⟩\left\vert\phi\right\rangle a number of times, about π/4⋅2n/2=π/4⋅8=2.2≈2\pi/4 \cdot 2^{n/2} = \pi/4 \cdot \sqrt{8} = 2.2 \approx 2:
WV∣ϕ⟩=[0.180.180.180.180.180.180.880.18],(WV)2∣ϕ⟩=[−0.09−0.09−0.09−0.09−0.09−0.090.97−0.09]\mathbf{WV}\left|\phi\right\rangle = \begin{bmatrix} 0.18 \\ 0.18 \\ 0.18 \\ 0.18 \\ 0.18 \\ 0.18 \\ 0.88 \\ 0.18 \\ \end{bmatrix}, \mathbf{(WV)^2}\left|\phi\right\rangle = \begin{bmatrix} -0.09 \\ -0.09 \\ -0.09 \\ -0.09 \\ -0.09 \\ -0.09 \\ 0.97 \\ -0.09 \\ \end{bmatrix}

As you can see, the probability of getting the state ∣6⟩\left\vert 6\right\rangle becomes very close to 1.

Making a measurement of the input register at this point will give us the state ∣6⟩\left\vert 6\right\rangle with a probability very close to 1.

We have just demonstrated the quantum search algorithm!

Why it works

Let ff be a function such that

f(x)={1x the item we are looking for0 otherwisef(x) = \begin{cases} 1 & x \text{ the item we are looking for}\\ 0 & \text{ otherwise} \end{cases}

Define the operator Uf\mathbf{U}_f whose action on an n qubit register and 1 qubit output register is

Uf(∣x⟩⊗∣y⟩)=∣x⟩⊗∣y⊕f(x)⟩\mathbf{U}_f(\left|x\right\rangle \otimes \left|y\right\rangle) = \left|x\right\rangle\otimes\left|y\oplus f(x)\right\rangle

Prepare the n qubit input register and 1 qubit output register in the following state:

∣0⟩…∣0⟩⏟n times⊗∣1⟩\underbrace{\left|0\right\rangle\ldots \left|0\right\rangle}_{\text{n times}} \otimes \left|1\right\rangle

Applying the Hadamard operator on the input and output qubits gives us a superposition of N=2nN=2^n states:

H⊗n⊗H(∣0…0⟩⊗∣1⟩)=H⊗n∣0…0⟩⊗H∣1⟩=12n/2∑x=02n−1∣x⟩⊗12(∣0⟩−∣1⟩)\begin{array}{rl} \displaystyle \mathbf{H}^{\otimes n}\otimes\mathbf{H}(\left|0\ldots 0\right\rangle\otimes \left|1\right\rangle )&= \mathbf{H}^{\otimes n}\left|0\ldots 0\right\rangle\otimes \mathbf{H}\left|1\right\rangle\\ &= \displaystyle \frac{1}{2^{n/2}}\sum_{x=0}^{2^n-1} \left|x\right\rangle \otimes \frac{1}{\sqrt{2}} \left(\left|0\right\rangle - \left|1\right\rangle\right) \end{array}

Next apply the operator Uf\mathbf{U}_f to get

Uf[12n/2∑x=02n−1∣x⟩⊗12(∣0⟩−∣1⟩)]=1212n/2[∑x=02n−1Uf∣x⟩⊗∣0⟩−∑x=02n−1Uf∣x⟩⊗∣1⟩]=1212n/2[∑x=02n−1∣x⟩⊗∣0⊕f(x)⟩⏟first underbrace−∑x=02n−1∣x⟩⊗∣1⊕f(x)⟩⏟second underbrace]\begin{array}{rl} \displaystyle \mathbf{U}_f \left[\frac{1}{2^{n/2}}\sum_{x=0}^{2^n-1} \left|x\right\rangle \otimes \frac{1}{\sqrt{2}} \left(\left|0\right\rangle - \left|1\right\rangle\right)\right] &= \displaystyle \frac{1}{\sqrt{2}} \frac{1}{2^{n/2}}\left[\sum_{x=0}^{2^n-1} \mathbf{U}_f \left|x\right\rangle \otimes \left|0\right\rangle - \sum_{x=0}^{2^n-1} \mathbf{U}_f \left|x\right\rangle \otimes \left|1\right\rangle\right] \\ &= \displaystyle \frac{1}{\sqrt{2}} \frac{1}{2^{n/2}}\left[\underbrace{\sum_{x=0}^{2^n-1} \left|x\right\rangle \otimes \left|0\oplus f(x) \right\rangle }_{\text{first underbrace}} - \underbrace{\sum_{x=0}^{2^n-1} \left|x\right\rangle \otimes \left|1\oplus f(x) \right\rangle}_{\text{second underbrace}}\right] \end{array}

When f(x)=1f(x) = 1 for x=a, the first underbrace will expand to

∑x=02n−1∣x⟩⊗∣0⊕f(x)⟩=∣0⟩⊗∣0⟩+…+∣a⟩⊗∣1⟩⏟+…+∣2n−1⟩⊗∣0⟩\displaystyle \sum_{x=0}^{2^n-1} \left|x\right\rangle \otimes \left|0\oplus f(x) \right\rangle = \left|0\right\rangle\otimes\left|0\right\rangle + \ldots + \underbrace{\left|a\right\rangle\otimes\left|1\right\rangle} + \ldots + \left|2^n-1\right\rangle \otimes \left|0\right\rangle

The second underbrace will expand to

∑x=02n−1∣x⟩⊗∣1⊕f(x)⟩=∣0⟩⊗∣1⟩+…+∣a⟩⊗∣0⟩⏟+…+∣2n−1⟩⊗∣1⟩\displaystyle \sum_{x=0}^{2^n-1} \left|x\right\rangle \otimes \left|1\oplus f(x) \right\rangle = \left|0\right\rangle\otimes\left|1\right\rangle + \ldots + \underbrace{\left|a\right\rangle\otimes\left|0\right\rangle} + \ldots + \left|2^n-1\right\rangle \otimes \left|1\right\rangle\\

The underbraces in the above summations can be swapped so that we get

1212n/2[∑x=02n−1(−1)f(x)∣x⟩⊗∣0⟩−∑x=02n−1(−1)f(x)∣x⟩⊗∣1⟩]\displaystyle \frac{1}{\sqrt{2}} \frac{1}{2^{n/2}} \left[ \sum_{x=0}^{2^n-1} (-1)^{f(x)} \left|x\right\rangle \otimes \left|0\right\rangle - \sum_{x=0}^{2^n-1} (-1)^{f(x)} \left|x\right\rangle \otimes \left|1\right\rangle\right] =12n/2∑x=02n−1(−1)f(x)∣x⟩⊗12(∣0⟩−∣1⟩)=12n/2∑x=02n−1(−1)f(x)∣x⟩⊗H∣1⟩\begin{array}{rl} &= \displaystyle \frac{1}{2^{n/2}} \sum_{x=0}^{2^n-1} (-1)^{f(x)} \left|x\right\rangle \otimes \frac{1}{\sqrt{2}} \left( \left|0\right\rangle - \left|1\right\rangle\right)\\ &= \displaystyle \frac{1}{2^{n/2}} \sum_{x=0}^{2^n-1} (-1)^{f(x)} \left|x\right\rangle \otimes \mathbf{H}\left|1\right\rangle \end{array}

This means that the action of Uf\mathbf{U}_f leaves the output qubit unentangled with the input qubit. We can just ignore this moving forward and focus our attention to the input qubits.

We view the current state of the input qubit as the result of some operator V\mathbf{V} defined by

V∣ϕ⟩=12n/2∑x=02n−1(−1)f(x)∣x⟩\mathbf{V} \left|\phi\right\rangle = \displaystyle \frac{1}{2^{n/2}} \sum_{x=0}^{2^n-1} (-1)^{f(x)} \left|x\right\rangle

where

∣ϕ⟩=12n/2∑x=02n−1∣x⟩\left|\phi\right\rangle = \displaystyle \frac{1}{2^{n/2}} \sum_{x=0}^{2^n-1} \left|x\right\rangle

We can derive the expression of V\mathbf{V} by expanding V∣ϕ⟩\mathbf{V} \left\vert\phi\right\rangle, noting that at x=a, f(x)=1f(x) = 1:

V∣ϕ⟩=12n/2∑x=02n−1(−1)f(x)∣x⟩=12n/2[∣0⟩+…−∣a⟩+…+∣2n−1⟩]=12n/2[∣0⟩+…+∣a⟩+…+∣2n−1⟩−2∣a⟩]=12n/2∑x=02n−1∣x⟩−22n/2∣a⟩=∣ϕ⟩−2⟨a∣ϕ⟩∣a⟩=[I−2∣a⟩⟨a∣]∣ϕ⟩\begin{array}{rl} \mathbf{V} \left|\phi\right\rangle &= \displaystyle \frac{1}{2^{n/2}} \sum_{x=0}^{2^n-1} (-1)^{f(x)} \left|x\right\rangle\\ &= \displaystyle \frac{1}{2^{n/2}} \left[\left|0\right\rangle + \ldots - \left|a\right\rangle +\ldots + \left|2^n-1\right\rangle\right]\\ &= \displaystyle \frac{1}{2^{n/2}} \left[\left|0\right\rangle + \ldots + \left|a\right\rangle +\ldots + \left|2^n-1\right\rangle - 2\left|a\right\rangle\right]\\ &= \displaystyle \frac{1}{2^{n/2}} \sum_{x=0}^{2^n-1} \left|x\right\rangle - \frac{2}{2^{n/2}} \left|a\right\rangle\\ &= \left|\phi\right\rangle - 2\left\langle a|\phi\right\rangle \left|a\right\rangle\\ &= \Big[\mathbf{I} - 2\left|a\right\rangle \left\langle a\right|\Big] \left|\phi\right\rangle\\ \end{array}

which means

V=I−2∣a⟩⟨a∣\mathbf{V} = \mathbf{I} - 2\left|a\right\rangle \left\langle a\right|

The two vectors ∣ϕ⟩\left\vert\phi\right\rangle and ∣a⟩\left\vert a\right\rangle determine a plane P. Let ∣a⊥⟩\left\vert a_{\perp}\right\rangle be the vector in the plane perpendicular to ∣a⟩\left\vert a\right\rangle. We can write ∣ϕ⟩\left\vert \phi\right\rangle as

∣ϕ⟩=ϕ1∣a⊥⟩+ϕ2∣a⟩\left|\phi\right\rangle = \phi_1 \left|a_\perp\right\rangle + \phi_2\left|a\right\rangle

Applying V\mathbf{V} to ∣ϕ⟩\left\vert \phi\right\rangle gives us:

V∣ϕ⟩=(I−2∣a⟩⟨a∣)(ϕ1∣a⊥⟩+ϕ2∣a⟩)=ϕ1∣a⊥⟩+ϕ2∣a⟩−2ϕ2∣a⟩=ϕ1∣a⊥⟩−ϕ2∣a⟩\begin{array}{rl} \mathbf{V}\left|\phi\right\rangle &= \left(\mathbf{I} - 2\left|a\right\rangle \left\langle a\right| \right) \left( \phi_1 \left|a_\perp\right\rangle + \phi_2\left|a\right\rangle \right)\\ &= \phi_1 \left|a_\perp\right\rangle + \phi_2\left|a\right\rangle - 2\phi_2\left|a\right\rangle\\ &= \phi_1 \left|a_\perp\right\rangle - \phi_2\left|a\right\rangle \end{array}

The effect of the operator V\mathbf{V} is therefore to reflect the vector ∣ϕ⟩\left\vert \phi\right\rangle with respect to the vector ∣a⊥⟩\left\vert a_\perp\right\rangle.

Now, we want to reflect this vector V∣ϕ⟩\mathbf{V}\left\vert \phi\right\rangle with respect to ∣ϕ⟩\left\vert \phi\right\rangle. To accomplish this, we define the operator W\mathbf{W} by

W=2∣ϕ⟩⟨ϕ∣−I\mathbf{W} = 2\left|\phi\right\rangle \left\langle\phi\right| - \mathbf{I}

Apply this operator to V∣ϕ⟩\mathbf{V}\left\vert\phi\right\rangle:

WV∣ϕ⟩=[2∣ϕ⟩⟨ϕ∣−I]V∣ϕ⟩=2∣ϕ⟩⟨ϕ∣V∣ϕ⟩−V∣ϕ⟩\begin{array}{rl} \mathbf{WV}\left|\phi\right\rangle &= \Big[ 2\left|\phi\right\rangle \left\langle\phi\right| - \mathbf{I} \Big]\mathbf{V}\left|\phi\right\rangle\\ &= 2\left|\phi\right\rangle \left\langle\phi\right|\mathbf{V}\left|\phi\right\rangle -\mathbf{V}\left|\phi\right\rangle \end{array}

If we express V∣ϕ⟩\mathbf{V}\left\vert \phi\right\rangle as a linear combination of ∣ϕ⟩\left\vert\phi\right\rangle and a vector ∣ϕ⊥⟩\left\vert\phi_\perp\right\rangle in the plane P,

V∣ϕ⟩=α∣ϕ⟩+β∣ϕ⊥⟩\mathbf{V}\left|\phi\right\rangle = \alpha \left|\phi\right\rangle + \beta \left|\phi_\perp\right\rangle

We have,

WV∣ϕ⟩=[2∣ϕ⟩⟨ϕ∣−I]V∣ϕ⟩=2∣ϕ⟩⟨ϕ∣V∣ϕ⟩−V∣ϕ⟩=2α∣ϕ⟩−α∣ϕ⟩−β∣ϕ⊥⟩=α∣ϕ⟩−β∣ϕ⊥⟩\begin{array}{rl} \mathbf{WV}\left|\phi\right\rangle &= \Big[ 2\left|\phi\right\rangle \left\langle\phi\right| - \mathbf{I} \Big]\mathbf{V}\left|\phi\right\rangle\\ &= 2\left|\phi\right\rangle \left\langle\phi\right|\mathbf{V}\left|\phi\right\rangle -\mathbf{V}\left|\phi\right\rangle\\ &= 2\alpha\left|\phi\right\rangle - \alpha \left|\phi\right\rangle - \beta \left|\phi_\perp\right\rangle\\ &= \alpha\left|\phi\right\rangle - \beta \left|\phi_\perp\right\rangle \end{array}

which demonstrates that W\mathbf{W} reflects V∣ϕ⟩\mathbf{V}\left\vert \phi\right\rangle with respect to ∣ϕ⟩\left\vert \phi\right\rangle.

Therefore, the effect of WV\mathbf{WV} on ∣ϕ⟩\left\vert \phi\right\rangle is to rotate it by an angle γ\gamma counter-clockwise.

We can compute this γ\gamma by getting the inner product of WV∣ϕ⟩\mathbf{WV}\left\vert\phi\right\rangle and ∣ϕ⟩\left\vert\phi\right\rangle. First, let's find the expression of WV∣ϕ⟩\mathbf{WV}\left\vert \phi\right\rangle:

WV∣ϕ⟩=W(I−2∣a⟩⟨a∣)∣ϕ⟩=W(∣ϕ⟩−2⟨a∣ϕ⟩⏟∣a⟩)\begin{array}{rl} \mathbf{WV}\left|\phi\right\rangle &= \mathbf{W} \left( \mathbf{I} - 2\left|a\right\rangle \langle a |\right) \left|\phi\right\rangle\\ &= \mathbf{W} \left(\left|\phi\right\rangle - 2 \underbrace{\langle a| \phi \rangle} \left|a\right\rangle \right) \end{array}

The quantity ⟨a∣ϕ⟩\langle a\vert \phi \rangle is

⟨a∣ϕ⟩=⟨a∣(12n/2∑k=02n−1∣x⟩)=12n/2=cos⁡θ\langle a| \phi \rangle = \displaystyle \langle a| \left( \frac{1}{2^{n/2}} \sum_{k=0}^{2^n-1} \left|x\right\rangle \right) = \frac{1}{2^{n/2}} = \cos \theta

where θ\theta is the angle between ∣a⟩\left\vert a\right\rangle and ∣ϕ⟩\left\vert \phi\right\rangle.

The complementary angle, ρ=90−θ\rho = 90-\theta is the angle between ∣ϕ⟩\left\vert\phi\right\rangle and ∣a⊥⟩\left\vert a_\perp\right\rangle. Using a well-known trigonometric identity, we can compute for the angle of ρ\rho:

cos⁡θ=sin⁡ρ=12n/2\cos \theta = \sin \rho = \displaystyle \frac{1}{2^{n/2}}

Since 12n/2\displaystyle \frac{1}{2^{n/2}} is very small if n is large,

sin⁡ρ=12n/2≈ρ\sin \rho = \displaystyle \frac{1}{2^{n/2}} \approx \rho

Continuing,

WV∣ϕ⟩=W(I−2∣a⟩⟨a∣)∣ϕ⟩=W(∣ϕ⟩−2cos⁡ρ∣a⟩)=(2∣ϕ⟩⟨ϕ∣−I)(∣ϕ⟩−2cos⁡ρ∣a⟩)=2∣ϕ⟩−∣ϕ⟩−2cos⁡ρ∣ϕ⟩⟨ϕ∣a⟩+2cos⁡ρ∣a⟩=∣ϕ⟩−4cos⁡2ρ∣ϕ⟩+2cos⁡ρ∣a⟩=(1−4cos⁡2ρ)∣ϕ⟩+2cos⁡ρ∣a⟩\begin{array}{rl} \mathbf{WV}\left|\phi\right\rangle &= \mathbf{W} \left( \mathbf{I} - 2\left|a\right\rangle \langle a |\right) \left|\phi\right\rangle\\ &= \mathbf{W} \left(\left|\phi\right\rangle - 2 \cos\rho \left|a\right\rangle \right)\\ &= (2\left|\phi\right\rangle \langle \phi| - \mathbf{I}) \left(\left|\phi\right\rangle - 2 \cos\rho \left|a\right\rangle \right)\\ &= 2\left|\phi\right\rangle - \left|\phi\right\rangle - 2\cos\rho \left|\phi\right\rangle \langle \phi |a\rangle + 2 \cos\rho \left|a\right\rangle\\ &= \left|\phi\right\rangle - 4\cos^2\rho \left|\phi\right\rangle + 2 \cos\rho \left|a\right\rangle\\ &= (1- 4\cos^2\rho) \left|\phi\right\rangle + 2 \cos\rho \left|a\right\rangle \end{array}

The inner product of WV∣ϕ⟩\mathbf{WV}\left\vert\phi\right\rangle and ∣ϕ⟩\left\vert\phi\right\rangle is given by

⟨ϕ∣WV∣ϕ⟩=⟨ϕ∣[(1−4cos⁡2ρ)∣ϕ⟩+2cos⁡ρ∣a⟩]=(1−4cos⁡2ρ)+2cos⁡2ρ=1−2cos⁡2ρ=cos⁡2ρ\begin{array}{rl} \langle\phi|\mathbf{WV}\left|\phi\right\rangle &= \langle\phi|\left[ (1- 4\cos^2\rho) \left|\phi\right\rangle + 2 \cos\rho \left|a\right\rangle\right]\\ &= (1- 4\cos^2\rho) + 2\cos^2\rho\\ &= 1- 2\cos^2\rho\\ &= \cos 2\rho \end{array}

Therefore, the angle between these two vectors is 2ρ=12n/22\rho = \displaystyle \frac{1}{2^{n/2}}. How many times do we have to apply the operator WV\mathbf{WV} to get to π/2\pi/2?

m⋅2ρ=π2m22n/2=π2m=π⋅2n/24\begin{array}{rl} m\cdot 2\rho &= \displaystyle \frac{\pi}{2}\\ \displaystyle m \frac{2}{2^{n/2}}&= \displaystyle \frac{\pi}{2}\\ m &=\displaystyle \frac{\pi\cdot 2^{n/2}}{4} \end{array}

Therefore, we need to apply the operator WV\mathbf{WV} O(N)O(\sqrt{N}) times to find our value (where N=2nN=2^n).

Image Credit: "Binoculars at Duomo roof /Prismaticos en el tejado del Duomo, Milan" by albertopveiga is marked with CC BY-NC-SA 2.0. To view the terms, visit https://creativecommons.org/licenses/by-nc-sa/2.0/?ref=openverse