Problem Statement
You are given an integer n n n .
Let us define [ n ] = { 1 , 2 , ⋯ , n } [n] = \{1, 2, \cdots, n\} [ n ] = { 1 , 2 , ⋯ , n } , and for a subset S S S of [ n ] [n] [ n ] , define a quantum state ∣ S ⟩ \ket{S} ∣ S ⟩ by
∣ S ⟩ = ∣ ∑ s ∈ S 2 s − 1 ⟩ . \begin{equation}
\ket{S} = \ket{\textstyle \sum_{s \in S} 2^{s - 1}} \nonumber.
\end{equation} ∣ S ⟩ = ∣ ∑ s ∈ S 2 s − 1 ⟩ .
Let ∣ S ∣ |S| ∣ S ∣ denotes the number of elements in a set S S S . Implement the following operation on a quantum circuit q c \mathrm{qc} qc with 2 n 2n 2 n qubits.
∑ S ⊆ [ n ] a S ∣ S ⟩ n ∣ 0 ⟩ n → q c 1 3 n ∑ S ⊆ T ⊆ [ n ] a T ∣ S ⟩ n ∣ 0 ⟩ n + 1 3 n ∑ T ⊆ S ⊆ [ n ] ( − 1 ) ( ∣ S ∣ − ∣ T ∣ ) a T ∣ S ⟩ n ∣ 2 n − 1 ⟩ n + ∑ i = 1 2 n − 2 ∑ S ⊆ [ n ] b S , i ∣ S ⟩ n ∣ i ⟩ n \begin{align}
\sum_{S \subseteq [n]} a_S \ket{S}_n \ket{0}_n
\xrightarrow{\mathrm{qc}}
&\sqrt{\frac{1}{3^n}} \sum_{S \subseteq T \subseteq [n]} a_T \ket{S}_n \ket{0}_n \nonumber\\
&+ \sqrt{\frac{1}{3^n}} \sum_{T \subseteq S \subseteq [n]} (-1)^{(|S| - |T|)} a_T \ket{S}_n \ket{2^n - 1}_n\nonumber\\
&+ \sum_{i = 1}^{2^n - 2} \sum_{S \subseteq [n]} b_{S, i} \ket{S}_n \ket{i}_n\nonumber\\
\end{align} S ⊆ [ n ] ∑ a S ∣ S ⟩ n ∣ 0 ⟩ n qc 3 n 1 S ⊆ T ⊆ [ n ] ∑ a T ∣ S ⟩ n ∣ 0 ⟩ n + 3 n 1 T ⊆ S ⊆ [ n ] ∑ ( − 1 ) ( ∣ S ∣ − ∣ T ∣ ) a T ∣ S ⟩ n ∣ 2 n − 1 ⟩ n + i = 1 ∑ 2 n − 2 S ⊆ [ n ] ∑ b S , i ∣ S ⟩ n ∣ i ⟩ n
Here, a S a_S a S represents the probability amplitude of a state ∣ S ⟩ n ∣ 0 ⟩ n \ket{S}_n\ket{0}_n ∣ S ⟩ n ∣ 0 ⟩ n , while b S , i b_{S, i} b S , i represents an arbitrary probability amplitude of a state ∣ S ⟩ n ∣ i ⟩ n \ket{S}_n \ket{i}_n ∣ S ⟩ n ∣ i ⟩ n (any values are permitted).
Constraints
1 ≤ n ≤ 5 1 \leq n \leq 5 1 ≤ n ≤ 5
The circuit depth must not exceed 8 8 8 .
Global phase is ignored in judge.
The submitted code must follow the specified format:
from qiskit import QuantumCircuit
def solve ( n : int ) -> QuantumCircuit:
qc = QuantumCircuit( 2 * n)
# Write your code here:
return qc
Sample Input
n = 1 n = 1 n = 1 :
Implemented circuit q c \mathrm{qc} qc should perform the following transformation.
a 0 ∣ 00 ⟩ + a 1 ∣ 10 ⟩ → q c 1 3 { ( a 0 + a 1 ) ∣ 00 ⟩ + a 1 ∣ 10 ⟩ + a 0 ∣ 01 ⟩ − ( a 0 − a 1 ) ∣ 11 ⟩ } \begin{equation}
a_0 \ket {00} + a_1 \ket {10} \xrightarrow{\mathrm{qc}} \frac{1}{\sqrt{3}} \lbrace (a_0 + a_1) \ket{00} + a_1 \ket{10} + a_0 \ket{01} - (a_0 -a_1) \ket{11} \rbrace \nonumber
\end{equation} a 0 ∣ 00 ⟩ + a 1 ∣ 10 ⟩ qc 3 1 {( a 0 + a 1 ) ∣ 00 ⟩ + a 1 ∣ 10 ⟩ + a 0 ∣ 01 ⟩ − ( a 0 − a 1 ) ∣ 11 ⟩ }
Hints
Open
For subsets A A A and B B B of [ n ] [n] [ n ] , "A ⊆ B A \subseteq B A ⊆ B " can be rephrased as "for any S ∈ [ n ] S \in [n] S ∈ [ n ] , A ∩ { S } ⊆ B ∩ { S } A \cap \lbrace S \rbrace \subseteq B \cap \lbrace S \rbrace A ∩ { S } ⊆ B ∩ { S } ".