So I have an operator $A_0$ whose matrix representation is given by $$A_0 = \begin{pmatrix} 0 & -i \\ -i & 0\end{pmatrix},$$ and I also have two vector states $|0\rangle$ and $|1\rangle$ represented by $$|0\rangle=\begin{pmatrix} 1 \\ 0 \end{pmatrix} \;\; \text{and} \;\; |1\rangle=\begin{pmatrix} 0 \\ 1 \end{pmatrix}.$$ I want Mathematica to calculate $(A_0 \otimes \mathbb{I})(|0\rangle \otimes |0\rangle) = -i |1\rangle \otimes |0\rangle$, where $\mathbb{I}$ is the identity operator. Writing everything in matrix notation would give us $$A_0 \otimes \mathbb{I} = \begin{pmatrix} \begin{pmatrix}0&0\\0&0\end{pmatrix} & \begin{pmatrix}-i&0\\0&-i\end{pmatrix} \\ \begin{pmatrix}-i&0\\0&-i\end{pmatrix} & \begin{pmatrix}0&0\\0&0\end{pmatrix} \end{pmatrix} \;\; \text{and} \;\; |0\rangle \otimes |0\rangle = \begin{pmatrix} \begin{pmatrix}1\\0\end{pmatrix} \\ \begin{pmatrix}0\\0\end{pmatrix} \end{pmatrix}$$ and the result would be $$\begin{pmatrix} \begin{pmatrix}0&0\\0&0\end{pmatrix} & \begin{pmatrix}-i&0\\0&-i\end{pmatrix} \\ \begin{pmatrix}-i&0\\0&-i\end{pmatrix} & \begin{pmatrix}0&0\\0&0\end{pmatrix} \end{pmatrix} \begin{pmatrix} \begin{pmatrix}1\\0\end{pmatrix} \\ \begin{pmatrix}0\\0\end{pmatrix} \end{pmatrix} = \begin{pmatrix} \begin{pmatrix}0&0\\0&0\end{pmatrix}\begin{pmatrix}1\\0\end{pmatrix} + \begin{pmatrix}-i&0\\0&-i\end{pmatrix}\begin{pmatrix}0\\0\end{pmatrix} \\ \begin{pmatrix}-i&0\\0&-i\end{pmatrix}\begin{pmatrix}1\\0\end{pmatrix} + \begin{pmatrix}0&0\\0&0\end{pmatrix}\begin{pmatrix}0\\0\end{pmatrix} \end{pmatrix}= \begin{pmatrix} \begin{pmatrix}0\\0\end{pmatrix} \\ \begin{pmatrix}-i\\0\end{pmatrix} \end{pmatrix} \;\;(*)$$ so I naturally wrote

A0 = {{0,-I},{-I,0}};
op = TensorProduct[A0,IdentityMatrix[2]];
st = TensorProduct[{1,0},{1,0}];

but the result it returns me is$$\begin{pmatrix} \begin{pmatrix}0&0\\0&0\end{pmatrix} & \begin{pmatrix}-i&0\\0&0\end{pmatrix} \\ \begin{pmatrix}-i&0\\0&0\end{pmatrix} & \begin{pmatrix}0&0\\0&0\end{pmatrix} \end{pmatrix}.$$I discovered that the problem is that Mathematica was interpreting

st = TensorProduct[{1,0},{1,0}];

as$$\begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix},$$so I changed it to

st = TensorProduct[{{1,0}},{{1,0}}];

and it returns me$$\begin{pmatrix} \begin{pmatrix}1&0\end{pmatrix} & \begin{pmatrix}0&0\end{pmatrix} \end{pmatrix},$$ which seems correct to me as Mathematica does not make any distinction between a body with single row or single column. But then I tried calculating what I need again with


and it returns me an error.

Dot:Tensors {{{{0,0},{0,0}},{{-I,0},{0,-I}}},{{{-I,0},{0,-I}},{{0,0},{0,0}}}} and {{{1,0},{0,0}}} have incompatible shapes.

So my question is what is the correct syntax for expressing the tensor and the operator such that Mathematica gives me a result of the form of the one shown in $(*)$ above?


Since you are multiplying a rank 4 tensor with a rank 2 tensor you need to specify the proper indices to contract. In this case:

A0 = {{0, -I}, {-I, 0}};
op = TensorProduct[A0, IdentityMatrix[2]];
st = TensorProduct[{1, 0}, {1, 0}];
TensorContract[TensorProduct[op, st], {{2, 5}, {4, 6}}]

Which gives the desired result

{{0, 0}, {-I, 0}}

If you want to use the Dot product you should use KroneckerProduct instead of Tensor product.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.