forked from nathanieljohnston/QETLAB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSkVectorNorm.m
53 lines (47 loc) · 1.93 KB
/
SkVectorNorm.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
%% SKVECTORNORM Computes the s(k)-norm of a vector
% This function has one required argument:
% VEC: a bipartite vector to have its s(k)-norm computed
%
% NRM = SkVectorNorm(VEC) is the maximal inner product of the bipartite
% vector VEC with a separable pure state. This is equal to the largest
% Schmidt coefficient of VEC.
%
% This function has two optional input arguments:
% K (default 1)
% DIM (default has both subsystems of equal dimension)
%
% NRM = SkVectorNorm(VEC,K,DIM) is the maximal inner product of VEC with
% a state that has Schmidt rank <= K. This quantity is equal to the sum
% of the squares of the singular values of the partial trace of VEC. It
% is also equal to the Euclidean norm of the vector of VEC's k largest
% Schmidt coefficients.
%
% DIM is a 1x2 vector containing the dimensions of the subsystems that
% VEC lives on. If DIM is a scalar instead of a vector, then it is
% assumed that the first subsystem of size DIM and the second subsystem
% of size length(VEC)/DIM.
%
% URL: http://www.qetlab.com/SkVectorNorm
% requires: opt_args.m, SchmidtDecomposition.m
% author: Nathaniel Johnston ([email protected])
% package: QETLAB
% last updated: December 2, 2012
function nrm = SkVectorNorm(vec,varargin)
lv = length(vec);
% set optional argument defaults: k=1, dim=sqrt(length(vec))
[k,dim] = opt_args({ 1, round(sqrt(lv)) },varargin{:});
% allow the user to enter a single number for dim
if(length(dim) == 1)
dim = [dim,lv/dim];
if abs(dim(2) - round(dim(2))) >= 2*lv*eps
error('SkVectorNorm:InvalidDim','If DIM is a scalar, it must evenly divide length(VEC); please provide a DIM array containing the dimensions of the subsystems.');
end
dim(2) = round(dim(2));
end
% It's faster to just compute the norm of VEC directly if that will give
% the correct answer.
if(k >= min(dim))
nrm = norm(vec);
else
nrm = norm(SchmidtDecomposition(vec,dim,k));
end