1 | initial version |
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