# Calculate dot product of two tensor products in mathematica as tensorproduct

I would like to calculate

$$(\mathbb{1} \otimes \mathbb{1} \otimes \sigma^+)(\mathbb{1} \otimes \mathbb{1} \otimes \sigma^-) = (\mathbb{1} \otimes \mathbb{1} \otimes \left( \begin{array} \\ 1 &0 \\ 0 &0\\ \end{array} \right) )$$

The code I have been using is

splus = {{0, 1}, {0, 0}};
sminus = Transpose[splus];
KroneckerProduct[IdentityMatrix, IdentityMatrix, splus].KroneckerProduct[IdentityMatrix, IdentityMatrix,  sminus]


However this does not give me a tensorproduct of the 3 tensors.

Edit I want that that the result is again in the compact format as the right-hand-side of the equation and not the expanded form in one large matrix. And i am also not able to rewrite the form of the left-hand-side, because i have a more complicated example where this is not easily possible.

Edit 2 This is the result i get from Soner's answer. What he writes is his output is the output i want, yet when i run his code i get this different output. • From the first impression Your task is to conduct the .-product. Your identity contains plenty of unity matrices from 2x2-matrix space. I accept Your definition of the sigma+/- matrices and Dot is Your operation: [reference.wolfram.com/language/ref/Dot.html] Mar 20 '20 at 21:16

An easy way is to use build-in symbol CircleTimes. We define that dot product is distributed over tensor product:

ClearAll[CircleTimes];
CircleTimes /: (a1_\[CircleTimes] b1_ \[CircleTimes] c1_ ).(a2_ \[CircleTimes] b2_ \[CircleTimes] c2_ ) := a1.a2 \[CircleTimes] b1.b2 \[CircleTimes] c1.c2 ;


Now, if we define our elements as

id = IdentityMatrix;
splus = {{0, 1}, {0, 0}};
sminus = Transpose[splus];


we get what OP wants:

CircleTimes[id, id, splus].CircleTimes[id, id, sminus]
(* {{1, 0}, {0, 1}}\[CircleTimes]{{1, 0}, {0, 1}}\[CircleTimes]{{1, 0}, {0, 0}} *)

• thanks. what you write as a comment is the output i want, yet when i run your code i get a different result. I made an edit to the orginal post to show you what output i get from your code, because i cannot post a picture to the comment section i think. Mar 21 '20 at 13:48
• @Franzi I edited the reply, there was a typo: \[CircleTimes] between a2_ and b2_ were written as [CircleTimes]. Mar 22 '20 at 6:45

Use assumptions with TensorExpand[]:

Assuming[(id | sp) ∈ Matrices[{2, 2}],
TensorExpand[KroneckerProduct[id, id, sp].KroneckerProduct[id, id, Transpose[sp]]]]
(* KroneckerProduct[MatrixPower[id, 2], MatrixPower[id, 2], sp.Transpose[sp, {2, 1}]] *)

% /. {MatrixPower[id, 2] -> id, sp -> {{0, 1}, {0, 0}}}
(* KroneckerProduct[id, id, {{1, 0}, {0, 0}}] *)


It's a little unclear what you're asking for, but I think what you want is not easy to achieve in any system. First, let me note that KroneckerProduct is correctly computing what you want:

splus = {{0, 1}, {0, 0}};
sminus = Transpose[splus];
id = IdentityMatrix;
KroneckerProduct[id, id, splus].KroneckerProduct[id, id, sminus] ==
KroneckerProduct[id, id, {{1, 0}, {0, 0}}]
(* True *)


Now, you make claim the output isn't what you want, but you want it to look like the RHS of your formula. So I guess you want the literal output TensorProduct[id, id, {{1,0},{0,0}}]. Well, this mixture of explicit and symbolic results its really hard to get to in any system, since it can't read your mind about which symbols to keep and which to expand out. Also, notice that id is not a symbolic representation of the identity matrix but rather an expliict matrix:

id (* aka IdentityMatrix *)
(* {{1, 0}, {0, 1}} *)


If you want manipulate matrices symbolically, you should use the assumptions mechanism and TensorReduce or TensorExpand. In this case, TensorExpand gives us a useful representation of your LHS. For any two $$2\times2$$ matrices id2 and sp we have:

Assuming[
{(id2 | sp) \[Element] Matrices[{2, 2}]},
TensorExpand[KroneckerProduct[id2, id2, sp].KroneckerProduct[id2, id2, Transpose[sp]]]
]
(* KroneckerProduct[MatrixPower[id2, 2], MatrixPower[id2, 2], sp.Transpose[sp, {2, 1}]] *)


(The Transpose[sp,{2,1}] is just an explicit form of Transpose, saying you are transposing the first two levels of the array. Obviously, for a matrix those are the only levels.) Since we know that id2 squares to itself and that sp . Transpose[sp] == {{1,0},{0,0}}, we can substitute those in:

% /. { MatrixPower[id2, 2] -> id2, sp.Transpose[sp, {2, 1}] -> {{1, 0}, {0, 0}}}
(* KroneckerProduct[id2, id2, {{1, 0}, {0, 0}}]*)


So getting the answer is semi-automatic, which is typically necessary for mixed symbolic/explicit results. I hope this helps.

You need to massage the ordering of the indices to make this calculation work. In general, if we have six $$2\times2$$ matrices

a = RandomInteger[{-10, 10}, {2, 2}];
b = RandomInteger[{-10, 10}, {2, 2}];
c = RandomInteger[{-10, 10}, {2, 2}];
d = RandomInteger[{-10, 10}, {2, 2}];
e = RandomInteger[{-10, 10}, {2, 2}];
f = RandomInteger[{-10, 10}, {2, 2}];


you can tensor-multiply them in two ways to get to your result:

(1) dot-products component-wise:

X = TensorProduct[a.d, b.e, c.f];


(2) tensor products and tensor contractions:

abc = TensorProduct[a, b, c];
def = TensorProduct[d, e, f];
X == Transpose[TensorContract[TensorProduct[abc, def],
{{2, 7}, {4, 9}, {6, 11}}],
{1, 3, 5, 2, 4, 6}]
(*    True    *)


a = IdentityMatrix;