Solution (source code)

= Solution

Represent the pure states by <density matrices> $\rho_u=(I+u\cdot\sigma)/2$ and $\rho_v=(I+v\cdot\sigma)/2$. The <Pauli matrices> obey $\operatorname{Tr}\sigma_i=0$ and $\operatorname{Tr}(\sigma_i\sigma_j)=2\delta_{ij}$. Consequently
$$
\operatorname{Tr}(\rho_u\rho_v)=\frac14\operatorname{Tr}\left[I+(u+v)\cdot\sigma+
\sum_{i,j}u_iv_j\sigma_i\sigma_j\right]
=\frac12(1+u\cdot v).
$$
On the other hand, $\rho_u=|u\rangle\langle u|$ and $\rho_v=|v\rangle\langle v|$ make that <trace> equal to $\langle u|v\rangle\langle v|u\rangle$. Thus the <pure-qubit overlap identity> is
$$
\boxed{|\langle u|v\rangle|^2=\tfrac12(1+u\cdot v).}
$$
For mixed states the <trace> formula still holds, but its left side is then a Hilbert–Schmidt overlap rather than this squared pure-state overlap.