B1: Bra-Ket Notated Gate

Time Limit: 3 sec

Memory Limit: 512 MiB

Score: 100

Writer: Not_Leonian

Editorial

For the inner products of the quantum states 0\ket{0} and 1\ket{1}, the following hold:

{00=(10)(10)=110=(01)(10)=001=(10)(01)=011=(01)(01)=1\begin{equation} \begin{cases} \braket{0|0} = \begin{pmatrix}1 & 0\end{pmatrix} \begin{pmatrix}1 \\ 0\end{pmatrix} = 1 \\ \braket{1|0} = \begin{pmatrix}0 & 1\end{pmatrix} \begin{pmatrix}1 \\ 0\end{pmatrix} = 0 \\ \braket{0|1} = \begin{pmatrix}1 & 0\end{pmatrix} \begin{pmatrix}0 \\ 1\end{pmatrix} = 0 \\ \braket{1|1} = \begin{pmatrix}0 & 1\end{pmatrix} \begin{pmatrix}0 \\ 1\end{pmatrix} = 1 \end{cases} \end{equation}

Thus, when we apply an operator A=10+01A = \ket{1} \bra{0} + \ket{0} \bra{1} to the quantum states 0\ket{0} and 1\ket{1}, we get the following results:

{0AA0=100+010=11AA1=101+011=0\begin{equation} \begin{cases} \ket{0} \xrightarrow{A} A \ket{0} = \ket{1} \braket{0|0} + \ket{0} \braket{1|0} = \ket{1} \\ \ket{1} \xrightarrow{A} A \ket{1} = \ket{1} \braket{0|1} + \ket{0} \braket{1|1} = \ket{0} \end{cases} \end{equation}

This operation that flips 0\ket{0} and 1\ket{1} can be realized with the XX gate.

Sample Code

Below is a sample program:

from qiskit import QuantumCircuit
 
 
def solve() -> QuantumCircuit:
    qc = QuantumCircuit(1)
 
    qc.x(0)
 
    return qc