Ask Your Question

Revision history [back]

Yes there is a partial support of index notation in Sage, see the section "Tensor calculus" of the tutorial. Here is a full example to compute the tensor field $C^c_{\ \ ab}$ that you mention:

sage: M = Manifold(2, 'M')
sage: X.<u,v> = M.chart()
sage: g = M.metric('g')
sage: g[0,1] = -1/2
sage: g.display()
g = -1/2 du*dv - 1/2 dv*du
sage: Omega = M.scalar_field(2/(sqrt(1+u^2)*sqrt(1+v^2)))
sage: tg = M.metric('tg', latex_name=r'\tilde{g}')
sage: tg.set(Omega^2*g)
sage: tg.display()
tg = -2/((u^2 + 1)*v^2 + u^2 + 1) du*dv - 2/((u^2 + 1)*v^2 + u^2 + 1) dv*du
sage: tnabla = tg.connection()
sage: ig = g.inverse()
sage: tng = tnabla(g)
sage: C = 1/2*ig['^{cd}']*(tng['_{bda}'] + tng['_{adb}'] - tng['_{abd}'])
sage: C
Tensor field of type (1,2) on the 2-dimensional differentiable manifold M
sage: C.display()
u/(u^2 + 1) d/du*du*du + v/(v^2 + 1) d/du*du*dv + u/(u^2 + 1) d/dv*dv*du + v/(v^2 + 1) d/dv*dv*dv
sage: C[:]
[[[u/(u^2 + 1), v/(v^2 + 1)], [0, 0]], [[0, 0], [u/(u^2 + 1), v/(v^2 + 1)]]]
sage: C[0,0,0]
u/(u^2 + 1)

Yes there is a partial support of index notation in Sage, see the section "Tensor calculus" of the tutorial. Here is a full example to compute the tensor field $C^c_{\ \ ab}$ that you mention:

sage: M = Manifold(2, 'M')
sage: X.<u,v> = M.chart()
sage: g = M.metric('g')
sage: g[0,1] = -1/2
sage: g.display()
g = -1/2 du*dv - 1/2 dv*du
sage: Omega = M.scalar_field(2/(sqrt(1+u^2)*sqrt(1+v^2)))
sage: tg = M.metric('tg', latex_name=r'\tilde{g}')
sage: tg.set(Omega^2*g)
sage: tg.display()
tg = -2/((u^2 + 1)*v^2 + u^2 + 1) du*dv - 2/((u^2 + 1)*v^2 + u^2 + 1) dv*du
sage: tnabla = tg.connection()
sage: ig = g.inverse()
sage: tng = tnabla(g)
sage: C = 1/2*ig['^{cd}']*(tng['_{bda}'] + tng['_{adb}'] - tng['_{abd}'])
tng['_{abd}']) 
sage: C
Tensor field of type (1,2) on the 2-dimensional differentiable manifold M
sage: C.display()
u/(u^2 + 1) d/du*du*du + v/(v^2 + 1) d/du*du*dv + u/(u^2 + 1) d/dv*dv*du + v/(v^2 + 1) d/dv*dv*dv
sage: C[:]
[[[u/(u^2 + 1), v/(v^2 + 1)], [0, 0]], [[0, 0], [u/(u^2 + 1), v/(v^2 + 1)]]]
sage: C[0,0,0]
u/(u^2 + 1)

EDIT (31 May 2020): the above code requires the latest version of SageMath, i.e. 9.1. Indeed, the syntax

C = 1/2*ig['^{cd}']*(tng['_{bda}'] + tng['_{adb}'] - tng['_{abd}'])

which involves a sum of tensors in index notation, is not understood in older versions of SageMath. See the 9.1 release notes.