# Contracting with Levi-Civita (totally antisymmetric) tensor

I have an array $v_{ijk}$ which is effectively a rank-$3$ tensor with dimensions $3\times3\times3$, and I need to contract it with $e^{ijk}$, i.e. evaluate $v_{ijk} e^{ijk}$ (see Einstein convention).
Can anyone tell me how that could be done?

• Have a look at the docs. – b.gates.you.know.what Feb 26 '14 at 12:52
• @b.gatessucks Would you include more details if my answer could be improved significantly? – Artes Feb 27 '14 at 12:24

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:

tp[v_]:= TensorProduct[ v, LeviCivitaTensor]


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],
{{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[[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, 2}]
Tr @ m == TensorContract[ m, {1, 2}]

 6
True


@Artes is right, but I have to mention also that if contracting with the Levi-Civitta tensor is something you are going to do many times, it is way more computationally efficient to use the direct summation over the coordinates. Also, it is usefull to calculate the tensor once and then use it without calling the LeveCivittaTensor function:

a = RandomReal[1, {3, 3, 3}];
e = LeviCivitaTensor;

AbsoluteTiming[
Do[TensorContract[
TensorProduct[a, LeviCivitaTensor], {{1, 4}, {2, 5}, {3, 6}}], 1000];
TensorContract[
TensorProduct[a, LeviCivitaTensor], {{1, 4}, {2, 5}, {3, 6}}]]

AbsoluteTiming[
Do[TensorContract[TensorProduct[a, e], {{1, 4}, {2, 5}, {3, 6}}], 1000];
TensorContract[TensorProduct[a, e], {{1, 4}, {2, 5}, {3, 6}}]]

AbsoluteTiming[
Do[Sum[e[[i, j, k]] a[[i, j, k]], {i, 3}, {j, 3}, {k, 3}], 1000];
Sum[e[[i, j, k]] a[[i, j, k]], {i, 3}, {j, 3}, {k, 3}]]

{0.597298, 0.258979}
{0.516749, 0.258979}
{0.0624368, 0.258979}
{"ft_lang_label":"__label__en","ft_lang_prob":0.7820851,"math_prob":0.96534896,"size":3806,"snap":"2019-51-2020-05","text_gpt3_token_len":1243,"char_repetition_ratio":0.12651236,"word_repetition_ratio":0.1442623,"special_character_ratio":0.35916972,"punctuation_ratio":0.23665893,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9977818,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-01-27T08:27:45Z\",\"WARC-Record-ID\":\"<urn:uuid:b6a30ca4-d28b-436c-b514-e7ae9b9afa38>\",\"Content-Length\":\"150484\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:cff4520c-f2d8-440c-a7eb-f6b624fde42c>\",\"WARC-Concurrent-To\":\"<urn:uuid:10c5377d-190d-437a-93af-f72ddaa8cdc5>\",\"WARC-IP-Address\":\"151.101.193.69\",\"WARC-Target-URI\":\"https://mathematica.stackexchange.com/questions/42964/contracting-with-levi-civita-totally-antisymmetric-tensor?noredirect=1\",\"WARC-Payload-Digest\":\"sha1:HTL5OM4R2CBXHFCKP2HEWOMJZQXDQNL6\",\"WARC-Block-Digest\":\"sha1:LCVBPPKG43VPK3L6I7HPBMA4UQSEPB35\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-05/CC-MAIN-2020-05_segments_1579251696046.73_warc_CC-MAIN-20200127081933-20200127111933-00198.warc.gz\"}"}