B3: Right Action in Another Fourier Basis

Time Limit: 3 sec

Memory Limit: 512 MiB

Score: 600

Writer: PSL

Editorial

You can solve this in almost the same way as the previous problem.

To gain better insight, we decompose E(m,k)E(m, k) based on whether the last n1n - 1 qubits are in the state 0n1\ket{0}_{n - 1} or not, as follows:

E(m,k)=12n+1F(m,k)+12nG(m,k)\begin{equation} E(m, k) = \frac{1}{\sqrt{2^{n + 1}}} F(m, k) + \frac{1}{\sqrt{2^n}} G(m, k) \end{equation}

where

F(m,k)=0a<20b<2(1)am+bkab0n1\begin{equation} F(m, k) = \sum_{0 \leq a < 2} \sum_{0 \leq b < 2} (-1)^{am + bk} \ket{a} \ket{b} \ket{0}_{n-1} \end{equation} G(m,k)=1c<2n1(XmRckI1In1)(00+11)cn1\begin{equation} G(m, k) = \sum_{1 \leq c < 2^{n-1}} \left( X^m R^{ck} \otimes I_1 \otimes I_{n-1} \right)(\ket{0} \ket{0} + \ket{1} \ket{1}) \ket{c}_{n-1} \end{equation}

First, by using the hint, we express F(m,k)F(m', k') in terms of mright,kright,mm_{\text{right}}, k_{\text{right}}, m, and kk:

F(m,k)=0a<20b<2(1)am+bkab0n1=0a<20b<2(1)a(m+mright)+b((1)mkrightk+kright)ab0n1=0a<20b<2(1)a(m+mright)+b(k+kright)ab0n1=0a<20b<2(1)amright+bkright(1)am+bkab0n1\begin{align} F(m', k') &= \sum_{0 \leq a < 2} \sum_{0 \leq b < 2} (-1)^{am' + bk'} \ket{a} \ket{b} \ket{0}_{n-1} \\ &= \sum_{0 \leq a < 2} \sum_{0 \leq b < 2} (-1)^{a (m + m_{\text{right}}) + b ((-1)^m k_{\text{right}}k + k_{\text{right}})} \ket{a} \ket{b} \ket{0}_{n-1} \\ &= \sum_{0 \leq a < 2} \sum_{0 \leq b < 2} (-1)^{a (m + m_{\text{right}}) + b (k + k_{\text{right}})} \ket{a} \ket{b} \ket{0}_{n-1} \\ &= \sum_{0 \leq a < 2} \sum_{0 \leq b < 2} (-1)^{am_{\text{right}} + b k_{\text{right}}} (-1)^{am + bk} \ket{a} \ket{b} \ket{0}_{n-1} \end{align}

Therefore, when the last n1n - 1 qubits are in the 0\ket{0} state, the following two operations are required:

  • If mright1 (mod 2)m_{\text{right}} \equiv 1 \ (\text{mod} \ 2), apply a ZZ gate to a\ket{a}.
  • If kright1 (mod 2)k_{\text{right}} \equiv 1 \ (\text{mod} \ 2), apply a ZZ gate to b\ket{b}.

Similarly, by using the hint, we express G(m,k)G(m', k') in terms of mright,kright,mm_{\text{right}}, k_{\text{right}}, m, and kk:

G(m,k)=1c<2n1(XmRckI1In1)(00+11)cn1=1c<2n1(Xm+mrightRc((1)mrightk+kright)I1In1)(00+11)cn1=1c<2n1(Xm+mrightR(1)mrightck+ckrightI1In1)(00+11)cn1=1c<2n1(XmRckXmrightRckrightI1In1)(00+11)cn1\begin{align} G(m', k') &= \sum_{1 \leq c < 2^{n-1}} \left( X^{m'} R^{ck'} \otimes I_1 \otimes I_{n-1} \right)(\ket{0} \ket{0} + \ket{1} \ket{1}) \ket{c}_{n-1} \\ &= \sum_{1 \leq c < 2^{n-1}} \left( X^{m + m_{\text{right}}} R^{c((-1)^{m_{\text{right}}} k + k_{\text{right}})} \otimes I_1 \otimes I_{n-1} \right)(\ket{0} \ket{0} + \ket{1} \ket{1}) \ket{c}_{n-1} \\ &= \sum_{1 \leq c < 2^{n-1}} \left( X^{m + m_{\text{right}}} R^{(-1)^{m_{\text{right}}} ck + ck_{\text{right}}} \otimes I_1 \otimes I_{n-1} \right)(\ket{0} \ket{0} + \ket{1} \ket{1}) \ket{c}_{n-1} \\ &= \sum_{1 \leq c < 2^{n-1}} \left( X^{m} R^{ck} X^{m_{\text{right}}} R^{ck_{\text{right}}} \otimes I_1 \otimes I_{n-1} \right)(\ket{0} \ket{0} + \ket{1} \ket{1}) \ket{c}_{n-1} \end{align}

