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...
Thanks in advance!