Skip to content

Selected Exercise Solutions

This appendix provides solutions to selected exercises marked with \((\star)\) throughout the book. Solutions to all programming exercises can be found in the companion GitHub repository.

Chapter 1: Mathematical Prerequisites

Exercise 1.1 (Fundamental): Show that the set of \(2\times2\) Hermitian matrices forms a real vector space. Find a basis.

Solution: A Hermitian matrix \(A\) satisfies \(A=A^\dagger\), i.e., \(A_{ij} = A_{ji}^*\). The diagonal entries are real; the off-diagonal entries are complex conjugates. A basis for \(2\times2\) Hermitian matrices: \(\{I, X, Y, Z\}\) (the Pauli matrices plus identity). Dimension: 4 (real). Linear combinations with real coefficients: \(aI + bX + cY + dZ\) for \(a,b,c,d\in\mathbb{R}\).

Chapter 2: Quantum Computing Essentials

Exercise 2.1 (Fundamental): Prove that the Hadamard gate is its own inverse.

Solution: \(H^2 = \frac{1}{\sqrt{2}}\begin{pmatrix}1&1\\1&-1\end{pmatrix} \cdot\frac{1}{\sqrt{2}}\begin{pmatrix}1&1\\1&-1\end{pmatrix} = \frac{1}{2}\begin{pmatrix}2&0\\0&2\end{pmatrix} = I\). ✓

Exercise 2.2 (Intermediate): Show that CNOT transforms \(|++\rangle\) to \(|++\rangle\) and \(|+-\rangle\) to \(|--\rangle\) (Hadamard basis).

Solution: \(|+\rangle = (|0\rangle+|1\rangle)/\sqrt{2}\), \(|-\rangle = (|0\rangle-|1\rangle)/\sqrt{2}\).

\(\text{CNOT}|++\rangle = \text{CNOT}\cdot\frac{1}{2}(|00\rangle+|01\rangle+|10\rangle+|11\rangle) = \frac{1}{2}(|00\rangle+|01\rangle+|11\rangle+|10\rangle) = |++\rangle\). ✓

\(\text{CNOT}|+-\rangle = \text{CNOT}\cdot\frac{1}{2}(|00\rangle-|01\rangle+|10\rangle-|11\rangle) = \frac{1}{2}(|00\rangle-|01\rangle+|11\rangle-|10\rangle) = |--\rangle\). ✓

Chapter 6: Variational Quantum Circuits

Exercise 6.1: For a QAOA circuit with \(p=1\) layer on a MaxCut instance with 4 nodes arranged in a cycle (edges \(\{01, 12, 23, 30\}\)), write out the cost and mixer Hamiltonians and derive the QAOA expectation value as a function of \((\gamma, \beta)\).

Solution: Cost Hamiltonian for MaxCut: \(H_C = \frac{1}{2}\sum_{\{i,j\}\in E}(1 - Z_iZ_j) = 2 - \frac{1}{2}(Z_0Z_1 + Z_1Z_2 + Z_2Z_3 + Z_3Z_0)\).

Mixer: \(H_B = \sum_{i=0}^3 X_i\).

\(p=1\) QAOA state: \(|\psi(\gamma,\beta)\rangle = e^{-i\beta H_B}e^{-i\gamma H_C}|+\rangle^4\).

After calculation, \(\langle H_C\rangle = 2 - \sin(4\beta)\sin(\gamma)\cos^3(\gamma) \cdot[1+\cos(\gamma)\text{ terms}]\). Maximum cut size for a 4-cycle is 4 (bipartite); \(p=1\) QAOA achieves \(\langle H_C\rangle_{\max} = 2.5\) (approximation ratio \(5/8\)).

Chapter 10: Quantum Neural Networks

Exercise 10.1: Derive the PSR for \(f(\theta) = \langle\psi|R_y^\dagger(\theta) Z R_y(\theta)|\psi\rangle\) where \(|\psi\rangle = |+\rangle\).

Solution: \(|\psi(\theta)\rangle = R_y(\theta)|+\rangle\). \(f(\theta) = \langle+|R_y^\dagger(\theta)Z R_y(\theta)|+\rangle\).

\(R_y(\theta)|+\rangle = \frac{1}{\sqrt{2}}(R_y(\theta)|0\rangle + R_y(\theta)|1\rangle) = \frac{1}{\sqrt{2}}\left[\begin{pmatrix}\cos(\theta/2)\\\sin(\theta/2)\end{pmatrix} + \begin{pmatrix}-\sin(\theta/2)\\\cos(\theta/2)\end{pmatrix}\right]\).

