I have some high dimensional high rank tensors, let's say $$F_{ijkl}$$ and I need to find $$F^{abcd}=g^{ai}g^{bj}g^{ck}g^{dl}F_{ijkl}.$$ Here $g^{ij}$ is the contravariant metric.
Simple summation in Mathematica takes way to much time
Do[Fup[[a,b,c,d]]=Sum[F[[j,j,k,l]]g[[a,i]]g[[b,j]]g[[c,k]]g[[d,l]],{i,1,dim},{j,1,dim},{k,1,dim},{l,1,dim}],{a,1,dim},{b,1,dim},{c,1,dim},{d,1,dim}]
But I can sum over first and last index using matrix multiplication, so first I calculate $F^a{}_{ij}{}^d$ and the do summation over last two indices:
Fuddu=g.F.g; Do[F^{abcd}=Sum[Fuddu[[a,j,k,d]]g[[b,j]]g[[c,k]],{j,1,dim},{k,1,dim}],{a,1,dim},{b,1,dim},{c,1,dim},{d,1,dim}]
This way is much faster but still takes a lot of time, I need smth even faster, any ideas guys?
Edit: I cannot give you my info, but you can choose some big dim
like 10, fill square matrix g
of dimension dim
and rank-4 tensor F
of dimension dim
with some random functions/numbers:
dim=10;g=RandomReal[{0, 1}, {dim, dim}];F=RandomReal[{0, 1}, {dim, dim,dim,dim}];
dim
is not specified andFup
,g
is not initialized as an array, etc. Please add the additional information. $\endgroup$TensorContract
will be helpful to you. $\endgroup$...Sum[F[[i,j,k,l]]...
$\endgroup$