Ask Your Question
2

R_{ab} = T_{ba} and so on

asked 2022-06-05 12:54:58 +0100

solidsnake gravatar image

How can I permute indices in tensor fields on manifolds? I would like to define the following (0,4) tensor

$R_{abcd} = g_{a[c}g_{d]b}$

but I can't find an "easy" way (apart from assigning all the components bruteforce with some for loop, I guess). I presume there should be an "ovious" way of doing that but I cannot find it. Thanks.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-06-16 16:00:10 +0100

eric_g gravatar image

Permutations of indices are not implemented yet, except for special cases. For $R_{ab} = T_{ba}$, you can write something like:

R[:] = T.comp().swap_adjacent_indices(0,1,2)[:]

but this is not very handy. Here is some example:

sage: X.<x,y> = M.chart()
sage: T = M.tensor_field(0, 2, [[x, y], [x^2, y^2]])
sage: R = M.tensor_field(0, 2)
sage: R[:] = T.comp().swap_adjacent_indices(0,1,2)[:]
sage: T[:]
[  x   y]
[x^2 y^2]
sage: R[:]
[  x x^2]
[  y y^2]

For $R_{abcd} = g_{a[c}g_{d]b}$, only the tensor product and the antisymmetrization can be achieved without any loop on the components:

sage: g = M.metric('g')
sage: g[0,0], g[1,1] = 1/(1 + y^2), 1/(1 + x^2)
sage: S = (g*g).antisymmetrize(1,2)

An equivalent writing of the last line is

sage: S = (g*g)['_a[bc]d']

At this stage, one has $S_{abcd} = g_{a[b}g_{c]d}$. To get $R_{abcd} = g_{a[c}g_{d]b}$, one has to do

sage: R = M.tensor_field(0, 4, antisym=(2,3))
sage: for a in M.irange():
....:     for b in M.irange():
....:         for c in M.irange():
....:             for d in M.irange(start=c+1):
....:                 R[a,b,c,d] = S[a,c,d,b]
....:

Some check:

sage: R[0, 1, 0, 1]
1/2/((x^2 + 1)*y^2 + x^2 + 1)
sage: R[0, 1, 0, 1] == 1/2*(g[0,0]*g[1,1] - g[0,1]*g[0,1])
True
edit flag offensive delete link more

Comments

1

Thank you very much. Indeed for the permutation itself (last step) I ended up with the following snippet

def permute(l,t):
    return [l[i-1] for i in t]

p = (1,3,4,2)
for ind in M.index_generator(4):
    R[ind] = S[permute(ind, p)]

which is slightly more compact than your excellent answer.

solidsnake gravatar imagesolidsnake ( 2022-07-19 14:08:28 +0100 )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

Stats

Asked: 2022-06-05 12:54:58 +0100

Seen: 281 times

Last updated: Jun 16 '22