                /**  Tensor contraction  **/
/*A: K McIsaac*/
/*S: University of Western Australia, Nedlands 6009, Australia*/
/*D: February, 1987 */
/*K: explicit tensors; inner products; generalized traces */
 
/*: Con[$list,$ni,$nj]
        forms the contraction of the tensor $list over its
        $ni th and $nj th indices. */

Con_:Tier;
Con[$ten,$i,$j] :: \
	(%tdim : Dim[$ten];\
	%ri : %tdim[$i];\
	%tdim[$i] : ; %tdim[$j] : ; %tdim : Cat[%tdim];\
	%ten : Ar[Len[Dim[$ten]],%make[$1]];\
	%ten[$i] : %ten[$j] : $z;\
	Ap[Ar[$1,Ap['Plus,Ar[$2,Proj[$ten,$3]]]],{%tdim,%ri,%ten}])

%make[$x] :: Make["$",$x]
/*E:
#I[1]::  <XCon
 
#I[2]::  w3:Ar[{2,2,2},f]
 
#O[2]:   {{{f[1,1,1],f[1,1,2]},{f[1,2,1],f[1,2,2]}},
 
                {{f[2,1,1],f[2,1,2]},{f[2,2,1],f[2,2,2]}}}
 
#I[3]::  Con[%,1,2]
 
#O[3]:   {f[1,1,1] + f[2,2,1],f[1,1,2] + f[2,2,2]}
 
#I[4]::  Con[w3,2,3]
 
#O[4]:   {f[1,1,1] + f[1,2,2],f[2,1,1] + f[2,2,2]}
 
#I[5]::  w4:Ar[{2,2,2,2},f];
 
#I[6]::  Con[w4,2,4]
 
#O[6]:   {{f[1,1,1,1] + f[1,2,1,2],f[2,1,1,1] + f[2,2,1,2]},
 
                {f[1,1,2,1] + f[1,2,2,2],f[2,1,2,1] + f[2,2,2,2]}}
*/
 
/*QV: Inner; Outer */
