Re: Best way to do contractions (arbitrary Tables with a Sum)?
- To: mathgroup at smc.vnet.net
- Subject: [mg105967] Re: [mg105937] Best way to do contractions (arbitrary Tables with a Sum)?
- From: "David Park" <djmpark at comcast.net>
- Date: Mon, 28 Dec 2009 04:57:27 -0500 (EST)
- References: <26453615.1261900685949.JavaMail.root@n11>
The Tensorial package has facilities for converting indexed tensor expressions to Mathematica arrays. In any case, the following are some tips that we list in the "Tensors and Mathematica Arrays" tutorial. The Prime Rule for Products of 'Tensor' Arrays in Mathematica: S.T dots the lowest level of S with the highest level of T, or equivalently S.T dots the last level of S with the first level of T. The Mathematica Transpose[T,{n1,n2,n3,...}] moves levels {1,2,3,...} to levels {n1,n2,n3,...}. We will always want to move the contracted level to the first or last level when doing Dot products and to the first two levels when doing single array contractions. If R, S, T,... are Mathematica tensor arrays, then their direct product is given by Outer[Times,R,S,T,...]. This will produce a single Mathematica array. The levels are in the same order as the levels in the successive arrays. When expanding tensors to be put in Outer it is best to keep the indicies in strictly ascending sort order with the slots, or at least within each tensor. The basic Mathematica command for contraction of the top two levels in a single array T is Tr[T,Plus,2]. We will have to use Transpose on T to put the contraction slots in the first two levels. We will have to repeat the operation if we want to do multiple contractions. So essentially you have to Transpose your array to get the contracted indices into the first two levels of the array and then use Tr. David Park djmpark at comcast.net http://home.comcast.net/~djmpark/ From: Erik Max Francis [mailto:max at alcyone.com] I'm trying to do arbitrary contractions with tensors, which basically amounts to taking an (arbitrarily) large multi-dimensional array, iterating over the uncontracted indices, and then summing over the two (and only two) indices to be contracted. If I were dealing with a specific case, I'd use Table with Sum: Table[ Sum[ a[[i1]][[i2]]...[[j]]...[[j]]...[[im]]], {j, n}], {i1, n}, {i2, n}, ... {im, n}] That is, iterating over the indices i1, i2, through im (all taking on values 1 through n) and summing over two of the indices (as j). I'm trying to figure out the most elegant way to do this in Mathematica and I'm only coming up with ugly solutions which are basically arbitrary reimplementations of Table-like functionality. I figure there's probably some more elegant way to approach this. Anyone have any ideas? -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis Without love, benevolence becomes egotism. -- Dr. Martin Luther King, Jr.