Editorial
This problem involves amplifying the probability amplitudes of specific computational basis states, assuming the use of Grover's algorithm, as in Problem B6 .
The probability P ( r ) P(r) P ( r ) of observing the target computational basis state after performing Grover iterations r r r times is expressed by
P ( r ) = sin 2 ( ( r + 1 2 ) θ ) , \begin{equation}
P(r) = \sin^2\left(\left(r + \frac{1}{2}\right)\theta\right),
\end{equation} P ( r ) = sin 2 ( ( r + 2 1 ) θ ) ,
where θ = 2 arcsin ( 1 / 2 n ) \theta = 2\arcsin(1/\sqrt{2^n}) θ = 2 arcsin ( 1/ 2 n ) .
The positive minimum real number r m i n r_{\mathrm{min}} r min that satisfies P ( r ) = 1 P(r)=1 P ( r ) = 1 can be given by
r m i n = π 2 θ − 1 2 . \begin{equation}
r_{\mathrm{min}}=\frac{\pi}{2\theta}-\frac{1}{2}.
\end{equation} r min = 2 θ π − 2 1 .
In practice, the number of iterations must be an integer, but within the constraints of this problem, it can be confirmed that rounding r m i n r_{\mathrm{min}} r min to an integer satisfies ∣ a L ∣ 2 ≥ 0.9 |a_L|^2\geq 0.9 ∣ a L ∣ 2 ≥ 0.9 .
For n = 10 n=10 n = 10 , r m i n ∼ 25 r_{\mathrm{min}} \sim 25 r min ∼ 25 , and since the circuit for Grover iterations can be implemented with a depth of 8 or less, the total depth of the quantum circuit can be kept below 250.
Proof of Equation (1)
Let us define the quantum state ∣ ψ ′ ⟩ \ket{\psi'} ∣ ψ ′ ⟩ by
∣ ψ ′ ⟩ = 1 2 n − 1 ( ∑ i = 0 2 n − 1 ∣ i ⟩ − ∣ L ⟩ ) . \begin{equation}
\ket{\psi'} = \frac{1}{\sqrt{2^n-1}} \left(\sum_{i=0}^{2^n-1}\ket{i} - \ket{L}\right).
\end{equation} ∣ ψ ′ ⟩ = 2 n − 1 1 ( i = 0 ∑ 2 n − 1 ∣ i ⟩ − ∣ L ⟩ ) .
The state ∣ ψ ⟩ \ket{\psi} ∣ ψ ⟩ can be expressed using ∣ L ⟩ \ket{L} ∣ L ⟩ and ∣ ψ ′ ⟩ \ket{\psi'} ∣ ψ ′ ⟩ as follows:
∣ ψ ⟩ = 1 2 n ∣ L ⟩ + 2 n − 1 2 n ∣ ψ ′ ⟩ \begin{equation}
\ket{\psi} = \frac{1}{\sqrt{2^n}} \ket{L} + \frac{\sqrt{2^n-1}}{\sqrt{2^n}} \ket{\psi'}
\end{equation} ∣ ψ ⟩ = 2 n 1 ∣ L ⟩ + 2 n 2 n − 1 ∣ ψ ′ ⟩
Next, considering θ \theta θ that satisfies
sin θ 2 = 1 2 n , \begin{equation}
\sin \frac{\theta}{2} = \frac{1}{\sqrt{2^n}},
\end{equation} sin 2 θ = 2 n 1 ,
we can rewrite ∣ ψ ⟩ \ket{\psi} ∣ ψ ⟩ as follows:
∣ ψ ⟩ = sin θ 2 ∣ L ⟩ + cos θ 2 ∣ ψ ′ ⟩ \begin{equation}
\ket{\psi}=\sin\frac{\theta}{2}\ket{L}+\cos\frac{\theta}{2}\ket{\psi'}
\end{equation} ∣ ψ ⟩ = sin 2 θ ∣ L ⟩ + cos 2 θ ∣ ψ ′ ⟩
Letting r r r be a non-negative integer, we compute the quantum state after performing Grover iterations on the following state:
sin ( ( r + 1 2 ) θ ) ∣ L ⟩ + cos ( ( r + 1 2 ) θ ) ∣ ψ ′ ⟩ \begin{equation}
\sin\left(\left(r+\frac{1}{2}\right)\theta\right)\ket{L}+\cos\left(\left(r+\frac{1}{2}\right)\theta\right)\ket{\psi'}
\end{equation} sin ( ( r + 2 1 ) θ ) ∣ L ⟩ + cos ( ( r + 2 1 ) θ ) ∣ ψ ′ ⟩
First, the inner products of ∣ ψ ⟩ \ket{\psi} ∣ ψ ⟩ , ∣ ψ ′ ⟩ \ket{\psi'} ∣ ψ ′ ⟩ , and ∣ L ⟩ \ket{L} ∣ L ⟩ yield:
⟨ ψ ∣ L ⟩ = ⟨ L ∣ ψ ⟩ = 1 / 2 n , ⟨ ψ ′ ∣ ψ ⟩ = ⟨ ψ ∣ ψ ′ ⟩ = 2 n − 1 / 2 n , ⟨ ψ ′ ∣ L ⟩ = ⟨ L ∣ ψ ′ ⟩ = 0 \braket{\psi|L}=\braket{L|\psi}=1/\sqrt{2^n},\ \braket{\psi'|\psi}=\braket{\psi|\psi'}=\sqrt{2^n-1}/\sqrt{2^n},\ \braket{\psi'|L}=\braket{L|\psi'}=0 ⟨ ψ ∣ L ⟩ = ⟨ L ∣ ψ ⟩ = 1/ 2 n , ⟨ ψ ′ ∣ ψ ⟩ = ⟨ ψ ∣ ψ ′ ⟩ = 2 n − 1 / 2 n , ⟨ ψ ′ ∣ L ⟩ = ⟨ L ∣ ψ ′ ⟩ = 0
Considering the oracle O O O that flips the sign of the computational basis state ∣ L ⟩ \ket{L} ∣ L ⟩ , it can be expressed as O = I − 2 ∣ L ⟩ ⟨ L ∣ O = I - 2\ket{L}\bra{L} O = I − 2 ∣ L ⟩ ⟨ L ∣ .
When we apply the oracle O O O to the quantum state in equation (7), we obtain:
O ( sin ( r + 1 2 θ ) ∣ L ⟩ + cos ( r + 1 2 θ ) ∣ ψ ′ ⟩ ) = ( I − 2 ∣ L ⟩ ⟨ L ∣ ) ( sin ( r + 1 2 θ ) ∣ L ⟩ + cos ( r + 1 2 θ ) ∣ ψ ′ ⟩ ) = sin ( r + 1 2 θ ) ∣ L ⟩ + cos ( r + 1 2 θ ) ∣ ψ ′ ⟩ − 2 sin ( r + 1 2 θ ) ∣ L ⟩ ⟨ L ∣ L ⟩ − 2 cos ( r + 1 2 θ ) ∣ L ⟩ ⟨ L ∣ ψ ′ ⟩ = sin ( r + 1 2 θ ) ∣ L ⟩ + cos ( r + 1 2 θ ) ∣ ψ ′ ⟩ − 2 sin ( r + 1 2 θ ) ∣ L ⟩ = − sin ( r + 1 2 θ ) ∣ L ⟩ + cos ( r + 1 2 θ ) ∣ ψ ′ ⟩ \begin{align}
&O \left(\sin\left(r_{+ \frac{1}{2}} \theta\right) \ket{L} + \cos\left(r_{+ \frac{1}{2}} \theta\right) \ket{\psi'}\right) \nonumber \\
&= (I - 2\ket{L}\bra{L}) \left(\sin\left(r_{+ \frac{1}{2}} \theta\right) \ket{L} + \cos\left(r_{+ \frac{1}{2}} \theta\right) \ket{\psi'}\right) \\
&= \sin \left(r_{+ \frac{1}{2}} \theta\right) \ket{L} + \cos\left(r_{+ \frac{1}{2}} \theta\right) \ket{\psi'} - 2\sin\left(r_{+ \frac{1}{2}} \theta\right) \ket{L} \braket{L|L} - 2\cos\left(r_{+ \frac{1}{2}} \theta\right) \ket{L} \braket{L|\psi'} \\
&= \sin \left(r_{+ \frac{1}{2}} \theta\right) \ket{L} + \cos\left(r_{+ \frac{1}{2}} \theta\right) \ket{\psi'} - 2\sin\left(r_{+ \frac{1}{2}} \theta\right) \ket{L} \\
&= - \sin\left(r_{+ \frac{1}{2}} \theta\right) \ket{L} + \cos\left(r_{+ \frac{1}{2}} \theta\right)\ket{\psi'}
\end{align} O ( sin ( r + 2 1 θ ) ∣ L ⟩ + cos ( r + 2 1 θ ) ∣ ψ ′ ⟩ ) = ( I − 2 ∣ L ⟩ ⟨ L ∣ ) ( sin ( r + 2 1 θ ) ∣ L ⟩ + cos ( r + 2 1 θ ) ∣ ψ ′ ⟩ ) = sin ( r + 2 1 θ ) ∣ L ⟩ + cos ( r + 2 1 θ ) ∣ ψ ′ ⟩ − 2 sin ( r + 2 1 θ ) ∣ L ⟩ ⟨ L ∣ L ⟩ − 2 cos ( r + 2 1 θ ) ∣ L ⟩ ⟨ L ∣ ψ ′ ⟩ = sin ( r + 2 1 θ ) ∣ L ⟩ + cos ( r + 2 1 θ ) ∣ ψ ′ ⟩ − 2 sin ( r + 2 1 θ ) ∣ L ⟩ = − sin ( r + 2 1 θ ) ∣ L ⟩ + cos ( r + 2 1 θ ) ∣ ψ ′ ⟩
where r + 1 2 r_{+ \frac{1}{2}} r + 2 1 denotes r + 1 / 2 r + 1 / 2 r + 1/2 .
Next, applying the operation represented by the operator 2 ∣ ψ ⟩ ⟨ ψ ∣ − I 2\ket{\psi}\bra{\psi} - I 2 ∣ ψ ⟩ ⟨ ψ ∣ − I gives us:
( 2 ∣ ψ ⟩ ⟨ ψ ∣ − I ) ( − sin ( r + 1 2 θ ) ∣ L ⟩ + cos ( r + 1 2 θ ) ∣ ψ ′ ⟩ ) = − 2 sin ( r + 1 2 θ ) ∣ ψ ⟩ ⟨ ψ ∣ L ⟩ + 2 cos ( r + 1 2 θ ) ∣ ψ ⟩ ⟨ ψ ∣ ψ ′ ⟩ + sin ( r + 1 2 θ ) ∣ L ⟩ − cos ( r + 1 2 θ ) ∣ ψ ′ ⟩ = − 2 2 n sin ( r + 1 2 θ ) ∣ ψ ⟩ + 2 2 n − 1 2 n cos ( r + 1 2 θ ) ∣ ψ ⟩ + sin ( r + 1 2 θ ) ∣ L ⟩ − cos ( r + 1 2 θ ) ∣ ψ ′ ⟩ = − 2 sin θ 2 sin ( r + 1 2 θ ) ∣ ψ ⟩ + 2 cos θ 2 cos ( r + 1 2 θ ) ∣ ψ ⟩ + sin ( r + 1 2 θ ) ∣ L ⟩ − cos ( r + 1 2 θ ) ∣ ψ ′ ⟩ = − 2 sin 2 θ 2 sin ( r + 1 2 θ ) ∣ L ⟩ − 2 sin θ 2 cos θ 2 sin ( r + 1 2 θ ) ∣ ψ ′ ⟩ + 2 sin θ 2 cos θ 2 cos ( r + 1 2 θ ) ∣ L ⟩ + 2 cos 2 θ 2 cos ( r + 1 2 θ ) ∣ ψ ′ ⟩ + sin ( r + 1 2 θ ) ∣ L ⟩ − cos ( r + 1 2 θ ) ∣ ψ ′ ⟩ = ( ( 1 − 2 sin 2 θ 2 ) sin ( r + 1 2 θ ) + 2 sin θ 2 cos θ 2 cos ( r + 1 2 θ ) ) ∣ L ⟩ + ( ( 2 cos 2 θ 2 − 1 ) cos ( r + 1 2 θ ) − 2 sin θ 2 cos θ 2 sin ( r + 1 2 θ ) ) ∣ ψ ′ ⟩ = ( sin ( r + 1 2 θ ) cos θ + cos ( r + 1 2 θ ) sin θ ) ∣ L ⟩ + ( cos ( r + 1 2 θ ) cos θ − sin ( r + 1 2 θ ) sin θ ) ∣ ψ ′ ⟩ = sin ( ( r + 1 2 + 1 ) θ ) ∣ L ⟩ + cos ( ( r + 1 2 + 1 ) θ ) ∣ ψ ′ ⟩ \begin{align}
& (2 \ket{\psi}\bra{\psi} - I) \left(- \sin \left(r_{+ \frac{1}{2}} \theta\right) \ket{L} + \cos \left(r_{+ \frac{1}{2}} \theta\right) \ket{\psi'} \right) \nonumber \\
&= -2 \sin \left(r_{+ \frac{1}{2}} \theta\right) \ket{\psi} \braket{\psi|L} + 2\cos \left(r_{+ \frac{1}{2}} \theta\right) \ket{\psi} \braket{\psi|\psi'} + \sin \left(r_{+ \frac{1}{2}} \theta\right) \ket{L} - \cos (r_{+ \frac{1}{2}} \theta )\ket{\psi'} \\
&= - \frac{2}{\sqrt{2^n}} \sin \left(r_{+ \frac{1}{2}} \theta\right) \ket{\psi} + \frac{2\sqrt{2^n-1}} {\sqrt{2^n}} \cos \left(r_{+ \frac{1}{2}} \theta\right) \ket{\psi} + \sin \left(r_{+ \frac{1}{2}} \theta\right) \ket{L} - \cos\left(r_{+ \frac{1}{2}} \theta\right) \ket{\psi'} \\
&= - 2 \sin \frac{\theta}{2} \sin \left(r_{+ \frac{1}{2}} \theta\right) \ket{\psi} + 2 \cos\frac{\theta}{2} \cos\left(r_{+ \frac{1}{2}} \theta\right) \ket{\psi} + \sin\left(r_{+ \frac{1}{2}} \theta\right) \ket{L} - \cos\left(r_{+ \frac{1}{2}} \theta\right)\ket{\psi'} \\
&= - 2 \sin^2 \frac{\theta}{2} \sin \left(r_{+ \frac{1}{2}} \theta\right) \ket{L} - 2\sin \frac{\theta}{2} \cos \frac{\theta}{2} \sin\left(r_{+ \frac{1}{2}} \theta\right) \ket{\psi'} \\
& \qquad \qquad + 2\sin\frac{\theta}{2} \cos \frac{\theta}{2} \cos\left(r_{+ \frac{1}{2}} \theta\right) \ket{L} + 2\cos^2 \frac{\theta}{2} \cos\left(r_{+ \frac{1}{2}} \theta\right) \ket{\psi'} + \sin\left(r_{+ \frac{1}{2}} \theta\right) \ket{L} - \cos\left(r_{+ \frac{1}{2}} \theta\right) \ket{\psi'} \nonumber \\
&= \left(\left(1 - 2 \sin^2 \frac{\theta}{2}\right) \sin\left(r_{+ \frac{1}{2}} \theta\right) + 2 \sin \frac{\theta}{2} \cos \frac{\theta}{2} \cos\left(r_{+ \frac{1}{2}} \theta\right)\right) \ket{L} \\
& \qquad \qquad + \left(\left(2 \cos^2\ \frac{\theta}{2} - 1\right) \cos\left(r_{+ \frac{1}{2}} \theta\right) - 2 \sin \frac{\theta}{2} \cos \frac{\theta}{2} \sin\left(r_{+ \frac{1}{2}} \theta\right)\right) \ket{\psi'} \nonumber \\
&= \left(\sin\left(r_{+ \frac{1}{2}} \theta\right) \cos \theta + \cos\left(r_{+ \frac{1}{2}} \theta\right) \sin \theta\right) \ket{L} + \left(\cos\left(r_{+ \frac{1}{2}} \theta\right) \cos \theta - \sin\left(r_{+ \frac{1}{2}} \theta\right) \sin \theta\right) \ket{\psi'} \\
&= \sin\left(\left(r_{+ \frac{1}{2}} + 1\right) \theta\right) \ket{L} + \cos \left(\left(r_{+ \frac{1}{2}} + 1\right) \theta\right) \ket{\psi'}
\end{align} ( 2 ∣ ψ ⟩ ⟨ ψ ∣ − I ) ( − sin ( r + 2 1 θ ) ∣ L ⟩ + cos ( r + 2 1 θ ) ∣ ψ ′ ⟩ ) = − 2 sin ( r + 2 1 θ ) ∣ ψ ⟩ ⟨ ψ ∣ L ⟩ + 2 cos ( r + 2 1 θ ) ∣ ψ ⟩ ⟨ ψ ∣ ψ ′ ⟩ + sin ( r + 2 1 θ ) ∣ L ⟩ − cos ( r + 2 1 θ ) ∣ ψ ′ ⟩ = − 2 n 2 sin ( r + 2 1 θ ) ∣ ψ ⟩ + 2 n 2 2 n − 1 cos ( r + 2 1 θ ) ∣ ψ ⟩ + sin ( r + 2 1 θ ) ∣ L ⟩ − cos ( r + 2 1 θ ) ∣ ψ ′ ⟩ = − 2 sin 2 θ sin ( r + 2 1 θ ) ∣ ψ ⟩ + 2 cos 2 θ cos ( r + 2 1 θ ) ∣ ψ ⟩ + sin ( r + 2 1 θ ) ∣ L ⟩ − cos ( r + 2 1 θ ) ∣ ψ ′ ⟩ = − 2 sin 2 2 θ sin ( r + 2 1 θ ) ∣ L ⟩ − 2 sin 2 θ cos 2 θ sin ( r + 2 1 θ ) ∣ ψ ′ ⟩ + 2 sin 2 θ cos 2 θ cos ( r + 2 1 θ ) ∣ L ⟩ + 2 cos 2 2 θ cos ( r + 2 1 θ ) ∣ ψ ′ ⟩ + sin ( r + 2 1 θ ) ∣ L ⟩ − cos ( r + 2 1 θ ) ∣ ψ ′ ⟩ = ( ( 1 − 2 sin 2 2 θ ) sin ( r + 2 1 θ ) + 2 sin 2 θ cos 2 θ cos ( r + 2 1 θ ) ) ∣ L ⟩ + ( ( 2 cos 2 2 θ − 1 ) cos ( r + 2 1 θ ) − 2 sin 2 θ cos 2 θ sin ( r + 2 1 θ ) ) ∣ ψ ′ ⟩ = ( sin ( r + 2 1 θ ) cos θ + cos ( r + 2 1 θ ) sin θ ) ∣ L ⟩ + ( cos ( r + 2 1 θ ) cos θ − sin ( r + 2 1 θ ) sin θ ) ∣ ψ ′ ⟩ = sin ( ( r + 2 1 + 1 ) θ ) ∣ L ⟩ + cos ( ( r + 2 1 + 1 ) θ ) ∣ ψ ′ ⟩
Therefore, the quantum state after performing the Grover iteration r r r times on ∣ ψ ⟩ \ket{\psi} ∣ ψ ⟩ from equation ( 6 ) (6) ( 6 ) can be represented by
∣ ψ ⟩ = sin ( ( r + 1 2 ) θ ) ∣ L ⟩ + cos ( ( r + 1 2 ) θ ) ∣ ψ ′ ⟩ . \begin{equation}
\ket{\psi} = \sin\left(\left(r + \frac{1}{2}\right) \theta\right) \ket{L} + \cos \left(\left(r + \frac{1}{2}\right) \theta\right) \ket{\psi'}.
\end{equation} ∣ ψ ⟩ = sin ( ( r + 2 1 ) θ ) ∣ L ⟩ + cos ( ( r + 2 1 ) θ ) ∣ ψ ′ ⟩ .
For the case where n = 2 n = 2 n = 2 , the circuit diagram is shown below.
The Reflect_B4
in the circuit diagram indicates the circuit of problem B4.
The above considerations can be interpreted geometrically as follows.
In the diagram, U ψ = 2 ∣ ψ ⟩ ⟨ ψ ∣ − I U_{\psi} = 2 \ket{\psi}\bra{\psi} - I U ψ = 2 ∣ ψ ⟩ ⟨ ψ ∣ − I .
In the 2-dimensional space spanned by ∣ ψ ′ ⟩ \ket{\psi'} ∣ ψ ′ ⟩ and ∣ L ⟩ \ket{L} ∣ L ⟩ , O O O is a transformation that moves a vector to a vector symmetric to ∣ ψ ′ ⟩ \ket{\psi'} ∣ ψ ′ ⟩ , while U ψ U_{\psi} U ψ is a transformation that moves a vector to a vector symmetric to ∣ ψ ⟩ \ket{\psi} ∣ ψ ⟩
Sample Code
Below is a sample program:
import math
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import ZGate
def compose_oracle ( qc : QuantumCircuit, y : QuantumRegister, o : QuantumCircuit) -> QuantumCircuit:
qc.x(y)
qc.h(y)
qc.compose(o, inplace = True )
qc.h(y)
qc.x(y)
return qc
def reflect ( n : int ) -> QuantumCircuit:
qc = QuantumCircuit(n)
qc.x( range (n))
qc.append(ZGate().control(n - 1 ), range (n))
qc.x( range (n))
return qc
def solve ( n : int , o : QuantumCircuit) -> QuantumCircuit:
x, y = QuantumRegister(n), QuantumRegister( 1 )
qc = QuantumCircuit(x, y)
theta = math.asin( 1 / math.sqrt( 2 ** n)) * 2
rotation_count = int ( round (math.pi / 2 / theta - 1 / 2 ))
qc.h( range (n))
for _ in range (rotation_count):
compose_oracle(qc, y, o)
qc.h( range (n))
qc.compose(reflect(n), inplace = True )
qc.h( range (n))
return qc