SwapOperator

From QETLAB
Revision as of 17:56, 12 November 2014 by Nathaniel (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
SwapOperator
Produces a unitary operator that swaps two subsystems

Other toolboxes required none
Related functions PermutationOperator
PermuteSystems
Swap
SymmetricProjection
Function category Permutations and symmetry of subsystems

SwapOperator is a function that returns a unitary operator that swaps two subsystems. The unitary can be chosen to be full or sparse.

Syntax

  • S = SwapOperator(DIM)
  • S = SwapOperator(DIM,SP)

Argument descriptions

  • DIM: A specification of the dimensions of the subsystems that S will act on. DIM can be provided in one of two ways:
    • If DIM is a scalar, then both subsystems are assumed to have dimension DIM.
    • If the subsystems have unequal dimensions, DIM should be a 1-by-2 vector containing their dimensions.
  • SP (optional, default 0): If set equal to 1, the swap operator is sparse. If equal to 0, the swap operator is full.

Examples

The standard swap operator

The following code produces the operator that swaps two qubits:

>> SwapOperator(2)
 
ans =
 
     1     0     0     0
     0     0     1     0
     0     1     0     0
     0     0     0     1

Source code

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

  1. %%  SWAPOPERATOR    Produces a unitary operator that swaps two subsystems
  2. %   This function has one required argument:
  3. %     DIM: the dimensions of the subsystems
  4. %
  5. %   S = SwapOperator(DIM) is the unitary operator that swaps two copies of
  6. %   DIM-dimensional space. If the two subsystems are not of the same
  7. %   dimension, DIM should be a 1-by-2 vector containing the dimension of
  8. %   the subsystems.
  9. %
  10. %   This function has one optional argument:
  11. %     SP (default 0)
  12. %   
  13. %   S = SwapOperator(DIM,SP) is as above, but the swap operator produced is
  14. %   sparse if SP = 1 and is full if SP = 0.
  15. %
  16. %   URL: http://www.qetlab.com/SwapOperator
  17.  
  18. %   requires: iden.m, opt_args.m, PermuteSystems.m, Swap.m
  19. %   author: Nathaniel Johnston (nathaniel@njohnston.ca)
  20. %   package: QETLAB
  21. %   last updated: November 12, 2014
  22.  
  23. function S = SwapOperator(dim,varargin)
  24.  
  25. % set optional argument defaults: sp=0
  26. [sp] = opt_args({ 0 },varargin{:});
  27.  
  28. % allow the user to enter a single number for dim
  29. if(length(dim)==1)
  30.     dim = [dim,dim];
  31. end
  32.  
  33. % swap the rows of Id appropriately
  34. S = Swap(iden(prod(dim),sp),[1,2],dim,1);