Circuit → Matrix:
Matrix → Circuit:
Key rule: right-to-left. In a circuit drawn left-to-right, the first gate applied is on the right in the matrix product. This is the #1 source of exam errors.
$$I = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} \qquad X = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix} \qquad Y = \begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix} \qquad Z = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}$$
$$H = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} \qquad S = \begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix} \qquad T = \begin{pmatrix} 1 & 0 \\ 0 & e^{i\pi/4} \end{pmatrix}$$
$$\text{CNOT} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix} \qquad \text{CZ} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \end{pmatrix}$$
$$\text{SWAP} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}$$
CNOT: control = top qubit (q1), target = bottom qubit (q2). The bottom-right 2×2 block is X. If control and target are swapped, the matrix changes — it's NOT the same.
For two 2×2 matrices \(A\) and \(B\), the tensor product \(A \otimes B\) is a 4×4 matrix with block structure:
$$A \otimes B = \begin{pmatrix} a_{11}B & a_{12}B \\ a_{21}B & a_{22}B \end{pmatrix} = \begin{pmatrix} a_{11}b_{11} & a_{11}b_{12} & a_{12}b_{11} & a_{12}b_{12} \\ a_{11}b_{21} & a_{11}b_{22} & a_{12}b_{21} & a_{12}b_{22} \\ a_{21}b_{11} & a_{21}b_{12} & a_{22}b_{11} & a_{22}b_{12} \\ a_{21}b_{21} & a_{21}b_{22} & a_{22}b_{21} & a_{22}b_{22} \end{pmatrix}$$
Each entry of \(A\) becomes a 2×2 block by multiplying it with the entire matrix \(B\).
Step 1 — Write out the block structure
$$H \otimes I = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 \cdot I & 1 \cdot I \\ 1 \cdot I & (-1) \cdot I \end{pmatrix}$$
Step 2 — Expand each block
$$= \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ 1 & 0 & -1 & 0 \\ 0 & 1 & 0 & -1 \end{pmatrix}$$
Useful identity: \((A \otimes B)(C \otimes D) = (AC) \otimes (BD)\). This is the mixed product property — it lets you multiply tensor products without expanding to 4×4 first.
Circuit: Apply H on qubit 1 and I on qubit 2 (first step), then apply X on qubit 1 and I on qubit 2 (second step). Find the total matrix.
Step 1 — First time step: parallel gates
H on q1, I on q2 → tensor product: \(H \otimes I\).
$$H \otimes I = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ 1 & 0 & -1 & 0 \\ 0 & 1 & 0 & -1 \end{pmatrix}$$
Step 2 — Second time step: parallel gates
X on q1, I on q2 → tensor product: \(X \otimes I\).
$$X \otimes I = \begin{pmatrix} 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \end{pmatrix}$$
Step 3 — Combine (right-to-left)
Second step acts after first, so total matrix = \((X \otimes I)(H \otimes I)\).
Using the mixed product property: \((X \otimes I)(H \otimes I) = (XH) \otimes (I \cdot I) = XH \otimes I\).
$$XH = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}\frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & -1 \\ 1 & 1 \end{pmatrix}$$
$$\text{Total} = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 0 & -1 & 0 \\ 0 & 1 & 0 & -1 \\ 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \end{pmatrix}$$
Circuit: First apply CNOT (control q1, target q2), then apply H on q1 and I on q2. Find the total matrix.
Step 1 — Identify gate matrices
First gate: \(\text{CNOT} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix}\)
Second gate: \(H \otimes I = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ 1 & 0 & -1 & 0 \\ 0 & 1 & 0 & -1 \end{pmatrix}\)
Step 2 — Multiply (right-to-left: second × first)
$$U = (H \otimes I) \cdot \text{CNOT}$$
Column by column:
$$U = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 0 & 0 & 1 \\ 0 & 1 & 1 & 0 \\ 1 & 0 & 0 & -1 \\ 0 & 1 & -1 & 0 \end{pmatrix}$$
Verification
Check: \(U\ket{00} = \frac{1}{\sqrt{2}}(\ket{00}+\ket{10})\). This is correct — CNOT does nothing to \(\ket{00}\), then H on q1 creates a superposition.
Given this 4×4 matrix, identify the circuit:
$$U = \frac{1}{\sqrt{2}}\begin{pmatrix} 0 & 1 & 0 & 1 \\ 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & -1 \\ 1 & 0 & -1 & 0 \end{pmatrix}$$
Step 1 — Check if it's a tensor product
For \(A \otimes B\), the top-left 2×2 block should be \(a_{11}B\) and the top-right should be \(a_{12}B\). Here the top-left block is \(\frac{1}{\sqrt{2}}\bigl(\begin{smallmatrix}0&1\\1&0\end{smallmatrix}\bigr)\) and the top-right is \(\frac{1}{\sqrt{2}}\bigl(\begin{smallmatrix}0&1\\1&0\end{smallmatrix}\bigr)\). Same block, so \(a_{11} = a_{12}\). Bottom-left block is the same as top-left, bottom-right has a sign flip. This gives \(a_{21} = a_{11}\), \(a_{22} = -a_{11}\).
So \(A = \frac{1}{\sqrt{2}}\bigl(\begin{smallmatrix}1&1\\1&-1\end{smallmatrix}\bigr) = H\) and \(B = \bigl(\begin{smallmatrix}0&1\\1&0\end{smallmatrix}\bigr) = X\).
Step 2 — Verify
$$H \otimes X = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 \cdot X & 1 \cdot X \\ 1 \cdot X & (-1) \cdot X \end{pmatrix} = \frac{1}{\sqrt{2}}\begin{pmatrix} 0 & 1 & 0 & 1 \\ 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & -1 \\ 1 & 0 & -1 & 0 \end{pmatrix} \checkmark$$
Answer
The circuit is: H on qubit 1, X on qubit 2 (applied in parallel, single time step).
Circuit: Z on qubit 1, X on qubit 2 (parallel, single time step). What is the 4×4 matrix?
Parallel gates on different qubits → tensor product. Top qubit is left factor.
$$Z \otimes X = \begin{pmatrix} 1 \cdot X & 0 \cdot X \\ 0 \cdot X & (-1) \cdot X \end{pmatrix} = \begin{pmatrix} 0 & 1 & 0 & 0 \\ 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & -1 \\ 0 & 0 & -1 & 0 \end{pmatrix}$$
Circuit: First apply \(H \otimes H\) (Hadamard on both qubits), then apply CNOT (control q1, target q2). What is the total matrix?
First, compute \(H \otimes H\):
$$H \otimes H = \frac{1}{2}\begin{pmatrix} 1 & 1 & 1 & 1 \\ 1 & -1 & 1 & -1 \\ 1 & 1 & -1 & -1 \\ 1 & -1 & -1 & 1 \end{pmatrix}$$
Right-to-left: CNOT acts second, so total = \(\text{CNOT} \cdot (H \otimes H)\).
$$U = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix} \cdot \frac{1}{2}\begin{pmatrix} 1 & 1 & 1 & 1 \\ 1 & -1 & 1 & -1 \\ 1 & 1 & -1 & -1 \\ 1 & -1 & -1 & 1 \end{pmatrix}$$
CNOT leaves the first two rows unchanged and swaps the last two rows:
$$U = \frac{1}{2}\begin{pmatrix} 1 & 1 & 1 & 1 \\ 1 & -1 & 1 & -1 \\ 1 & -1 & -1 & 1 \\ 1 & 1 & -1 & -1 \end{pmatrix}$$
Identify the circuit for this matrix:
$$U = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \end{pmatrix}$$
Check known gates. Compare with CNOT:
$$\text{CNOT}_{12} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix}$$
Not the same — in our matrix, the swap happens in rows 1–2 (middle), not rows 2–3 (bottom).
This is CNOT with control = q2, target = q1 (reversed control). When q2 = 1 (i.e., basis states \(\ket{01}\) and \(\ket{11}\)), the target q1 gets flipped:
\(\ket{01} \to \ket{11}\), \(\ket{11} \to \ket{01}\). Check the matrix: column 2 (index 01) maps to row 4 (index 11), and column 4 (index 11) maps to row 2 (index 01). Correct.
Answer: CNOT with control = q2 (bottom), target = q1 (top).
Circuit: Apply H on qubit 1, I on qubit 2 (first step), then apply CZ (second step). What is the total matrix?
First step: \(H \otimes I = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ 1 & 0 & -1 & 0 \\ 0 & 1 & 0 & -1 \end{pmatrix}\)
Second step: \(\text{CZ} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \end{pmatrix}\)
Total = \(\text{CZ} \cdot (H \otimes I)\). CZ only negates row 4 (the \(\ket{11}\) row):
$$U = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ 1 & 0 & -1 & 0 \\ 0 & -1 & 0 & 1 \end{pmatrix}$$
Identify the circuit for this matrix:
$$U = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ 0 & 1 & 0 & -1 \\ 1 & 0 & -1 & 0 \end{pmatrix}$$
Try to decompose. Check if it's a tensor product: top-left block is \(\frac{1}{\sqrt{2}}\bigl(\begin{smallmatrix}1&0\\0&1\end{smallmatrix}\bigr)\), top-right is \(\frac{1}{\sqrt{2}}\bigl(\begin{smallmatrix}1&0\\0&1\end{smallmatrix}\bigr)\). Both are \(\frac{1}{\sqrt{2}}I\).
Bottom-left: \(\frac{1}{\sqrt{2}}\bigl(\begin{smallmatrix}0&1\\1&0\end{smallmatrix}\bigr)\), bottom-right: \(\frac{1}{\sqrt{2}}\bigl(\begin{smallmatrix}0&-1\\-1&0\end{smallmatrix}\bigr)\). Bottom-right = \(-1 \times\) bottom-left.
So \(A = \frac{1}{\sqrt{2}}\bigl(\begin{smallmatrix}1&1\\0&0\end{smallmatrix}\bigr)\)? No — that's not unitary. The blocks don't factor as a clean tensor product.
Instead, try known decompositions. Notice this maps \(\ket{00} \to \frac{1}{\sqrt{2}}(\ket{00}+\ket{10})\) and \(\ket{10} \to \frac{1}{\sqrt{2}}(\ket{00}-\ket{10})\) — that's H on qubit 1. But \(\ket{01} \to \frac{1}{\sqrt{2}}(\ket{01}+\ket{11})\) while \(\ket{11} \to \frac{1}{\sqrt{2}}(\ket{01}-\ket{11})\) — also H on qubit 1. Rows 3–4 are swapped compared to \(H \otimes I\).
Compare with Example 2: \((H \otimes I) \cdot \text{CNOT}\):
$$\frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 0 & 0 & 1 \\ 0 & 1 & 1 & 0 \\ 1 & 0 & 0 & -1 \\ 0 & 1 & -1 & 0 \end{pmatrix}$$
Not the same. Try \(\text{CNOT} \cdot (H \otimes I)\) (H first, then CNOT):
CNOT swaps the last two rows of \(H \otimes I\):
$$\frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ 0 & 1 & 0 & -1 \\ 1 & 0 & -1 & 0 \end{pmatrix} \checkmark$$
Answer: H on qubit 1 (first step), then CNOT with control = q1, target = q2 (second step).