Computing: \(f(\theta) = \langle\psi(\theta)|Z|\psi(\theta)\rangle = -\sin\theta\).

PSR: \(f'(\theta) = \frac{1}{2}[f(\theta+\pi/2) - f(\theta-\pi/2)] = \frac{1}{2}[-\sin(\theta+\pi/2) - (-\sin(\theta-\pi/2))] = \frac{1}{2}[-\cos\theta + \cos\theta]\cdot 2 = -\cos\theta\).

Direct: \(\frac{d}{d\theta}(-\sin\theta) = -\cos\theta\). ✓

Chapter 15: Optimization

Exercise 15.1: Prove that for \(f(\theta) = a\cos\theta + b\sin\theta + c\), the PSR \(\frac{1}{2}[f(\theta+\pi/2) - f(\theta-\pi/2)] = \frac{df}{d\theta}\).

Solution: LHS \(= \frac{1}{2}[a\cos(\theta+\pi/2) + b\sin(\theta+\pi/2) + c - a\cos(\theta-\pi/2) - b\sin(\theta-\pi/2) - c]\)

\(= \frac{1}{2}[-a\sin\theta + b\cos\theta - a\sin\theta + b\cos\theta\cdot(-1)\cdot(-1) …]\)

Wait, let us compute directly: \(\cos(\theta\pm\pi/2) = \mp\sin\theta\), \(\sin(\theta\pm\pi/2) = \pm\cos\theta\).

LHS \(= \frac{1}{2}[a(-\sin\theta) + b\cos\theta - a\sin\theta - b(-\cos\theta)]\)

\(= \frac{1}{2}[-2a\sin\theta + 2b\cos\theta] = -a\sin\theta + b\cos\theta\).

RHS \(= \frac{d}{d\theta}(a\cos\theta + b\sin\theta + c) = -a\sin\theta + b\cos\theta\). ✓

Chapter 16: Barren Plateaus

Exercise 16.1: For \(n=2\) qubits and Haar-random unitaries, compute \(\mathrm{Var}_U[\partial_k\langle Z_0\rangle]\) (local cost).

Solution: By the 2-design integration formula, for local observable \(Z_0\): \(\mathbb{E}_U[\langle Z_0\rangle] = \mathrm{Tr}[Z_0]/2^n = 0\). \(\mathbb{E}_U[\langle Z_0\rangle^2] = \frac{\mathrm{Tr}[Z_0^2]}{2^n(2^n+1)} \cdot 2^n = \frac{2}{2^2+1} = \frac{2}{5}\) for \(n=2\).

The PSR gives \(\partial_k\langle Z_0\rangle = \frac{1}{2}[\langle Z_0\rangle_+ - \langle Z_0\rangle_-]\). \(\mathrm{Var}[\partial_k\langle Z_0\rangle] = \frac{1}{4}\cdot 2\cdot\mathbb{E}[\langle Z_0\rangle^2] = \frac{1}{4}\cdot 2\cdot\frac{2}{5} = \frac{1}{5}\).

This is \(O(1)\) (independent of \(n\)), confirming local costs avoid barren plateaus. ✓

Chapter 20: Finance

Exercise 20.1: Formulate the binary knapsack problem as a QUBO.

Solution: Knapsack: maximize \(\sum_i v_i x_i\) subject to \(\sum_i w_i x_i \leq W\), \(x_i\in\{0,1\}\).

QUBO (penalty method): \(\mathcal{Q}(\mathbf{x}) = -\sum_i v_i x_i + \lambda\left(\sum_i w_i x_i - W\right)^2 \cdot \mathbf{1}[\sum_i w_i x_i > W]\)

Approximate continuous penalty (always active): \(\mathcal{Q}(\mathbf{x}) = -\sum_i v_i x_i + \lambda\left(\sum_i w_i x_i - W\right)^2\)

Q matrix entries: \(Q_{ii} = -v_i + \lambda w_i^2 - 2\lambda W w_i\), \(Q_{ij} = 2\lambda w_i w_j\) for \(i\neq j\).

Compare portfolio QUBO: both are binary, quadratic, with linear and quadratic terms. Knapsack uses an inequality constraint (converted via slack variable or soft penalty); portfolio uses an equality constraint (cardinality \(\sum x_i = k\)).