# Index notation

I am taking a course in general relativity, and I was planing to use sage for doing calculations.

I have

from sage.tensor.modules.tensor_with_indices import TensorWithIndices
M = FiniteRankFreeModule(QQ, 4, name='M')
e = M.basis('e')
a = M.tensor((2,0), name='a')
a[:] = [[2,0,1,-1], [1,0,3,2], [-1,1,0,0], [-2,1,1,-2]]
g = M.tensor((0,2), name='g')
g[:] = [[1,0,0,0], [0,1,0,0], [0,0,1,0],[0,0,0,1]]
v=M.tensor((1,0), name='v')
v[:]=[-1,2,0,-2]

I wanted to calculate $a^{^i,^j}$ Is there some way to tell Sage what is the metric, and do the index lowering automatically? I did it manually, but it's cumbersome for more complicated calculations.

A=a['^ik']*g['_jk'];A[:]

Also, I don't know how to compute $vî v_i$, since

v['^i']*g['_ij']*v['i']

does not work.

Apart from that, I would like to know if there is a way to do this kind of computations with tensor fields and index notation, including derivatives, etc.

edit retag close merge delete

Sort by » oldest newest most voted

Hi,

In the tensor calculus on free modules, the concept of metric is not implemented (yet), so you have to manipulate metrics as symmetric tensors of type (0,2) and perform the contractions explicitely, as you did. If you really want to use some metric on a differentiable manifold, I would advise you to install SageManifolds : with it, once you have defined a pseudo-Riemannian metric g, you may write a.up(g) or a.down(g) to raise or lower indices with g. SageManifolds is aimed to be fully integrated in SageMath, but for the time being, only the part regarding tensor calculus on free modules is. To use the pseudo-Riemannian part, you have to install SageManifolds in SageMath by following these instructions. Note that SageManifolds is already installed in the SageMathCloud, so you can use it directly there.

The line

from sage.tensor.modules.tensor_with_indices import TensorWithIndices

is not necessary.

You should declare g as a symmetric tensor: either by

g = M.tensor((0,2), name='g', sym=(0,1))

or by

g = M.sym_bilinear_form(name='g')

In the current setting, one cannot use index notations to perform contractions on more than two tensors, which explains why v['^i']*g['_ij']*v['^j'] does not work. You can either do it in two steps:

w = v['^i']*g['_ij']
s = w['_j']*v['^j']

or not use the index notation:

s = v.contract(g).contract(v)

or, even shorter:

s = g(v,v)

Best wishes,

Eric.

more