B4: Reflection Operator I

Time Limit: 3 seconds

Memory Limit: 512 MiB

Score: 200 points

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=2∣0⟩⟨0∣−IA = 2 \ket{0} \bra{0} - I

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

Constraints

  • 2≤n≤102 \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=2∣00⟩⟨00∣−I=(10000−10000−10000−1)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.
∣ψ⟩=a0∣0...0⟩n+a1∣10...0⟩n+...+a2n−1∣1...1⟩n=(a0⋮a2n−1)\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=∣0⟩⟨0∣+∣1⟩⟨1∣+⋯+∣2n−1⟩⟨2n−1∣I = \ket{0}\bra{0} + \ket{1}\bra{1} + \cdots + \ket{2^n-1}\bra{2^n-1}

Please sign in to submit your answer.