1 | initial version |

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.

A few remarks about your code:

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.

2 | No.2 Revision |

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.

A few remarks about your code:

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.

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.