Ask Your Question

Contraction of Levi-Civita Symbols

asked 2021-08-09 16:56:58 +0200

zenAmp gravatar image

I would like to calculate various contractions of the Levi-Civita symbol using SageMath. As far as i know, there is no direct implementation of the ordinary symbol, so I followed another post and just used the Euclidean space:

E = EuclideanSpace(2, start_index=0)
g = E.metric()
eps = g.volume_form()
eps_dual = g.volume_form(2)

I tested some generic contractions which all seemed to work fine, however, once I started to change the contraction order, things became odd. While

res = eps['_ij']*eps_dual['^ij']

correctly returns E^2 --> R \n (x, y) |--> 2, for

res = eps['_ij']*eps_dual['^ji']

(2nd ij swapped ) I would expect to get E^2 --> R \n (x, y) |--> -2, but sage tells me its +2 again. The same happens if I use res = eps.contract(0, 1, eps_dual, 1, 0) instead of the explicit index notation. I don't know if this is some kind of convention I'm not aware of, however

res = (eps['_ij']*eps_dual['^jk']).trace()


res = (eps['_ij']*eps_dual['^jk'])['^n_n']

works just fine. Why does it seem like Sage does not care about the order if I contract all indices at once but does if I do it one after another?

edit retag flag offensive close merge delete



Welcome to Ask Sage! Thank you for your question.

slelievre gravatar imageslelievre ( 2021-08-09 17:34:29 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2021-08-10 10:45:57 +0200

eric_g gravatar image

updated 2021-09-14 13:27:03 +0200

Thanks for your report! This is indeed a bug: the current implementation of contractions on multiple indices yield wrong results when the index positions in each of the two tensors do not have the same order and the outcome is a scalar field (when the outcome is a tensor field of nonzero valence, there is no issue). I've opened the Trac ticket #32355 for a fix.

EDIT (14 Sept. 2021): the fix proposed in #32355 has been merged in SageMath 9.5.beta1; so SageMath 9.5 will be free of this bug.

edit flag offensive delete link more


Thanks for opening the ticket. Indeed, for tensor fields it does seem to work which explains why taking the trace returns the correct result. For now, I just contract all but two indices and apply the trace in the end as workaround.

zenAmp gravatar imagezenAmp ( 2021-08-10 11:37:26 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2021-08-09 16:56:58 +0200

Seen: 208 times

Last updated: Sep 14 '21