Solution (source code)

= Solution

Set $X=\rho-\sigma$. The <trace distance> is $D(\rho,\sigma)=\tfrac12\|X\|_1$, where $\|X\|_1=\operatorname{Tr}\sqrt{X^\dagger X}$. Since $X$ is a <Hermitian operator>, its <spectral decomposition> is $X=\sum_jx_j|j\rangle\langle j|$. Define its <positive part of a Hermitian operator> and <negative part of a Hermitian operator> by
$$
Q=\sum_{x_j>0}x_j|j\rangle\langle j|,\qquad
R=\sum_{x_j<0}(-x_j)|j\rangle\langle j|.
$$
They are <positive semidefinite operators>, satisfy $X=Q-R$ and $QR=0$, and obey $|X|=Q+R$. Therefore
$$
\boxed{D(\rho,\sigma)=\frac12(\operatorname{Tr}Q+\operatorname{Tr}R).}
$$
The states have equal trace, so $\operatorname{Tr}X=0$ and $\operatorname{Tr}Q=\operatorname{Tr}R=D(\rho,\sigma)$. This is the <spectral-parts formula for trace distance>.