Code accompanying the manuscript Nat. Phys. 19, 184–189 (2023) (arXiv:2111.02438).
The code below shows how to implement the tempered negativity $N_\tau(\rho)$, a lower bound on entanglement cost of any state. It requires CVX for MATLAB and additionally uses the helper function PartialTranspose
from QETLAB.
It takes three arguments:
rho
,omega
, if one wishes to compute $N_\tau(\rho | \omega)$,d
when both subsystems have equal dimension, or as a list [dA, dB]
; if not provided, the dimensions are assumed to be equal.As the last two arguments are both optional, function calls of the form TempN(rho)
, TempN(rho, [dA, dB])
, TempN(rho, omega)
, TempN(rho, omega, [dA, dB])
are all valid.
The function returns the value of $N_\tau$ and an optimal dual operator $X$.
function [cvx_optval, X] = TempN(rho, varargin)
% the ugly block of code below handles the various optional arguments
if nargin<2
omega = rho;
d = sqrt(max(size(rho)))*[1,1];
elseif nargin==2
if min(size(varargin{1})) == 1
omega = rho;
d = varargin{1} * ones(1,3-max(size(varargin{1})));
else
omega = varargin{1};
d = sqrt(max(size(rho)))*[1,1];
end
elseif nargin==3
omega = varargin{1};
d = varargin{2} * ones(1,3-max(size(varargin{2})));;
end
D = prod(d);
rho = (rho+rho')/2; % to avoid numerical issues
omega = (omega+omega')/2;
% main SDP
cvx_begin sdp quiet
variable X(D,D) hermitian
maximize trace(X*rho)
-eye(D) <= PartialTranspose(X,2,d) <= eye(D)
-trace(X*omega)*eye(D) <= X <= trace(X*omega)*eye(D)
cvx_end
end