MathGroup Archive 2010

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

Search the Archive

Re: Contraction of Tensors in Mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg112537] Re: Contraction of Tensors in Mathematica
  • From: Peter Breitfeld <phbrf at t-online.de>
  • Date: Sun, 19 Sep 2010 05:37:55 -0400 (EDT)
  • References: <i727in$etb$1@smc.vnet.net>

Sam Takoy wrote:

> Hi,
>
> I this message I will suppress the covariant/contravariant nature of 
> tensors.
>
> Suppose I have two tensors A_ijkl and B_rstu (denoted by a and b in 
> Mathematica). Each tensor is presented for a 4-deep list. Now, I want to 
> form a new tensor:
>
> C_ijklrstu = A_ijkl*B_rstu
>
> and I want C to be represented by an 8-deep list. I've gathered is that 
> what I need to do is
>
> c = Outer[Times, a, b];
>
> Great!
>
> Now supposed I want to do some contraction to define a new tensor
>
> D_jklrsu = C_ijklrsiu?
>
>
> How do I do that?
>
> Many thanks in advance!
>
> Sam
>

I use the following functions, which seem to work:

This function sums over the first two indices of the tensor:
Spur12[T_]:=Tr[T,Plus,2]//Simplify

The following function adds the missing indices of the list up to the
maximal one given:
padindexlist[indices_]:=
   Join[indices,Complement[Range[Max[indices]],indices]]

the following function IndicesVorn[T,{i,j,...}] transposes the tensor so that
the index i becomes the first index, the index j the second etc.:

IndicesVorn[T_,indices_]:=
   Transpose[T,Ordering[padindexlist[indices]]]

This makes the contraction: contract[T,{i,j,m,n,...}] contracts over the
indices i and j, m and m, etc.:

contract[T_,indices_]:=
  Nest[Spur12[#]&, IndicesVorn[T,indices],Length[indices]/2]

Example with a smaller Tensor:
 T=Array[a[##]&,{2,2,2,2,2}]

 contract[T,{1,2}]

 Out={{{a[1, 1, 1, 1, 1] + a[2, 2, 1, 1, 1], 
   a[1, 1, 1, 1, 2] + a[2, 2, 1, 1, 2]}, {a[1, 1, 1, 2, 1] + 
    a[2, 2, 1, 2, 1], 
   a[1, 1, 1, 2, 2] + a[2, 2, 1, 2, 2]}}, {{a[1, 1, 2, 1, 1] + 
    a[2, 2, 2, 1, 1], 
   a[1, 1, 2, 1, 2] + a[2, 2, 2, 1, 2]}, {a[1, 1, 2, 2, 1] + 
    a[2, 2, 2, 2, 1], a[1, 1, 2, 2, 2] + a[2, 2, 2, 2, 2]}}}out

 contract[T,{1,2,4,5}]

 Out=
 {a[1, 1, 1, 1, 1] + a[1, 1, 1, 2, 2] + a[2, 2, 1, 1, 1] + a[2, 2, 1, 2, 2], 
 a[1, 1, 2, 1, 1] + a[1, 1, 2, 2, 2] + a[2, 2, 2, 1, 1] + a[2, 2, 2, 2, 2]}


Hope this helps
//Peter
-- 
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de


  • Prev by Date: Re: New Version 3 Presentations
  • Next by Date: Re: Contraction of Tensors in Mathematica
  • Previous by thread: Re: Contraction of Tensors in Mathematica
  • Next by thread: Re: Contraction of Tensors in Mathematica