I want to implement the Yang-Baxter equation (in the form of the first formula given in the link). My R-with-caron matrix (called s in the code) is not stored as a tensor with dimensions n.n.n.n, but with the upper and lower indices thrown together, i.e. (nxn).(nxn). This needs some care with indices. My code:

(*Id*) id=IdentityMatrix[n];
(*S x Id*) s1=Partition[Flatten[Transpose[Outer[Times,s,id],{1,3,2,4}]],n^3];
(*Id x S*) s2=Partition[Flatten[Transpose[Outer[Times,id,s],{1,3,2,4}]],n^3];
(*YBE*) nul=Flatten[s1.s2.s1-s2.s1.s2];

As I see it:

  • The Outer[] in line 2 creates a tensor of size (nxn).(nxn).n.n, visually:
  • enter image description here
  • But now the indices are totally in the wrong order. I thus Transpose[] them into the order 123456 again (but still with 12 and 34 grouped together). This gives a (nxn).n.(nxn).n tensor:
  • enter image description here
  • Partition[Flatten[]] now converts into a (nxnxn).(nxnxn) matrix, with all upper and all lower indices grouped together.
  • Line 4 then implements the first picture from the link.

After 20 years, I have reasons to believe I botched somewhere - can you verify I did the code, especially regarding Transpose[], correctly? (Probably it would have been cleaner to store s as a tensor and Transpose[] over six indices!)

  • 1
    $\begingroup$ When I try to evaluate this Mathematica complains that n and s are undefined. $\endgroup$ Commented May 21 at 9:43
  • 2
    $\begingroup$ It would be easier if you explained the result you want from a given input rather than couch the question inside this whole yang-baxter business. If you have a question about using Transpose, then give us a small example of a structure you have and the desired output you'd like to transform it into. $\endgroup$
    – lericr
    Commented May 21 at 14:22
  • 1
    $\begingroup$ Also, maybe what you want is ArrayFlatten rather than Partition[Flatten[...]]. $\endgroup$
    – lericr
    Commented May 21 at 14:38
  • $\begingroup$ @HenrikSchumacher: I amended with an actual example. Can't check it at the moment, license complaint. (I guess it's just a down server...) The result should be 0...unless I confused R and R-caron. $\endgroup$ Commented May 22 at 8:31

1 Answer 1


Disclaimer: I have no knowledge at all about the Yang-Baxter equations. So this is more an extended comment than an answer.

What I find very fishy about your definitions of s1 and s2 is that you reshape tensors of very different dimensions here:

Transpose[Outer[Times, s, id], {1, 3, 2, 4}] // Dimensions
Transpose[Outer[Times, id, s], {1, 3, 2, 4}] // Dimensions

{4, 2, 4, 2}

{2, 4, 2, 4}

But I cannot really tell. Also, what came to my mind is that you might want to use KroneckerProduct:

s1 = KroneckerProduct[s, id];
s2 = KroneckerProduct[id, s];
s1 . s2 . s1 - s2 . s1 . s2
  • $\begingroup$ Indeed, I also found it fishy, but it seemed to work for 20 years. :-) After overthinking the stuff anew, I guess my problem sits in confusing R and R-caron all the time, but luckily, this is only an error of mind and not of computation. In any case, THX for the suggestion. Didn't know Kronecker could be used for that...(I just read the description, the symbol alone "proves" that it works...) $\endgroup$ Commented May 22 at 12:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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