### Examples of first-order tensor manipulation¶

First we define a 4D manifold with Minkowski metric

In :
%display latex

In :
M = Manifold(4, 'M', structure='Lorentzian')
C.<t,x,y,z> = M.chart()
g = M.metric()
g[0, 0], g[1, 1], g[2, 2], g[3, 3] = 1, -1, -1, -1
g[:]

Out:

Let's perturbate this metric with a small tensor $h$, depending on a small parameter $\tau$.

In :
tau = var('tau')
h = M.tensor_field(0, 2, sym=(0,1))
h[0, 1], h[0, 2], h[0, 3] = exp(-tau*x), 2*exp(-2*tau*y), 3*exp(-3*tau*z)
g.set(g + h)
g[:]

Out:

The computation of the connection takes several seconds, and produces big expressions.

In :
nab = g.connection()
nab.display(only_nonredundant=True)

Out:

If $\tau$ is small, it can be interesting to look a this at the first order. It appears for example that it is completely independent of the coordinates.

In :
nab.set_calc_order(tau, 1, True)
nab.display(only_nonredundant=True)

Out:

It is also possible to perform the computation of the connection completely at the first order, by setting the order of $g$ instead of $\Gamma$. All derived quatities are then computed at this order.

In :
g.set_calc_order(tau, 1, True)
g[:]

Out:

The computation of the connection is much faster, and of course gives the same result.

In :
nab2 = g.connection()
nab == nab2

Out: