SchmidtDecomposition

From QETLAB
Jump to: navigation, search
SchmidtDecomposition
Computes the Schmidt decomposition of a bipartite vector

Other toolboxes required none
Related functions IsProductVector
OperatorSchmidtDecomposition
SchmidtRank
Function category Entanglement and separability

SchmidtDecomposition is a function that computes the Schmidt decomposition of a bipartite vector. The user may specify how many terms in the Schmidt decomposition they wish to be returned.

Syntax

  • S = SchmidtDecomposition(VEC)
  • S = SchmidtDecomposition(VEC,DIM)
  • S = SchmidtDecomposition(VEC,DIM,K)
  • [S,U,V] = SchmidtDecomposition(VEC,DIM,K)

Argument descriptions

Input arguments

  • VEC: A bipartite vector (e.g., a pure quantum state) to have its Schmidt decomposition computed.
  • DIM (optional, by default has both subsystems of equal dimension): A 1-by-2 vector containing the dimensions of the subsystems that VEC lives on.
  • K (optional, default 0): A flag that determines how many terms in the Schmidt decomposition should be computed. If K = 0 then all terms with non-zero Schmidt coefficients are computed. If K = -1 then all terms (including zero Schmidt coefficients) are computed. If K > 0 then the K terms with largest Schmidt coefficients are computed.

Output arguments

  • S: A vector containing the Schmidt coefficients of VEC.
  • U (optional): A matrix whose columns are the left Schmidt vectors of VEC.
  • V (optional): A matrix whose columns are the right Schmidt vectors of VEC.

Examples

The following code returns the Schmidt decomposition of the standard maximally-entangled pure state $\frac{1}{\sqrt{d}}\sum_j|j\rangle\otimes|j\rangle \in \mathbb{C}^d \otimes \mathbb{C}^d$ in the $d = 3$ case:

>> [s,u,v] = SchmidtDecomposition(MaxEntangled(3))
 
s =
 
    0.5774
    0.5774
    0.5774
 
 
u =
 
     1     0     0
     0     1     0
     0     0     1
 
 
v =
 
     1     0     0
     0     1     0
     0     0     1

Source code

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

  1. %%  SCHMIDTDECOMPOSITION   Computes the Schmidt decomposition of a bipartite vector
  2. %   This function has one required argument:
  3. %     VEC: a bipartite vector to have its Schmidt decomposition computed
  4. %
  5. %   S = SchmidtDecomposition(VEC) is a vector containing the non-zero
  6. %   Schmidt coefficients of the bipartite vector VEC, where the two
  7. %   subsystems are each of size sqrt(length(VEC)).
  8. %
  9. %   This function has two optional input arguments:
  10. %     DIM (default [sqrt(length(VEC)),sqrt(length(VEC))])
  11. %     K (default 0)
  12. %
  13. %   [S,U,V] = SchmidtDecomposition(VEC,DIM,K) gives the Schmidt
  14. %   coefficients S of the vector VEC and the corresponding left and right
  15. %   Schmidt vectors in the matrices U and V. DIM is a 1x2 vector containing
  16. %   the dimensions of the subsystems that VEC lives on. K is a flag that
  17. %   determines how many terms in the Schmidt decomposition should be
  18. %   computed. If K = 0 then all terms with non-zero Schmidt coefficients
  19. %   are computed. If K = -1 then all terms (including zero Schmidt
  20. %   coefficients) are computed. If K > 0 then the K terms with largest
  21. %   Schmidt coefficients are computed.
  22. %
  23. %   If DIM is a scalar instead of a vector, then it is assumed that the
  24. %   first subsystem of size DIM and the second subsystem of size
  25. %   length(VEC)/DIM.
  26. %
  27. %   URL: http://www.qetlab.com/SchmidtDecomposition
  28.  
  29. %   requires: opt_args.m
  30. %   author: Nathaniel Johnston (nathaniel@njohnston.ca)
  31. %   package: QETLAB
  32. %   last updated: December 1, 2012
  33.  
  34. function [s,u,v] = SchmidtDecomposition(vec,varargin)
  35.  
  36. lv = length(vec);
  37.  
  38. % set optional argument defaults: dim=sqrt(length(vec)), k=0
  39. [dim,k] = opt_args({ round(sqrt(lv)), 0 },varargin{:});
  40.  
  41. % allow the user to enter a single number for dim
  42. if(length(dim) == 1)
  43.     dim = [dim,lv/dim];
  44.     if abs(dim(2) - round(dim(2))) >= 2*lv*eps
  45.         error('SchmidtDecomposition:InvalidDim','The value of DIM must evenly divide length(VEC); please provide a DIM array containing the dimensions of the subsystems.');
  46.     end
  47.     dim(2) = round(dim(2));
  48. end
  49.  
  50. % Try to guess whether svd or svds will be faster, and then perform the
  51. % appropriate singular value decomposition.
  52. adj = 20 + 1000*(~issparse(vec));
  53.  
  54. if(k > 0 && k <= ceil(min(dim)/adj)) % just a few Schmidt coefficients
  55.     [v,s,u] = svds(reshape(vec,dim(end:-1:1)),k);
  56. else % lots of Schmidt coefficients
  57.     [v,s,u] = svd(reshape(full(vec),dim(end:-1:1)));
  58.     if(k > 0)
  59.         v = v(:,1:k);
  60.         s = s(:,1:k);
  61.         u = u(:,1:k);
  62.     end
  63. end
  64. s = diag(s);
  65. if(k == 0)
  66.     r = sum(s > max(dim) * eps(s(1)));  % Schmidt rank (use same tolerance as MATLAB's rank function)
  67.     s = s(1:r);   % Schmidt coefficients
  68.     u = u(:,1:r);
  69.     v = v(:,1:r);
  70. end
  71. u = conj(u);