B4: Reflection Operator I

Time Limit: 3 sec

Memory Limit: 512 MiB

Score: 200

Problem Statement

You are given an integer nn. Implement the operation defined by the following matrix AA on a quantum circuit qc\mathrm{qc} with nn qubits:

A=200IA = 2 \ket{0} \bra{0} - I

where II denotes the 2n×2n2^n \times 2^n identity matrix.

Constraints

  • 2n102 \leq n \leq 10
  • 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(n)
    # Write your code here:
 
    return qc

Sample Input

  • n=2n=2: The matrix AA is calculated as follows.
A=20000I=(1000010000100001)A = 2 \ket{00} \bra{00} - I = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & -1 & 0 & 0\\ 0 & 0 & -1 & 0\\ 0 & 0 & 0 & -1 \end{pmatrix}

Hints

Open
  • An nn-qubit quantum state ψ\ket{\psi} can be represented as a column vector of size 2n2^n, just like a 11-qubit quantum state, and the adjoint ψ\bra{\psi}, inner product ϕψ\braket{\phi|\psi}, and outer product ψϕ\ket{\psi}\bra{\phi} can also be defined in the same way.
ψ=a00...0n+a110...0n+...+a2n11...1n=(a0a2n1)\ket{\psi} = a_0\ket{0...0}_n + a_1\ket{10...0}_n + ... + a_{2^n-1}\ket{1...1}_n = \begin{pmatrix} a_0 \\ \vdots \\ a_{2^n - 1} \end{pmatrix}
  • In the case of nn qubits, the identity matrix II can be transformed as follows.
I=00+11++2n12n1I = \ket{0}\bra{0} + \ket{1}\bra{1} + \cdots + \ket{2^n-1}\bra{2^n-1}

Please sign in to submit your answer.