# Appendix A — Mathematical toolkit {#toolkit .unnumbered}

This appendix supplies details that are useful across chapters. It can be read when a calculation first needs them rather than memorized before beginning.

## Matrix multiplication and adjoints

For matrices A of shape m×n and B of shape n×p,
$(AB)_{jk}=\sum_{\ell=1}^nA_{j\ell}B_{\ell k}$.
The inner dimensions must match. For two square matrices,

$$\begin{pmatrix}a&b\\c&d\end{pmatrix}
\begin{pmatrix}e&f\\g&h\end{pmatrix}
=\begin{pmatrix}ae+bg&af+bh\\ce+dg&cf+dh\end{pmatrix}.$$

The adjoint conjugates entries and transposes:
$(A^\dagger)_{jk}=A_{kj}^*$. It reverses products:
$(AB)^\dagger=B^\dagger A^\dagger$. Consequently a circuit's inverse reverses gate order and replaces each gate with its adjoint.

An outer product $|u\rangle\langle v|$ is a matrix with entries $u_jv_k^*$. Its action on $|w\rangle$ is
$|u\rangle(\langle v|w\rangle)$. An inner product is a scalar. Confusing the order changes the mathematical type of the result.

## Eigenvectors and diagonalization

An eigenvector satisfies $A|v\rangle=\lambda|v\rangle$ with nonzero v. Eigenvalues solve $\det(A-\lambda I)=0$. For a Hermitian two-by-two matrix

$$A=\begin{pmatrix}a&c\\c^*&b\end{pmatrix},\quad a,b\in\mathbb R,$$

the characteristic equation is

$$(a-\lambda)(b-\lambda)-|c|^2=0,$$
$$\lambda^2-(a+b)\lambda+ab-|c|^2=0.$$

Thus

$$\lambda_\pm=\frac{a+b\pm\sqrt{(a-b)^2+4|c|^2}}2.$$

These are real. Solve $(A-\lambda I)v=0$ for each eigenvector and normalize. If eigenvalues are distinct, Hermiticity makes the eigenvectors orthogonal: taking matrix elements in both orders gives
$(\lambda-\mu)\langle v|w\rangle=0$.

The spectral theorem writes a Hermitian matrix as
$A=\sum_j\lambda_j|v_j\rangle\langle v_j|$ with an orthonormal eigenbasis. It defines functions of A:
$f(A)=\sum_jf(\lambda_j)|v_j\rangle\langle v_j|$.
This explains exponentials of Hamiltonians, square roots of positive matrices, and matrix entropy.

A matrix is positive semidefinite exactly when all its eigenvalues are nonnegative. A two-by-two Hermitian density matrix with trace one is physical if its diagonal entries and determinant are nonnegative. Checking only trace and Hermiticity is insufficient.

## Gram–Schmidt and projection

Given a normalized vector $|u\rangle$ and another vector $|v\rangle$, subtract its component along u:

$$|w\rangle=|v\rangle-|u\rangle\langle u|v\rangle.$$

Then
$\langle u|w\rangle=\langle u|v\rangle-\langle u|u\rangle\langle u|v\rangle=0$.
If w is nonzero, normalize it. Repeating this process builds an orthonormal basis from linearly independent vectors.

For an orthonormal set, the projector onto its span is
$P=\sum_j|u_j\rangle\langle u_j|$. It obeys $P^2=P=P^\dagger$.
For a complete basis, P=I. Expanding a vector using this identity yields its projection coefficients.

The Cauchy–Schwarz inequality
$|\langle u|v\rangle|^2\le\langle u|u\rangle\langle v|v\rangle$
ensures that overlap probabilities between normalized states lie in [0,1]. Equality occurs when the vectors are linearly dependent.

## Singular values and Schmidt form

For any matrix M, the eigenvalues of $M^\dagger M$ are nonnegative. Their square roots are its singular values. A singular-value decomposition is
$M=U\Sigma V^\dagger$, with diagonal nonnegative Σ and unitary U,V of suitable shapes.

For a bipartite pure state's coefficient matrix $M_{ab}=c_{ab}$, the singular values are square roots of the Schmidt probabilities. In the fixed product bases, the reduced operators are $\rho_A=MM^\dagger$ and $\rho_B=M^T M^*=(M^\dagger M)^T$. Indeed, $(\rho_B)_{bb'}=\sum_a M_{ab}M^*_{ab'}$. Both have the same nonzero eigenvalues. Their equality of spectra explains equal reduced entropies for a pure joint state.

The largest singular value is the operator norm ‖M‖, the maximum stretching of a unit vector. The trace norm sums singular values. The Frobenius norm is
$\|M\|_F=\sqrt{\sum_{jk}|M_{jk}|^2}$.
Different norms answer different error questions; state overlap, global operator error, and local observable error should not be interchanged.

## Geometric sums and Fourier cancellation

For r≠1,

$$1+r+\cdots+r^{N-1}=\frac{1-r^N}{1-r}.$$

Multiply the left side by 1−r and all intermediate terms cancel. For a nontrivial Nth root of unity, $r^N=1$, so the sum is zero. For r=1, the sum is N; using the quotient without taking the limit would divide by zero.

This one identity proves QFT column orthogonality and determines finite-precision phase-estimation peaks. Binary Hadamard cancellation is a related character-orthogonality identity for XOR rather than addition modulo N.

## Continued fractions by recurrence

For partial quotients $a_0,a_1,\ldots$, initialize
$p_{-2}=0,p_{-1}=1,q_{-2}=1,q_{-1}=0$. Then

$$p_k=a_kp_{k-1}+p_{k-2},\qquad
q_k=a_kq_{k-1}+q_{k-2}.$$

The kth convergent is $p_k/q_k$. For $[0;2,1,170]$:
$0/1$, $1/2$, $1/3$, and $171/512$ follow directly.
In order finding, a good rational approximation still needs a modular check; the recurrence does not know the physical problem's order.

## Confidence and finite samples

For independent Bernoulli samples, the standard deviation of a sample proportion is $\sqrt{p(1-p)/N}$. Substituting $\hat p$ gives an estimated standard error, but near zero or one a naive normal interval can be misleading.

A distribution-free bound for independent bounded trials is Hoeffding's inequality:

$$\Pr(|\hat p-p|\ge\epsilon)\le2e^{-2N\epsilon^2}.$$

To make this at most δ, it suffices that
$N\ge\ln(2/\delta)/(2\epsilon^2)$.
This is conservative but does not require an unknown p in the bound. It still assumes independence; repeated drift or correlated experimental errors need another analysis.

For several simultaneous claims, their combined error probability must be controlled. A union bound can allocate δ across them. Reporting many favorable outcomes from a large unreported search is not equivalent to testing one prespecified prediction.

## Global phase in numerical comparisons

Two vectors may represent the same pure state while having different entries. Fidelity
$|\langle\psi|\phi\rangle|^2$ compares them without global-phase sensitivity. To compare entries, estimate the phase from a nonzero overlap and align one vector first.

Do not use phase-insensitive comparison when relative phases between controlled branches matter. A subroutine equal to a target up to phase may produce a different controlled operation if that phase is not tracked. The scope of the comparison must match the circuit's use.

