# Pauli

 Other toolboxes required Pauli Produces a Pauli operator none GellMannGenGellMannGenPauliPauliChannel Special states, vectors, and operators

Pauli is a function that produces the 2-by-2 Pauli X, Y, Z, or identity operator, as defined here:

$X = \begin{bmatrix}0 & 1\\ 1 & 0\end{bmatrix}, \ \ Y = \begin{bmatrix}0 & -i\\ i & 0\end{bmatrix}, \ \ Z = \begin{bmatrix}1 & 0\\ 0 & -1\end{bmatrix}, \ \ I = \begin{bmatrix}1 & 0\\ 0 & 1\end{bmatrix}.$

This function can also produce multi-qubit Pauli operators.

## Syntax

• P = Pauli(IND)
• P = Pauli(IND,SP)

## Argument descriptions

• IND: An index indicating which Pauli operator you would like to be generated. Values of 1, 2, 3, and 0 correspond to the Pauli X, Y, Z, and identity operators, respectively. Values of 'I', 'X', 'Y', and 'Z' are also accepted, and indicate the Pauli identity, X, Y, and Z operators, respectively. If IND is a vector then this function returns a multi-qubit Pauli operator whose action on the K-th qubit is the same as Pauli(IND(K)).
• SP (optional, default 1): A flag (either 1 or 0) indicating that the Pauli operator produced should or should not be sparse.

## Examples

### Single-qubit examples

>> full(Pauli('X'))

ans =

0     1
1     0

>> full(Pauli(1))

ans =

0     1
1     0

>> full(Pauli(0))

ans =

1     0
0     1

>> full(Pauli('Y'))

ans =

0.0000 + 0.0000i   0.0000 - 1.0000i
0.0000 + 1.0000i   0.0000 + 0.0000i

>> Pauli('Z',1) % sparse Pauli Z operator

ans =

(1,1)        1
(2,2)       -1

### Multi-qubit examples

>> full(Pauli('XZI')) % the three-qubit Pauli operator X \otimes Z \otimes I

ans =

0     0     0     0     1     0     0     0
0     0     0     0     0     1     0     0
0     0     0     0     0     0    -1     0
0     0     0     0     0     0     0    -1
1     0     0     0     0     0     0     0
0     1     0     0     0     0     0     0
0     0    -1     0     0     0     0     0
0     0     0    -1     0     0     0     0

>> Pauli([0,1,2]) % the three-qubit Pauli operator I \otimes X \otimes Y

ans =

(4,1)           0 + 1.0000i
(3,2)           0 - 1.0000i
(2,3)           0 + 1.0000i
(1,4)           0 - 1.0000i
(8,5)           0 + 1.0000i
(7,6)           0 - 1.0000i
(6,7)           0 + 1.0000i
(5,8)           0 - 1.0000i

## Source code

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

1. %%  PAULI    Produces a Pauli operator
2. %   This function has one required argument:
3. %     IND (an index 0,1,2,3 or 'I', 'X', 'Y', 'Z', or a vector of such indices)
4. %
5. %   P = Pauli(IND) is the 2-by-2 Pauli matrix indicated by the value of
6. %   IND. IND = 1 gives the Pauli X operator, IND = 2 gives the Pauli Y
7. %   operator, IND = 3 gives the Pauli Z operator, and IND = 0 gives the
8. %   identity operator. Alternatively, IND can be set to one of 'I', 'X',
9. %   'Y', or 'Z' to indicated the Pauli identity, X, Y, or Z operator.
10. %
11. %   IND can also be a vector, in which case the output will be a
12. %   multi-qubit Pauli operator whose action on the k-th qubit is described
13. %   by the Pauli operator specified in the k-th entry of IND.
14. %
15. %   This function has one optional argument:
16. %     SP (default 1)
17. %
18. %   P = Pauli(IND,SP) is as above, with sparsity of the output determined
19. %   by the value of SP. If SP = 0 then the output will be full, if SP = 1
20. %   then the output will be sparse.
21. %
22. %   URL: http://www.qetlab.com/Pauli
23. 
24. %   requires: opt_args.m, Pauli.m, Tensor.m
25. %   author: Nathaniel Johnston (nathaniel@njohnston.ca)
26. %   package: QETLAB
27. %   last updated: November 27, 2014
28. 
29. function p = Pauli(ind,varargin)
30. 
31. % set optional argument defaults: sp=1
32. [sp] = opt_args({ 1 },varargin{:});
33. 
34. num_qubits = length(ind);
35. 
36. % Did the user just request a one-qubit Pauli operator? OK, make it.
37. if(num_qubits == 1)
38.     if(ind(1) == 1 || strcmpi(ind,'x'))
39.         p = [0 1;1 0];
40.     elseif(ind(1) == 2 || strcmpi(ind,'y'))
41.         p = [0 -1i;1i 0];
42.     elseif(ind(1) == 3 || strcmpi(ind,'z'))
43.         p = [1 0;0 -1];
44.     else
45.         p = eye(2);
46.     end
47. 
48.     if(sp)
49.         p = sparse(p);
50.     end
51. 
52. % Did the user request a multi-qubit Pauli operator? Construct the
53. % one-qubit ones and then tensor.
54. else
55.     for j = num_qubits:-1:1
56.         p_cell{j} = Pauli(ind(j),sp);
57.     end
58.     p = Tensor(p_cell);
59. end