MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Best way to do contractions (arbitrary Tables with a Sum)?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105937] Best way to do contractions (arbitrary Tables with a Sum)?
  • From: Erik Max Francis <max at alcyone.com>
  • Date: Sun, 27 Dec 2009 02:24:22 -0500 (EST)

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.


  • Prev by Date: Re: Taylor expansion of Jacobi's elliptic functions
  • Next by Date: Re: problem with EvenQ
  • Previous by thread: Re: reverse the order of replacements in a list of rules
  • Next by thread: Re: Best way to do contractions (arbitrary Tables with a Sum)?