# IsProductOperator

 Other toolboxes required IsProductOperator Determines if an operator is an elementary tensor none IsProductVectorOperatorSchmidtDecompositionOperatorSchmidtRank Entanglement and separability

IsProductOperator is a function that determines if a bipartite or multipartite operator is an elementary tensor or not. If it is an elementary tensor, its tensor decomposition can be provided.

## Syntax

• IPO = IsProductOperator(X)
• IPO = IsProductOperator(X,DIM)
• [IPO,DEC] = IsProductOperator(X,DIM)

## Argument descriptions

### Input arguments

• X: An operator that acts on a bipartite or multipartite Hilbert space.
• DIM (optional, by default has all 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 X lives on the tensor product of two spaces, the first of which has dimension DIM and the second of which has dimension length(X)/DIM.
• If $X \in M_{n_1} \otimes \cdots \otimes M_{n_p}$ then DIM should be a row vector containing the dimensions (i.e., DIM = [n_1, ..., n_p]).
• 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 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_p; n_1, ..., n_p].

### Output arguments

• IPO: Either 1 or 0, indicating that X is or is not an elementary tensor.
• DEC (optional): If IPO = 1 (i.e., X is an elementary tensor), then DEC is a cell containing two or more operators, the tensor product of which is X. If IPO = 0 then DEC is meaningless.

## Examples

The following code verifies that the 8-by-8 identity operator (interpreted as living in 3-qubit space) is indeed a product operator:

>> [ipo,dec] = IsProductOperator(eye(8),[2,2,2])

ipo =

1

dec =

[2x2 double]    [2x2 double]    [2x2 double]

>> celldisp(dec)

dec{1} =

0.9170         0
0    0.9170

dec{2} =

-0.9170         0
0   -0.9170

dec{3} =

-1.1892         0
0   -1.1892

As we can see, the tensor decomposition that is returned is not always the "cleanest" one that exists. However, we can verify that it is indeed a valid tensor decomposition of the identity operator:

>> Tensor(dec)

ans =

1.0000         0         0         0         0         0         0         0
0    1.0000         0         0         0         0         0         0
0         0    1.0000         0         0         0         0         0
0         0         0    1.0000         0         0         0         0
0         0         0         0    1.0000         0         0         0
0         0         0         0         0    1.0000         0         0
0         0         0         0         0         0    1.0000         0
0         0         0         0         0         0         0    1.0000

## Source code

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

1. %%  ISPRODUCTOPERATOR   Determines if an operator is an elementary tensor
2. %   This function has one required argument:
3. %     X: an operator living on the tensor product of two or more subsystems
4. %
5. %   IPO = IsProductOperator(X) is either 1 or 0, indicating that X is or
6. %   is not a product operator (note that X is assumed to be bipartite
7. %   unless the optional argument DIM (see below) is specified).
8. %
9. %   This function has one optional input argument:
10. %     DIM (default has two subsystems of equal dimension)
11. %
12. %   [IPO,DEC] = IsProductOperator(X,DIM) indicates that X is or is not a
13. %   product operator, as above. DIM is a vector containing the dimensions
14. %   of the subsystems that X acts on. If IPO = 1 then DEC is a product
15. %   decomposition of X. More specifically, DEC is a cell containing
16. %   operators whose tensor product equals X.
17. %
18. %   URL: http://www.qetlab.com/IsProductOperator
19. 
20. %   requires: opt_args.m, IsProductVector.m, PermuteSystems.m,
21. %             SchmidtDecomposition.m, Swap.m
22. %
23. %   author: Nathaniel Johnston (nathaniel@njohnston.ca)
24. %   package: QETLAB
25. %   last updated: November 12, 2014
26. 
27. function [ipo,dec] = IsProductOperator(X,varargin)
28. 
29. dX = size(X);
30. sdX = round(sqrt(dX));
31. 
32. % set optional argument defaults: dim=sqrt(length(X))
33. [dim] = opt_args({ [sdX(1) sdX(1);sdX(2) sdX(2)] },varargin{:});
34. 
35. % allow the user to enter a single number for dim
36. num_sys = length(dim);
37. if(num_sys == 1)
38.     dim = [dim,dX(1)/dim];
39.     if abs(dim(2) - round(dim(2))) >= 2*dX(1)*eps
40.         error('IsProductOperator: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.');
41.     end
42.     dim(2) = round(dim(2));
43.     num_sys = 2;
44. end
45. 
46. % allow the user to enter a vector for dim if X is square
47. if(min(size(dim)) == 1)
48.     dim = dim(:)'; % force dim to be a row vector
49.     dim = [dim;dim];
50. end
51. 
52. % reshape the operator into the appropriate vector and then test if it's a product vector
53. [ipo,dec] = IsProductVector(PermuteSystems(reshape(X,prod(prod(dim)),1),Swap(1:2*num_sys,[1,2],[2,num_sys]),[dim(2,:),dim(1,:)]),prod(dim));
54. 
55. % reshape the decomposition into the proper form
56. if(ipo)
57.     dec = cellfun(@(x,y) reshape(x,y(1),y(2)),dec,mat2cell(dim,2,ones(1,num_sys)),'un',0);
58. end