Skip to main content
added 262 characters in body
Source Link

You can use the second syntax of Transpose and it should work like the code below, but it is yet to be checked whether each 4-length List as the second argument of Transpose exactly corresponds to your order of indexes or not

n = {a, b};
id4 = TensorProduct[IdentityMatrix[2], n, n];
mat = TensorProduct[n, n, n, n] - (id4 + Transpose[id4, {1, 3, 2, 4}] + 
     Transpose[id4, {1, 4, 3, 2}] + Transpose[id4, {3, 1, 4, 2}] + 
     Transpose[id4, {3, 1, 2, 4}] + Transpose[id4, {3, 4, 1, 2}])/6

Update

As @WReach mentioned in the comment, two groups of indices above should indeed be corrected as below:

{3, 1, 4, 2} -> {2, 4, 1, 3}
{3, 1, 2, 4} -> {2, 3, 1, 4}

Though, the spirit of using Transpose is uninfluenced all the way.

You can use the second syntax of Transpose and it should work like the code below, but it is yet to be checked whether each 4-length List as the second argument of Transpose exactly corresponds to your order of indexes or not

n = {a, b};
id4 = TensorProduct[IdentityMatrix[2], n, n];
mat = TensorProduct[n, n, n, n] - (id4 + Transpose[id4, {1, 3, 2, 4}] + 
     Transpose[id4, {1, 4, 3, 2}] + Transpose[id4, {3, 1, 4, 2}] + 
     Transpose[id4, {3, 1, 2, 4}] + Transpose[id4, {3, 4, 1, 2}])/6

You can use the second syntax of Transpose and it should work like the code below, but it is yet to be checked whether each 4-length List as the second argument of Transpose exactly corresponds to your order of indexes or not

n = {a, b};
id4 = TensorProduct[IdentityMatrix[2], n, n];
mat = TensorProduct[n, n, n, n] - (id4 + Transpose[id4, {1, 3, 2, 4}] + 
     Transpose[id4, {1, 4, 3, 2}] + Transpose[id4, {3, 1, 4, 2}] + 
     Transpose[id4, {3, 1, 2, 4}] + Transpose[id4, {3, 4, 1, 2}])/6

Update

As @WReach mentioned in the comment, two groups of indices above should indeed be corrected as below:

{3, 1, 4, 2} -> {2, 4, 1, 3}
{3, 1, 2, 4} -> {2, 3, 1, 4}

Though, the spirit of using Transpose is uninfluenced all the way.

added 52 characters in body
Source Link

You can use the second syntax of Transpose and it should work like the code below, but I am not sure for theit is yet to be checked whether each 4-length List as the second argument of Transpose exactly corresponds to your order of indexes or not

n = {a, b};
id = IdentityMatrix[2]; id4 = TensorProduct[idTensorProduct[IdentityMatrix[2], n, n];
mat = TensorProduct[n, n, n, n] - (id4 + Transpose[id4, {1, 3, 2, 4}] + 
     Transpose[id4, {1, 4, 3, 2}] + Transpose[id4, {3, 1, 4, 2}] + 
     Transpose[id4, {3, 1, 2, 4}] + Transpose[id4, {3, 4, 1, 2}])/6

You can use the second syntax of Transpose and it should work like the code below, but I am not sure for the each 4-length List as the second argument of Transpose

n = {a, b};
id = IdentityMatrix[2]; id4 = TensorProduct[id, n, n];
mat = TensorProduct[n, n, n, n] - (id4 + Transpose[id4, {1, 3, 2, 4}] + 
     Transpose[id4, {1, 4, 3, 2}] + Transpose[id4, {3, 1, 4, 2}] + 
     Transpose[id4, {3, 1, 2, 4}] + Transpose[id4, {3, 4, 1, 2}])/6

You can use the second syntax of Transpose and it should work like the code below, but it is yet to be checked whether each 4-length List as the second argument of Transpose exactly corresponds to your order of indexes or not

n = {a, b};
id4 = TensorProduct[IdentityMatrix[2], n, n];
mat = TensorProduct[n, n, n, n] - (id4 + Transpose[id4, {1, 3, 2, 4}] + 
     Transpose[id4, {1, 4, 3, 2}] + Transpose[id4, {3, 1, 4, 2}] + 
     Transpose[id4, {3, 1, 2, 4}] + Transpose[id4, {3, 4, 1, 2}])/6
Source Link

You can use the second syntax of Transpose and it should work like the code below, but I am not sure for the each 4-length List as the second argument of Transpose

n = {a, b};
id = IdentityMatrix[2]; id4 = TensorProduct[id, n, n];
mat = TensorProduct[n, n, n, n] - (id4 + Transpose[id4, {1, 3, 2, 4}] + 
     Transpose[id4, {1, 4, 3, 2}] + Transpose[id4, {3, 1, 4, 2}] + 
     Transpose[id4, {3, 1, 2, 4}] + Transpose[id4, {3, 4, 1, 2}])/6