I recommend exploiting new and powerful capabilities of Mathematica 9.
When we deal with symbolic tensors sometimes we would like to assume special properties of tensors like their specific symmetries, dimensions etc. because most of tensor equations of mathematical physics (Maxwell, Yang-Mills, Einstein etc.) involve special symmetries of underlying tensors and one would substantially simplify symbolic processing if one assumed appropriate symmetries from scratch. For this purpose one may use $Assumptions
, however there were rather few questions explicitly asking about them (see e.g. How to declare a 3D vector variable? or Can Mathematica do symbolic linear algebra?).
We can define a general tensor product of tensor v
with LeviCivitaTensor[3]
:
tp[v_]:= TensorProduct[ v, LeviCivitaTensor[3]]
and also an appropriate tensor contraction of a tensor, namely we need to contract the tensor product tp
having 6
indicies in their appropriate pairs, namely {1, 4}, {2, 5}
and {3, 6}
:
tc[v_]:= TensorContract[ TensorProduct[ v, LeviCivitaTensor[3]],
{{1, 4}, {2, 5}, {3, 6}}]
when we have defined a tensor v
. e.g.:
v = RandomInteger[{-10, 10}, {3, 3, 3}]
{{{8, 4, -4}, {2, -2, 4}, {-1, 9, -8}},
{{-9, -7, 8}, {-9, -4, 5}, {-9, 2, -7}},
{{-7, 10, -4}, {-5, 9, -9}, {-4, 6, 5}}}
tc[ v, {{1, 4}, {2, 5}, {3, 6}}]
-7
Tensor contraction of a tensor product can be performed also using Inner
or in an obvious (more procedural) way, using Sum
, Part
and Times
(see e.g. How to calculate scalar curvature Ricci tensor and Christoffel symbols in Mathematica? for more extensive usage of the latter approach) :
Sum[ v[[i, j, k]] LeviCivitaTensor[3][[i, j, k]], {i, 3}, {j, 3}, {k, 3}]
-7
A bit a simpler example of tensor contraction is e.g. a trace of a matrix (an operator in appropriate basis) m
:
m = RandomInteger[{-10, 10}, {3, 3}]
{{ 9, 3, -8},
{-2, 4, -6},
{ 9, 1, -7}}
We can see that the result should be 6
. We can contract it with respect to the first and the second indicies , i.e. using { 1, 2}
as the second argument in TensorContract
or Tr
or simply computing the sum of diagonal elements:
TensorContract[ m, {1,972386138613364491061315961722 2}]+
Tr @ m423510802332512236733007952840 == TensorContract[ m, {1, 2}]
6
True 1395896940945876727794323914562