Exercises: Chapter 7 — Quantum Circuits: Building Computations from Gates — Universal Gate Sets, Circuit Diagrams, and Circuit Depth

Exercise 7.1 — Circuit Identity Verification

Prove the identity $HXH = Z$ by (a) matrix multiplication and (b) building both circuits in Qiskit and comparing their unitaries. Then prove $HZH = X$ and $HYH = -Y$. Show that $H$ conjugation maps Paulis as $H:\{X, Y, Z\} \to \{Z, -Y, X\}$ — it cyclically permutes $X \to Z \to X$ (with a sign flip on $Y$).

Exercise 7.2 — Depth Optimization

Given the following circuit, find an equivalent circuit with minimal depth:

q_0: ── H ── T ── T ── H ──●──
                              │
q_1: ── X ── H ── X ── H ── X ──

Use circuit identities to simplify. Since $T^2 = S$ and $H^2 = I$, what does the circuit reduce to? Verify your answer with Qiskit.

Exercise 7.3 — Building a Controlled-U

Implement a controlled-$R_y(\pi/4)$ gate using the decomposition from Section 7.11.1. Verify it produces the correct unitary by comparing with RZGate.control(). How many CNOTs does your decomposition use?

Exercise 7.4 — Transpilation Analysis

Create a 5-qubit circuit with 10 random $U_3$ gates and 5 CNOT gates between random qubits. Transpile it for FakeBrisbane() at all four optimization levels. Report the depth, gate count, and number of SWAP gates inserted for each level. Plot the results.

Exercise 7.5 — Reversible Addition

Design a quantum circuit that performs reversible addition of two 2-bit numbers: $|a\rangle|b\rangle|0\rangle \to |a\rangle|b\rangle|a+b\rangle$. Use Toffoli and CNOT gates. Implement it in Qiskit and verify it works for all 16 possible inputs.

Exercise 7.6 — Solovay-Kitaev Approximation

(a) Using the Clifford+T gate set, approximate $R_y(\pi/3)$ to precision $\epsilon = 0.01$ using the Solovay-Kitaev algorithm (or a simpler search). How many $T$ gates are required?

(b) Verify your approximation by computing the fidelity $\left|\langle \psi_{\text{exact}} | \psi_{\text{approx}} \rangle\right|^2$ between the exact and approximate states.

Exercise 7.7 — GHZ State Verification

(a) Create a 5-qubit GHZ state circuit and compute its statevector.

(b) Verify that the state has the correct amplitudes by measuring in the computational basis and checking the probability of $|00000\rangle$ and $|11111\rangle$.

(c) Measure each qubit independently and compute the expectation values $\langle Z_i \rangle$ and two-qubit correlations $\langle Z_i Z_j \rangle$. Verify that $\langle Z_i \rangle = 0$ and $\langle Z_i Z_j \rangle = 1$ for all $i, j$.

Exercise 7.8 — SWAP Decomposition and Cost

(a) Prove that the 3-CNOT decomposition of SWAP is correct by computing the product $\text{CNOT}_{0\to1} \cdot \text{CNOT}_{1\to0} \cdot \text{CNOT}_{0\to1}$ and showing it equals the SWAP matrix.

(b) On a device where two-qubit gates have 10× the error rate of single-qubit gates, what is the total error of a SWAP compared to a single CNOT?

(c) How many CNOTs does a 3-qubit permutation (e.g., the cyclic permutation $|abc\rangle \to |bca\rangle$) require? Design the circuit.

Exercise 7.9 — Circuit Depth Trade-offs

(a) Implement the 4-qubit QFT circuit in two ways: (1) the standard linear-depth version, and (2) a log-depth version using parallel controlled-phase gates. Compare their depths.

(b) For a 10-qubit QFT, what is the ratio of depths between the two implementations?

Exercise 7.10 — Toffoli Gate Decomposition

(a) Decompose the Toffoli gate into CNOT and single-qubit gates. The standard decomposition uses 6 CNOTs. Find or verify this decomposition.

(b) Show that if you have one ancilla qubit in state $|0\rangle$, the Toffoli can be decomposed using only 4 CNOTs.

(c) Verify both decompositions by comparing their unitaries with the Toffoli unitary.