Re: Best way to do contractions (arbitrary Tables with a Sum)?
- To: mathgroup at smc.vnet.net
- Subject: [mg105962] Re: Best way to do contractions (arbitrary Tables with a Sum)?
- From: "Norbert P." <bertapozar at gmail.com>
- Date: Mon, 28 Dec 2009 04:56:29 -0500 (EST)
- References: <hh72a3$kqa$1@smc.vnet.net>
On Dec 26, 11:28 pm, Erik Max Francis <m... at alcyone.com> wrote: > 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 && m... 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. Hi, not sure if this is the best way, but you don't need to use Table, use Sum[a[[All, ..., All, j, All, ..., All, j, All, ...]], {j,n}] But it is still a Table-like functionality... Norbert