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.