Checking a tensor product (Yang Baxter Equation)

I want to verify that a matrix $R$ satisfies this equation $$\left(R\otimes id\right)\left(id\otimes R\right)\left(R\otimes id\right)=\left(id\otimes R\right)\left(R\otimes id\right)\left(id\otimes R\right)$$ Are this lines correct?

R = ({{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, q}, {0, 0, q, 1 - q^2}});
id = IdentityMatrix[4];
r1 = KroneckerProduct[id, R];
r2 = KroneckerProduct[R, id];
r1.r2.r1 - r2.r1.r2 // MatrixForm


Of course the matrix R would be the one to check. The result in a positive case of course should be the zero matrix. Is the syntax correct?

• What about using TensorProduct? – Henrik Schumacher Mar 10 '18 at 8:07
• is it different? – Dac0 Mar 10 '18 at 10:22
• Doesn't work with TensorProduct – Dac0 Mar 10 '18 at 10:24
• Aha. You know that "it doesn't seem to work" is very useless problem description, do you? Moreover, this is not necessarily a problem with Mathematica but with the matrix R... – Henrik Schumacher Mar 10 '18 at 11:10
• You know, context is important... – Henrik Schumacher Mar 10 '18 at 11:21

What is you definition of the multiplication in $(A \otimes B) \cdot (C \otimes D)$? Probably it does not coincide with Mathematica's Dot. Honestly, I am not entirely sure what KroneckerProduct does with matrices and how this interacts with Dot (personally, I use KroneckerProduct solely for vector-vector pairs). So I try to boil things down to TensorProduct and TensorContract.

As can be read off from the documentation, Dot merely contracts the last slot of the first argument with the first slot of the second argument. So that would be

$$(A \otimes B) . (C \otimes D) = A \otimes (B \cdot C) \otimes D.$$

In Mathematica syntax, Dot is equivalent on pairs of 4-tensors to the following function:

dot[S_?(TensorRank[#] == 4 &), T_?(TensorRank[#] == 4 &)] :=
TensorContract[S\[TensorProduct]T, {4, 5}];


This is why $(A \otimes B) . (C \otimes D)$ is a tensor of rank 6 and not of rank 4.

I guess you think in terms of matrix algebras, so maybe you mean

$$(A \otimes B) \cdot (C \otimes D) = (A \cdot C) \otimes (B \cdot D).$$

I think the desired product can be expressed unambiguously by the following function:

newdot[S_?(TensorRank[#] == 4 &), T_?(TensorRank[#] == 4 &)] :=
TensorContract[S\[TensorProduct]T, {2, 5, 4, 7}];

• thank you, could you add also the correct syntax? – Dac0 Mar 10 '18 at 11:27
• I'm not sure I followed you until the end... I mean what is the problem if I first calculate the matrices KroneckerProduct and then I multiply them? – Dac0 Mar 10 '18 at 11:34
• Sorry about the mess with KroneckerProduct. I edited the post with hopefully correct code. – Henrik Schumacher Mar 10 '18 at 12:15