Editorial
First, we apply an X X X gate to the first qubit of the zero state ∣ 0000...0 ⟩ \ket{0000...0} ∣ 0000...0 ⟩ .
∣ 0000...0 ⟩ → X ( 0 ) ∣ 1000...0 ⟩ \begin{equation}
\ket{0000...0} \xrightarrow{X(0)} \ket{1000...0}
\end{equation} ∣ 0000...0 ⟩ X ( 0 ) ∣ 1000...0 ⟩
Next, we apply a controlled R y R_y R y gate to this quantum state ∣ 1000...0 ⟩ \ket{1000...0} ∣ 1000...0 ⟩ to create a superposition state of ∣ 1000...0 ⟩ \ket{1000...0} ∣ 1000...0 ⟩ and ∣ 1100...0 ⟩ \ket{1100...0} ∣ 1100...0 ⟩ .
Considering that the amplitude of ∣ 1000...0 ⟩ \ket{1000...0} ∣ 1000...0 ⟩ should be 1 / n 1/\sqrt{n} 1/ n in the final state, the rotation angle θ 1 \theta_1 θ 1 can be determined by solving the following simultaneous equations:
{ cos ( θ 1 2 ) = 1 n sin ( θ 1 2 ) = n − 1 n \begin{equation}
\left\{ \,
\begin{aligned}
& \cos\left(\frac{\theta_1}{2}\right) = \frac{1}{\sqrt{n}} \\
& \sin\left(\frac{\theta_1}{2}\right) = \sqrt{\frac{n-1}{n}}
\end{aligned}
\right.
\end{equation} ⎩ ⎨ ⎧ cos ( 2 θ 1 ) = n 1 sin ( 2 θ 1 ) = n n − 1
Solving these equations gives the following solution within the range 0 ≤ θ 1 ≤ 2 π 0 \leq \theta_1 \leq 2\pi 0 ≤ θ 1 ≤ 2 π :
θ 1 = 2 arctan ( n − 1 ) \begin{equation}
\theta_1 = 2 \arctan{(\sqrt{n-1})}
\end{equation} θ 1 = 2 arctan ( n − 1 )
Therefore, we apply a controlled R y R_y R y gate with rotation angle θ 1 \theta_1 θ 1 to the quantum state ∣ 1000...0 ⟩ \ket{1000...0} ∣ 1000...0 ⟩ , using the first qubit as the control qubit and the second qubit as the target qubit:
∣ 1000...0 ⟩ → C R y ( θ 1 , 0 , 1 ) 1 n ∣ 1000...0 ⟩ + n − 1 n ∣ 1100...0 ⟩ \begin{equation}
\ket{1000...0} \xrightarrow{CRy(\theta_1,0,1)} \frac{1}{\sqrt{n}} \ket{1000...0} + \sqrt{\frac{n-1}{n}} \ket{1100...0}
\end{equation} ∣ 1000...0 ⟩ CR y ( θ 1 , 0 , 1 ) n 1 ∣ 1000...0 ⟩ + n n − 1 ∣ 1100...0 ⟩
Then, we apply a controlled X X X gate with the second qubit as the control qubit and the first qubit as the target qubit:
1 n ∣ 1000...0 ⟩ + n − 1 n ∣ 1100...0 ⟩ → C X ( 1 , 0 ) 1 n ∣ 1000...0 ⟩ + n − 1 n ∣ 0100...0 ⟩ \begin{equation}
\frac{1}{\sqrt{n}} \ket{1000...0} + \sqrt{\frac{n-1}{n}} \ket{1100...0} \xrightarrow{CX(1,0)} \frac{1}{\sqrt{n}} \ket{1000...0} + \sqrt{\frac{n-1}{n}} \ket{0100...0}
\end{equation} n 1 ∣ 1000...0 ⟩ + n n − 1 ∣ 1100...0 ⟩ CX ( 1 , 0 ) n 1 ∣ 1000...0 ⟩ + n n − 1 ∣ 0100...0 ⟩
Repeating these operations—applying controlled R y R_y R y and controlled X X X gates sequentially—a total of n n n times allows us to solve this problem.
∣ 0000...0 ⟩ → X ( 0 ) ∣ 1000...0 ⟩ → C R y ( θ 1 , 0 , 1 ) 1 n ∣ 1000...0 ⟩ + n − 1 n ∣ 1100...0 ⟩ → C X ( 1 , 0 ) 1 n ∣ 1000...0 ⟩ + n − 1 n ∣ 0100...0 ⟩ → C R y ( θ 2 , 1 , 2 ) 1 n ( ∣ 1000...0 ⟩ + ∣ 0100...0 ⟩ ) + n − 2 n − 1 ∣ 0110...0 ⟩ → C X ( 2 , 1 ) 1 n ( ∣ 1000...0 ⟩ + ∣ 0100...0 ⟩ ) + n − 2 n − 1 ∣ 0010...0 ⟩ ⋮ → C X ( n , n − 1 ) 1 n ( ∣ 1000...0 ⟩ + ∣ 0100...0 ⟩ + ⋯ + ∣ 0000...1 ⟩ ) \begin{align}
\ket{0000...0} &\xrightarrow{X(0)} \ket{1000...0} \nonumber \\
&\xrightarrow{CRy(\theta_1, 0, 1)} \frac{1}{\sqrt{n}} \ket{1000...0} + \sqrt{\frac{n-1}{n}} \ket{1100...0} \nonumber\\
&\xrightarrow{CX(1, 0)} \frac{1}{\sqrt{n}} \ket{1000...0} + \sqrt{\frac{n-1}{n}} \ket{0100...0} \nonumber\\
&\xrightarrow{CRy(\theta_2, 1, 2)} \frac{1}{\sqrt{n}} (\ket{1000...0} + \ket{0100...0}) + \sqrt{\frac{n-2}{n-1}} \ket{0110...0} \nonumber\\
&\xrightarrow{CX(2, 1)} \frac{1}{\sqrt{n}} (\ket{1000...0} + \ket{0100...0}) + \sqrt{\frac{n-2}{n-1}} \ket{0010...0} \nonumber\\
&\qquad \qquad \qquad \qquad \qquad \qquad \vdots \nonumber\\
&\xrightarrow{CX(n, n-1)} \frac{1}{\sqrt{n}} (\ket{1000...0} + \ket{0100...0} + \cdots + \ket{0000...1})
\end{align} ∣ 0000...0 ⟩ X ( 0 ) ∣ 1000...0 ⟩ CR y ( θ 1 , 0 , 1 ) n 1 ∣ 1000...0 ⟩ + n n − 1 ∣ 1100...0 ⟩ CX ( 1 , 0 ) n 1 ∣ 1000...0 ⟩ + n n − 1 ∣ 0100...0 ⟩ CR y ( θ 2 , 1 , 2 ) n 1 ( ∣ 1000...0 ⟩ + ∣ 0100...0 ⟩ ) + n − 1 n − 2 ∣ 0110...0 ⟩ CX ( 2 , 1 ) n 1 ( ∣ 1000...0 ⟩ + ∣ 0100...0 ⟩ ) + n − 1 n − 2 ∣ 0010...0 ⟩ ⋮ CX ( n , n − 1 ) n 1 ( ∣ 1000...0 ⟩ + ∣ 0100...0 ⟩ + ⋯ + ∣ 0000...1 ⟩ )
Sample Code
Below is a sample program:
import math
from qiskit import QuantumCircuit
def solve ( n : int ) -> QuantumCircuit:
qc = QuantumCircuit(n)
theta = [ 2 * math.atan(math.sqrt(i)) for i in range (n - 1 , 0 , - 1 )]
qc.x( 0 )
for i in range (n - 1 ):
qc.cry(theta[i], i, i + 1 )
qc.cx(i + 1 , i)
return qc