# PermutationOperator

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
 Other toolboxes required PermutationOperator Produces a unitary operator that permutes subsystems none PermuteSystemsSwapSwapOperatorSymmetricProjection Permutations and symmetry of subsystems

PermutationOperator is a function that returns a unitary operator that permutes two or more subsystems. The unitary can be chosen to be full or sparse.

## Syntax

• P = PermutationOperator(DIM,PERM)
• P = PermutationOperator(DIM,PERM,INV_PERM)
• P = PermutationOperator(DIM,PERM,INV_PERM,SP)

## Argument descriptions

• DIM: A specification of the dimensions of the subsystems that P will act on. DIM can be provided in one of two ways:
• If DIM is a scalar, then all subsystems are assumed to have dimension DIM.
• If the subsystems have unequal dimensions, DIM should be a vector containing their dimensions.
• PERM: a permutation vector (i.e., a permutation of the vector 1:n)
• INV_PERM (optional, default 0): If equal to 0, this argument has no effect. If equal to 1, the permutation operator permutes subsystems according to the inverse of PERM rather than PERM itself.
• SP (optional, default 0): If set equal to 1, the permutation operator is sparse. If equal to 0, the permutation operator is full.

## Examples

### The standard swap operator

The following code produces the operator that swaps two qubits (note that for simple uses like this one, it may be easier to just use the SwapOperator function):

```>> PermutationOperator(2,[2,1])

ans =

1     0     0     0
0     0     1     0
0     1     0     0
0     0     0     1```

Similarly, the following code produces a sparse operator that swaps two qutrits:

```>> PermutationOperator(3,[2,1],0,1)

ans =

(1,1)        1
(4,2)        1
(7,3)        1
(2,4)        1
(5,5)        1
(8,6)        1
(3,7)        1
(6,8)        1
(9,9)        1```

## Source code

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

1. `%%  PERMUTATIONOPERATOR    Produces a unitary operator that permutes subsystems`
2. `%   This function has two required arguments:`
3. `%     DIM: the dimensions of the subsystems to be permuted`
4. `%     PERM: a permutation vector`
5. `%`
6. `%   P = PermutationOperator(DIM,PERM) is a unitary operator that permutes`
7. `%   the order of subsystems according to the permutation vector PERM, where`
8. `%   the ith subsystem has dimension DIM(i).`
9. `%`
10. `%   This function has three optional arguments:`
11. `%     INV_PERM (default 0)`
12. `%     SP (default 0)`
13. `%   `
14. `%   P = PermutationOperator(DIM,PERM,INV_PERM,SP) is the same as above, but`
15. `%   it implements the inverse permutation of PERM if INV_PERM=1. The`
16. `%   permutation operator returned is full if SP=0 and sparse if SP=1.`
17. `%`
18. `%   URL: http://www.qetlab.com/PermutationOperator`
19. ` `
20. `%   requires: iden.m, opt_args.m, PermuteSystems.m`
21. `%   author: Nathaniel Johnston (nathaniel@njohnston.ca)`
22. `%   package: QETLAB`
23. `%   last updated: November 28, 2012`
24. ` `
25. `function P = PermutationOperator(dim,perm,varargin)`
26. ` `
27. `% set optional argument defaults: inv_perm=0, sp=0`
28. `[inv_perm, sp] = opt_args({ 0, 0 },varargin{:});`
29. ` `
30. `% allow the user to enter a single number for dim`
31. `if(length(dim)==1)`
32. `    dim = dim*ones(1,max(perm));`
33. `end`
34. ` `
35. `% swap the rows of Id appropriately`
36. `P = PermuteSystems(iden(prod(dim),sp),perm,dim,1,inv_perm);`