# MatsumotoFidelity

 Other toolboxes required MatsumotoFidelity Computes the Matsumoto fidelity of two density matrices none Fidelity Norms and distance measures yes (concave)

MatsumotoFidelity is a function that computes the Matsumoto fidelity[1][2] between two quantum states $\rho$ and $\sigma$, defined by $F(\rho,\sigma) := \mathrm{Tr}(\rho\#\sigma),$ where $\rho\#\sigma := \rho^{1/2}\Big(\rho^{-1/2}\sigma\rho^{-1/2}\Big)\rho^{1/2}.$

## Syntax

• FID = MatsumotoFidelity(RHO,SIGMA)

## Argument descriptions

• RHO: A density matrix.
• SIGMA: A density matrix.

## Examples

### Pure states

If $\rho = |v\rangle\langle v|$ and $\sigma = |w\rangle\langle w|$ are both pure states then their Matsumoto fidelity simply equals 1 if they are parallel and zero otherwise:

>> v = RandomStateVector(4);
>> w = RandomStateVector(4);
>> MatsumotoFidelity(v*v',w*w')

ans =

1.7454e-05

This highlights one slight limitation of this function: it is only accurate to 4 or so decimal places when both inputs are non-invertible (it is much more accurate if at least one input is invertible).

## Source code

Click on "expand" to the right to view the MATLAB source code for this function.

1. %%  MATSUMOTOFIDELITY    Computes the Matsumoto fidelity of two density matrices
2. %   This function has two required input arguments:
3. %     RHO,SIGMA: density matrices
4. %
5. %   FID = MatsumotoFidelity(RHO,SIGMA) is the Matsumoto fidelity between
6. %   the two density matrices RHO and SIGMA, defined by tr(RHO#SIGMA), where
7. %   RHO#SIGMA is the matrix geometric mean. FID is a value between 0 and 1,
8. %   with 0 corresponding to matrices RHO and SIGMA with 0-intersection
9. %   ranges, and 1 corresponding to the case RHO = SIGMA.
10. %
11. %   URL: http://www.qetlab.com/MatsumotoFidelity
12. 
13. %   requires: nothing (only uses CVX if called as an input to CVX)
14. %   authors: Nathaniel Johnston (nathaniel@njohnston.ca)
15. %   package: QETLAB
16. %   last updated: June 23, 2020
17. 
18. function fid = MatsumotoFidelity(rho,sigma)
19. 
20. sz_rho = size(rho);
21. 
22. % Do some error checking.
23. if(~all(sz_rho == size(sigma)))
24.     error('MatsumotoFidelity:InvalidDims','RHO and SIGMA must be matrices of the same size.');
25. elseif(sz_rho(1) ~= sz_rho(2))
26.     error('MatsumotoFidelity:InvalidDims','RHO and SIGMA must be square.');
27. end
28. 
29. % If rho or sigma is a CVX variable then compute fidelity via semidefinite
30. % programming, so that this function can be used in the objective function
31. % or constraints of other CVX optimization problems.
32. if(isa(rho,'cvx') || isa(sigma,'cvx'))
33.     cvx_begin sdp quiet
34.         cvx_precision best
35.         variable X(sz_rho(1),sz_rho(1)) hermitian;
36.         maximize trace(X);
37.         subject to
38.             cons = [rho,X;X,sigma];
39.             cons + cons' >= 0; % avoid some numerical problems: CVX often thinks things aren't hermitian without this
40.     cvx_end
41. 
42.     fid = cvx_optval;
43. 
44. % If rho and sigma are *not* CVX variables, compute fidelity normally,
45. % since this is much faster.
46. else
47.     if(abs(det(sigma)) > abs(det(rho))) % for numerical stability, invert the density matrix with larger determinant
48.         temp_rho = rho;
49.         rho = sigma;
50.         sigma = temp_rho;
51.     end
52.     rho = rho + 10^(-8)*eye(sz_rho(1)); % need rho to be invertilble -- this is a ham-fisted way of avoiding problems
53.     [sq_rho,res] = sqrtm(rho); % need "res" parameter to suppress MATLAB singularity warning
54.     isq_rho = inv(sq_rho);
55.     isq_rho = (isq_rho+isq_rho')/2;
56.     [sq_fid,res] = sqrtm(isq_rho*sigma*isq_rho);
57.     fid = real(trace(sq_rho*sq_fid*sq_rho)); % finally, compute the fidelity
58. end

## References

1. K. Matsumoto. Reverse test and quantum analogue of classical fidelity and generalized fidelity. E-print: arXiv:1006.0302, 2010.
2. S. S. Cree and J. Sikora. A fidelity measure for quantum states based on the matrix geometric mean. E-print: arXiv:2006.06918, 2020.