# Quantum fidelity simplified formula while both of the density matrices are single qubit states

I have a question while reading the quantum fidelity definition in Wikipedia Fidelity of quantum states, at the end of the Definition section of quantum fidelity formula, it says Explicit expression for qubits. If rho and sigma are both qubit states, the fidelity can be computed as: $$F(\rho, \sigma)=\operatorname{tr}(\rho \sigma)+2 \sqrt{\operatorname{det}(\rho) \operatorname{det}(\sigma)}$$ So I'm really confused about where this formula comes from. I tested several simple examples, it seems that the formula is not suitable to calculate the fidelity between two mixed states while the dimensions of the density matrices are not $$2\times2$$ (e.g. for the case both of the two matrices are diag(0.5,0,0,0.5), the fidelity calculated by this formula is 0.5 not 1.

However, if one of the density matrices is in pure state, it seems the result now is always correct even though the dimensions of the density matrices are bigger than $$2\times2$$.

I'm wondering how to prove this formula and is it always safe to use it while one of the density matrices is in pure state...

The general expression for the fidelity is $$F(\rho,\sigma)=\left(\text{Tr}\sqrt{\sqrt{\rho}\sigma\sqrt{\rho}}\right)^2=(\text{Tr}|\sqrt{\rho\sigma}|)^2.$$ Assume $$\rho$$ and $$\sigma$$ are $$2\times 2$$ matrices. Then $$\sqrt{\rho\sigma}$$ is also a $$2\times 2$$ matrix which we assume to have eigenvalues $$\lambda_1$$ and $$\lambda_2$$. Thus, $$F=(|\lambda_1|+|\lambda_2|)^2=\lambda_1^2+\lambda_2^2+2|\lambda_1\lambda_2|.$$
However, we also have that $$\text{Tr}(\rho\sigma)=\lambda_1^2+\lambda_2^2$$ and $$\text{det}(\rho\sigma)=\lambda_1^2\lambda_2^2,$$ so $$\sqrt{\text{det}(\rho\sigma)}=|\lambda_1\lambda_2|$$. So, that proves the relation specifically for $$2\times 2$$ matrices. As you stated, it generally does not hold for larger matrices.
In the special case of $$\rho$$ being pure, it does hold, but it's far easier simply to calculate $$F=\langle\psi|\sigma|\psi\rangle=\text{Tr}(\rho\sigma)$$.