Author 
Comment/Response 
Ben

03/22/12 5:34pm
Hello,
I work with tensornetworks and often have to contract two tensors. Usually they are only connected by one index and can be contracted using ‘Dot’.
But this doesn’t work if the network has loops. Consider this situation:
AC
 
BD
A, B, C and D are supposed to represent tensors. I contract A and B to some tensor E. In the next step I contract CD to tensor F. The network looks like:
E=F
E and F are connected by two indices. I can apply ‘Dot’ as well and obtain a Tensor G, but this contracts only on index. So my resulting network looks like this:
+G+
 
++
I believe this is trace[G]. In a more general case two tensors may have N equal indices. This means I have to take the trace N1 times.
I guess this should work in general, but I fear it is not very efficient and unfortunately efficiency is important in this project. I'm also not sure how to implement this in Mathematica.
Actually I'm looking for some function F[A,B,num] which returns a fully contracted tensor over all indices. num is the number of equal indices. I assume that tensor A has an index ordering like this {...,a,b,c,d,i1,i2,i3} and B {i3,i2,i1,e,f,...}, so num=3 in this case. If A is of rank k and B of rank n the resulting tensor is of rank k+n  2*num.
I'm not used to Mathematica. I would be very thankful if someone post code for F[A,B,num]. Also versions that are not the most efficient are very welcome.
Thanks a lot.
Ben
URL: , 
