# Difference between revisions of "Realignment"

 Other toolboxes required Realignment Computes the realignment of a bipartite operator none PartialTransposePermuteSystemsSwap Superoperators

Realignment is a function that computes the realignment of a bipartite operator.

## Syntax

• RX = Realignment(X)
• RX = Realignment(X,DIM)

## Argument descriptions

• X: A bipartite operator to have its realignment computed.
• DIM (optional, by default has both subsystems of equal dimension): A specification of the dimensions of the subsystems that X lives on. DIM can be provided in one of three ways:
• If DIM is a scalar, it is assumed that the first subsystem has dimension DIM and the second subsystem has dimension length(X)/DIM.
• If $X \in M_{n_1} \otimes M_{n_2}$ then DIM should be a row vector containing the dimensions (i.e., DIM = [n_1, n_2]).
• If the subsystems aren't square (i.e., $X \in M_{m_1, n_1} \otimes M_{m_2, n_2}$) then DIM should be a matrix with two rows. The first row of DIM should contain the row dimensions of the subsystems (i.e., the mi's) and its second row should contain the column dimensions (i.e., the ni's). In other words, you should set DIM = [m_1, m_2; n_1, n_2].

## Examples

### A two-qubit example

When viewed as a map on block matrices, the realignment map takes each block of the original matrix and makes its vectorization the rows of the realignment matrix. This is illustrated by the following small example:

>> X = reshape(1:16,4,4)'

X =

1     2     3     4
5     6     7     8
9    10    11    12
13    14    15    16

>> Realignment(X)

ans =

1     2     5     6
3     4     7     8
9    10    13    14
11    12    15    16

### A non-square example

The realignment map sends $|i\rangle\langle j| \otimes |k\rangle\langle \ell|$ to $|i\rangle\langle k| \otimes |j\rangle\langle \ell|$. Thus it changes the dimensions of matrices if the subsystems aren't square and of the same size. The following code computes the realignment of an operator $X \in M_{5,2} \otimes M_{3,7}$:

>> X = reshape(1:210,14,15)'

X =

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    54    55    56
57    58    59    60    61    62    63    64    65    66    67    68    69    70
71    72    73    74    75    76    77    78    79    80    81    82    83    84
85    86    87    88    89    90    91    92    93    94    95    96    97    98
99   100   101   102   103   104   105   106   107   108   109   110   111   112
113   114   115   116   117   118   119   120   121   122   123   124   125   126
127   128   129   130   131   132   133   134   135   136   137   138   139   140
141   142   143   144   145   146   147   148   149   150   151   152   153   154
155   156   157   158   159   160   161   162   163   164   165   166   167   168
169   170   171   172   173   174   175   176   177   178   179   180   181   182
183   184   185   186   187   188   189   190   191   192   193   194   195   196
197   198   199   200   201   202   203   204   205   206   207   208   209   210

>> Realignment(X,[5,3;2,7])

ans =

1     2     3     4     5     6     7    15    16    17    18    19    20    21    29    30    31    32    33    34    35
8     9    10    11    12    13    14    22    23    24    25    26    27    28    36    37    38    39    40    41    42
43    44    45    46    47    48    49    57    58    59    60    61    62    63    71    72    73    74    75    76    77
50    51    52    53    54    55    56    64    65    66    67    68    69    70    78    79    80    81    82    83    84
85    86    87    88    89    90    91    99   100   101   102   103   104   105   113   114   115   116   117   118   119
92    93    94    95    96    97    98   106   107   108   109   110   111   112   120   121   122   123   124   125   126
127   128   129   130   131   132   133   141   142   143   144   145   146   147   155   156   157   158   159   160   161
134   135   136   137   138   139   140   148   149   150   151   152   153   154   162   163   164   165   166   167   168
169   170   171   172   173   174   175   183   184   185   186   187   188   189   197   198   199   200   201   202   203
176   177   178   179   180   181   182   190   191   192   193   194   195   196   204   205   206   207   208   209   210

## Source code

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

1. %%  REALIGNMENT    Computes the realignment of a bipartite operator
2. %   This function has one required argument:
3. %     X: a matrix
4. %
5. %   RX = Realignment(X) is the realignment of the matrix X, where it is
6. %   assumed that the number of rows and columns of X are both perfect
7. %   squares and both subsystems have equal dimension. The realignment is
8. %   defined by mapping the operator |ij><kl| to |ik><jl| and extending
9. %   linearly.
10. %
11. %   This function has one optional argument:
12. %     DIM (default has all subsystems of equal dimension)
13. %
14. %   RX = Realignment(X,DIM) gives the realignment of the matrix X,
15. %   where the dimensions of the two subsystems are given by the vector DIM.
16. %   If X is non-square, different row and column dimensions can be
17. %   specified by putting the row dimensions in the first row of DIM and the
18. %   column dimensions in the second row of DIM.
19. %
20. %   URL: http://www.qetlab.com/Realignment
21. 
22. %   requires: opt_args.m, PartialTranspose.m, PermuteSystems.m, Swap.m
23. %   author: Nathaniel Johnston (nathaniel@njohnston.ca)
24. %   package: QETLAB
25. %   last updated: November 12, 2014
26. 
27. function RX = Realignment(X,varargin)
28. 
29. dX = size(X);
30. round_dim = round(sqrt(dX));
31. 
32. % set optional argument defaults: dim = sqrt(length(dim))
33. [dim] = opt_args({ round_dim' },varargin{:});
34. 
35. % allow the user to enter a single number for dim
36. if(length(dim) == 1)
37.     dim = [dim,dX(1)/dim];
38.     if abs(dim(2) - round(dim(2))) >= 2*dX(1)*eps
39.         error('Realignment:InvalidDim','If DIM is a scalar, X must be square and DIM must evenly divide length(X); please provide the DIM array containing the dimensions of the subsystems.');
40.     end
41.     dim(2) = round(dim(2));
42. end
43. 
44. % allow the user to enter a vector for dim if X is square
45. if(min(size(dim)) == 1)
46.     dim = dim(:)'; % force dim to be a row vector
47.     dim = [dim;dim];
48. end
49. 
50. % perform the realignment, using the fact that RX = S*PartialTranspose(S*X,1), where S is the swap operator
51. RX = Swap(PartialTranspose(Swap(X,[1,2],dim,1),1,[dim(1,2),dim(1,1);dim(2,1),dim(2,2)]),[1,2],[dim(2,1),dim(1,1);dim(1,2),dim(2,2)],1);