In the previous problem, XmleftX^{m_{\text{left}}} RckleftR^{c k_{\text{left}}} was applied on the left, whereas in the current problem, XmrightX^{m_{\text{right}}} RckrightR^{c k_{\text{right}}} is applied on the right. This difference is at the heart of the problem. So, how should we handle the application of XmrightX^{m_{\text{right}}} RckrightR^{c k_{\text{right}}} on the right?

For any matrices UU and VV, the following equation is valid.

(UVI1)(00+11)=(UVT)(00+11)\begin{equation} (UV \otimes I_{1}) (\ket{0}\ket{0} + \ket{1}\ket{1}) = (U \otimes V^{\text{T}}) (\ket{0}\ket{0} + \ket{1}\ket{1}) \end{equation}

Using the fact that X=XTX = X^{\text{T}} and R=RTR = R^{\text{T}}, we obtain the following transformation.

Eq. (11)=1c<2n1(XmRck(XmrightRckright)TIn1)(00+11)cn1=1c<2n1(I1(XmrightRckright)TIn1)(XmRckI1In1)(00+11)cn1=1c<2n1(I1RckrightXmrightIn1)(XmRckI1In1)(00+11)cn1\begin{align} \text{Eq. (11)} &= \sum_{1 \leq c < 2^{n-1}} \left( X^{m} R^{ck} \otimes \left( X^{m_{\text{right}}} R^{ck_{\text{right}}} \right)^\text{T} \otimes I_{n-1} \right)(\ket{0} \ket{0} + \ket{1} \ket{1}) \ket{c}_{n-1} \\ &= \sum_{1 \leq c < 2^{n-1}} \left( I_1 \otimes \left( X^{m_{\text{right}}} R^{ck_{\text{right}}} \right)^\text{T} \otimes I_{n-1} \right) \left( X^{m} R^{ck} \otimes I_1 \otimes I_{n-1} \right)(\ket{0} \ket{0} + \ket{1} \ket{1}) \ket{c}_{n-1} \\ &= \sum_{1 \leq c < 2^{n-1}} \left( I_1 \otimes R^{ck_{\text{right}}} X^{m_{\text{right}}} \otimes I_{n-1} \right) \left( X^{m} R^{ck} \otimes I_1 \otimes I_{n-1} \right)(\ket{0} \ket{0} + \ket{1} \ket{1}) \ket{c}_{n-1} \\ \end{align}

Then, by expanding cc bitwise, the expression RckrightXmrightR^{ck_{\text{right}}} X^{m_{\text{right}}} becomes:

RckrightXmright=Rc0krightRc1(2kright)... Rcn2(2n2kright)Xmright\begin{equation} R^{ck_{\text{right}}} X^{m_{\text{right}}} = R^{c_0 k_{\text{right}}} R^{c_1 (2 k_{\text{right}})} ... \ R^{c_{n-2} (2^{n-2} k_{\text{right}})} X^{m_{\text{right}}} \end{equation}

Therefore, when at least one of the last n1n - 1 qubits is in the 1\ket{1} state, the following two operations are required:

  • If mright1 (mod 2)m_{\text{right}} \equiv 1 \ (\text{mod} \ 2), apply an XX gate to b\ket{b}. (You can implement this using the Problem A3 circuit.)
  • For any j{0,1,,n2}j \in \lbrace0, 1, \dots, n-2\rbrace, if cj=1c_{j} = 1, apply the R2jkleftR^{2^j k_{\text{left}}} to b\ket{b}. (You can implement this using the rotation gate RzRz.)

By performing the above operations in sequence, you can obtain the desired quantum state.

The circuit diagram for n=4,mright=1n = 4, m_{\text{right}} = 1, and kright=2k_{\text{right}} = 2 is as follows.

The circuit depth is O(n)O(n).

Sample Code

Below is a sample program:

import math
 
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import XGate, ZGate, RZGate
 
 
def A3(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
 
    qc.x(m[0])
 
    qc.x(k)
 
    qc.compose(XGate().control(len(k)), [*k, m[0]], inplace=True)
 
    qc.x(k)
 
    return qc
 
 
def solve(n: int, m_right: int, k_right: int) -> QuantumCircuit:
    a, b, c = QuantumRegister(1), QuantumRegister(1), QuantumRegister(n - 1)
    qc = QuantumCircuit(a, b, c)
 
    qc.x(c)
 
    if m_right:
        qc.compose(ZGate().control(len(c)), [*c, a[0]], inplace=True)
    if k_right % 2:
        qc.compose(ZGate().control(len(c)), [*c, b[0]], inplace=True)
 
    qc.x(c)
 
    if m_right:
        qc.compose(A3(n - 1), [b[0], *c], inplace=True)
 
    theta = 2 * math.pi / 2 ** (n - 1)
    for i in range(n - 1):
        angle = theta * k_right * (2 ** i)
        qc.compose(RZGate(angle).control(1),
                   [c[i], b[0]], inplace=True)
 
    return qc