B7: Reflection Operator III

Time Limit: 3 sec

Memory Limit: 512 MiB

Score: 300

Writer: Not_Leonian

Editorial

We focus on the fact that applying the operation of probelm B3 to the zero state 0\ket{0} results in the state ψ\ket{\psi}.

When we express the quantum state ψ\ket{\psi} as ψ=U0\ket{\psi}=U\ket{0}, we have:

UU=I\begin{equation} UU^{\dagger} = I \end{equation}

From the properties of the adjoint matrix, we have:

ψ=ψ=(U0)=0U=0U\begin{equation} \bra{\psi}=\ket{\psi}^{\dagger}=(U\ket{0})^{\dagger}=\ket{0}^{\dagger}U^{\dagger}=\bra{0}U^{\dagger} \end{equation}

This allows us to transform 2ψψI2\ket{\psi}\bra{\psi} - I as follows:

2ψψI=2U00UUU=U(200I)U\begin{equation} 2\ket{\psi}\bra{\psi} - I = 2 U \ket{0} \bra{0} U^{\dagger} - UU^{\dagger} = U (2\ket{0}\bra{0} - I) U^{\dagger} \end{equation}

Therefore, this problem can be solved by implementing the inverse circuit of the circuit implemented in B3, followed by implementing the circuit of B4, and then implementing the circuit of B3 again.

For the case where n=3n = 3, the circuit diagram is shown below. In the circuit diagram, Rotate_B3 represents the B3 circuit, Rotate_B3_dg represents the inverse circuit of B3, and Reflect_B4 represents the B4 circuit.

Sample Code

Below is a sample program:

from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate
 
 
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 rotate(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
 
    for i in range(n):
        qc.ry(T[i] * 2, i)
 
    return qc
 
 
def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
 
    qc.compose(rotate(n, T).inverse(), inplace=True)
    qc.compose(reflect(n), inplace=True)
    qc.compose(rotate(n, T), inplace=True)
 
    return qc