# Implementation of quantum Uhlmann Fidelity in Mathematica

I want to implement the quantum Uhlmann fidelity $$F(\rho, \sigma) := \mathrm{tr} \left[\sqrt{\sqrt{\rho} \sigma \sqrt{\rho}} \right]^2.$$ in Mathematica as a measure of "closeness" between two density matrices.

However, I think that my implementation is wrong.

$$fidelity[\rho\_, \sigma\_] := (\mathrm{Tr} \left[\sqrt{(\sqrt{\rho}).\sigma.(\sqrt{\rho})} \right])^2$$

When I test it on test$$\rho$$ = {{1/9, 2/3, 2/9}, {1/3, 4/9, 4/9}, {2/9, 4/9, 4/9}};

test$$\sigma$$ = {{1/9, 1/3, 2/9}, {1/3, 4/9, 4/9}, {2/9, 4/9, 4/9}};

I get a fidelity of 1, which is obviously not correct, as these matrices are not the same. I would expect that the fidelity is 1 if and only if $$\rho=\sigma$$.

• You need use MatrixPower to take a matrix square root. What you do in your code takes each matrix element’s square root, which is very different. – Roman Sep 5 '20 at 9:08
• Could it be that $\varrho$ needs to have trace equal to one for $F(\varrho,\varrho) = 1$ to hold true? Your $\varrho$ has trace $0.8 \neq 1$. Which is to say, your $\varrho$ is not a density matrix... – Henrik Schumacher Sep 5 '20 at 9:18
• @ Thanks, I updated the post with two different density matrices that give the wrong result. – MrDerDart Sep 5 '20 at 9:58
• Your new test matrices are not positive semi-definite. – Roman Sep 5 '20 at 11:40

Here is a definition that is insensitive to density matrix normalization:

F[ρ_, σ_] := Tr[MatrixPower[MatrixPower[ρ, 1/2].σ.MatrixPower[ρ, 1/2], 1/2]]^2/(Tr[ρ]*Tr[σ])


Tests with positive semi-definite $$3\times3$$ matrices:

testρ = {{1/5, 1/5, 0}, {1/5, 3/5, 1/5}, {0, 1/5, 1/5}};
testσ = {{1/3, -1/6, 1/6}, {-1/6, 1/3, -1/6}, {1/6, -1/6, 1/3}};

F[testρ, testρ] // FullSimplify
(*    1    *)

F[testρ, testσ] // FullSimplify
(*    8/15    *)

F[testσ, testρ] // FullSimplify
(*    8/15    *)

F[testσ, testσ] // FullSimplify
(*    1    *)