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
1)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.
2)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.
3)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.
4) 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.
David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/
________________________________
From: David Park <djm...@comcast.net>
To: Sam Takoy <sam....@yahoo.com>; math...@smc.vnet.net
Sent: Sat, September 18, 2010 7:58:41 AM
Subject: RE: Contraction of Tensors in Mathematica
These are the Mathematical techniques for handling tensor arrays:
1)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.
2)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.
3)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.
4) 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.
>> Thanks again. What's a good way to ensure that the rest of the indices remain
>>in the same order. If I need to contract indices 5 and 8, I would swap 1 with 5
>>and 2 with 8 before calling Tr. This will mess up the order of indices. What I
>>need instead is bring 5 forward and shift 1 2 3 4 down one. Then bring 8 to slot
>>two and move the rest down one. I could probably do this in a painfully
>>convoluted way, but is there a more elegant way of doing this?
You may want to take a look at this thread:
http://groups.google.com/group/comp.soft-sys.math.mathematica/browse_thread/thread/7f0195213d9d50e0
<http://groups.google.com/group/comp.soft-sys.math.mathematica/browse_thread/thread/7f0195213d9d50e0>
Regards,
Leonid
> 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
d = Total @ Flatten[c, {{1,7}}]
?
Hopefully the following example will be clear enough to generalise:
In[1]:= A=Array[a,{2,2,2}]
Out[1]= {{{a[1,1,1],a[1,1,2]},{a[1,2,1],a[1,2,2]}},
{{a[2,1,1],a[2,1,2]},{a[2,2,1],a[2,2,2]}}}
In[2]:= Tr[A,Plus,2]
Out[2]= {a[1,1,1]+a[2,2,1],a[1,1,2]+a[2,2,2]}
In[3]:= Tr[Transpose[A,{1,3,2}],Plus,2]
Out[3]= {a[1,1,1]+a[2,1,2],a[1,2,1]+a[2,2,2]}
A trace to depth 2, traces over the first two indices.
Take the appropriate Transpose[] to move the indices you want to trace
to the front (leaving the rest in the same order).
Simon
"?" indeed.
As others suggested, use "Tr".
d = Tr[Flatten[c, {{1}, {7}}], Plus, 2];
Vince
xAct now has an easy to use GUI called xPrint (also free) which
dramatically speeds up your learning curve and tensor input. It can be
found at:
https://sites.google.com/site/xprintforxact/
Finally you can visit the xAct user group at:
http://groups.google.com/group/xact/topics?hl=en
With xAct you can work symbolically and "numerically" (meaning; with
components in a specific base), as in your example.