Swap

Swap is a function that swaps the position of two subsystems in the space on which a quantum state or operator live. Note that the state or operator can have more than two subsystems altogether – the remaining subsystems are not affected. To permute the positions of more than two subsystems, use the PermuteSystems function.

Syntax

 * SX = Swap(X)
 * SX = Swap(X,SYS)
 * SX = Swap(X,SYS,DIM)
 * SX = Swap(X,SYS,DIM,ROW_ONLY)

Argument descriptions

 * X: a vector (e.g., a pure quantum state) or a matrix to have its subsystems permuted
 * SYS (optional, default [1,2]</tt>): a 1-by-2 vector containing the indices of the subsystems to be swapped
 * DIM</tt> (optional, by default has all subsystems of equal dimension): A specification of the dimensions of the subsystems that X</tt> lives on. DIM</tt> can be provided in one of three ways:
 * If DIM</tt> is a scalar, it is assumed that X</tt> lives on the tensor product of two spaces, the first of which has dimension DIM</tt> and the second of which has dimension length(X)/DIM</tt>.
 * If $X \in M_{n_1} \otimes \cdots \otimes M_{n_p}$ then DIM</tt> should be a row vector containing the dimensions (i.e., DIM = [n_1, ..., n_p]</tt>).
 * If the subsystems aren't square (i.e., $X \in M_{m_1, n_1} \otimes \cdots \otimes M_{m_p, n_p}$) then DIM</tt> should be a matrix with two rows. The first row of DIM</tt> 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_p; n_1, ..., n_p]</tt>.
 * ROW_ONLY</tt> (optional, default 0</tt>): If set equal to 1</tt>, only the rows of <tt>X</tt> are permuted (this is equivalent to multiplying <tt>X</tt> on the left by <tt>SwapOperator(DIM,SYS)</tt>). If equal to <tt>0</tt>, both the rows and columns of <tt>X</tt> are permuted (this is equivalent to multiplying <tt>X</tt> on both the left and right by the swap operator).

Examples
The following code constructs a 4-by-4 matrix (thought of as an operator in $M_2 \otimes M_2$) and then swaps the two subsystems, which is equivalent to multiplying on the left and right by the swap operator: