Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
explore-for-students
GitHub Repository: explore-for-students/python-tutorials
Path: blob/main/Group exercises/Group exercise 6.ipynb
968 views
Kernel: Python 3

Exercise for Sympy and General Relativity in a (hazel)nutshell

In this exercise, we introduce the General theory of Relativity (developped by Einstein in the 1910s) that we want to use in order to understand the evolution of the Universe.

According to General Relativity (GR) gravitational field is the spacetime which is represented by the metric tensor gg. As often in physics, we will designate the tensor gg by its components gμνg_{\mu\nu}. It is a rank 2 tensor (represented by 2 indices, hence rank "2") which in 4 spacetime dimensions is just a 4×44\times4 matrix.

The reason is that the Greek indices μ,ν,α,β\mu,\nu, \alpha, \beta \ldots take values 0,1,2,30,1,2,3 in 4 dimensions.

The metric gμνg_{\mu\nu} gives the line element (the distance in spacetime between two infinitesimally close events): ds2=μ=03ν=03gμνdxμdxνgμνdxμdxν.(1) \text{d}s^2 = \sum_{\mu=0}^3 \sum_{\nu=0}^3 g_{\mu\nu}\text{d}x^\mu \text{d}x^\nu \equiv g_{\mu\nu}\text{d}x^\mu \text{d}x^\nu \, . \tag{1}

The Einstein summation convention is used for the second equality: if an index appears twice -once in subscript and once in superscript- then it is summed over all possible values (see eqs (4) and (5) below for more information).

The geometry of spacetime (specific form of the components of gμνg_{\mu\nu}) is affected by the matter content of the Universe and the configuration of the matter content is affected by the geometry of spacetime, and this cycle of action and reaction goes on and on. A famous explanation of GR is given by John A. Wheeler: "Spacetime tells matter how to move; matter tells spacetime how to curve."

Small note: In popularisation of physics (and even sometimes in textbooks) we can find representations of the effects of General Relativity in which the space is shown as a sheet that is deformed by masses. This representation is misleading and shouldn't be looked as more as a vague intuition (in fact it's even a pretty good representation of classical Newtonian gravity, do you see why?). The two main errors I see in this representation are: 1: only curvature of space is shown, while GR needs the curvature of spacetime (the time is the important feature!), and 2: this representation shows a 2D space curved in a 3rd dimension. There is no reason to think that our 4D spacetime is curved in a 5th dimension.

General Relativity states that gravity is not a force: in the presence or absence of gravity and in absence of other fundamental forces, a particle follows geodesics of the spacetime, i.e., falls freely. Since gravity (spacetime and its geometry) and matter acts on each other on and on, the fundamental equations of motion of (GR), called Einstein equations are of the form:

Geometry of the spacetime=Matter content,(2)\text{Geometry of the spacetime} = \text{Matter content} \, , \tag{2}

or in mathematical notations (in SI units): Rμν12gμνR=8πGc4Tμν.(3)R_{\mu\nu} - \frac{1}{2}g_{\mu\nu}R =\frac{8\pi G}{c^4} T_{\mu\nu} \, . \tag{3}

On the right-hand side of this equation we find the stress-energy tensor TμνT_{\mu\nu} multiplied by a constant κ=8πG/c4\kappa = 8 \pi G /c^4 which is a dimensional constant made up of the speed of light cc and the Newton constant GG (sometimes κ\kappa is called the Einstein constant). The stress-energy tensor is another rank 2 tensor (or 4×44 \times 4 matrix in 4 dimensions) that describes matter content of the universe. It depends on the properties and the behavior of the matter, particularly its energy density, pressure and shear (see Fig. 1).

stress-energy_tensor.png ParseError: KaTeX parse error: \tag works only in display equations Illustration of the stress-energy tensor TμνT^{\mu\nu} in General Relativity. Taken from Wikimedia.

On the left-hand side of eq. (3) we have the metric tensor gμνg_{\mu\nu}, the Ricci tensor RμνR_{\mu\nu} and the Ricci scalar RR. But in fact everything on the left hand side is computed from the metric tensor gμνg_{\mu\nu} itself, i.e. Rμν[gμν]R_{\mu\nu}[g_{\mu\nu}]. From a certain combination of first derivatives of the metric we obtain the Christoffel symbols Γμνρ\Gamma^\rho_{\mu\nu}. A certain combination of first derivatives of Christoffel symbols yields to the most important object in GR after the metric tensor itself, namely the Riemann tensor which has 4 indices RαβμνR_{\alpha\beta\mu\nu}. The Riemann tensor describes the curvature of spacetime (or equivalently the curvature of the metric tensor). From this tensor one can construct the Ricci tensor RμνR_{\mu\nu} and then the Ricci scalar RR, which is the trace of the Ricci tensor: RRμμR \equiv R^\mu_\mu. See exercise below for more details.

The Christoffel sympbols Γμνρ\Gamma^\rho_{\mu\nu} can be thought of 4 matrices (corresponding to ρ\rho taking values 0,1,2,30,1,2,3) each being a 4×44\times4 matrix (corresponding to μ,ν\mu,\nu taking values 0,1,2,30,1,2,3). Note that Christoffel symbols are not tensors, hence called "symbols".

The Einstein's equation, eq. (3), then expands to 16 highly non-linear differential equations.

Since Greek indices μ,ν,\mu,\nu,\ldots take values 0,1,2,30,1,2,3 in 4 dimensions, RμνR_{\mu\nu} can be seen as a 4×44\times4 matrix, namely it has 16 components although not all of them are independent. The same goes for the metric tensor gμνg_{\mu\nu} and the stress-energy tensor TμνT_{\mu\nu}. The reason that these Greek indices take values 0,1,2,30,1,2,3 is that they refer to the coordinates used to describe spacetime: 00 corresponds to the time coordinate usually denoted by tt, and 1,2,31,2,3 refer to spatial dimensions which in Cartesian coordinates correspond to x,y,zx,y,z. Hence, in Cartesian cooridnates {xμ}\{x^\mu\} we have x0=t,x1=x,x2=y,x3=zx^0=t,\,x^1=x,\,x^2=y,\,x^3=z. If we want to just refer to the spatial part, we usually use Latin indices a,b,c,a,b,c,\ldots, for example, in Cartesian coordinates the spatial part is denoted by {xa}\{x^a\} where a=1,2,3a=1,2,3 and x1=x,x2=y,x3=zx^1=x,\,x^2=y,\,x^3=z.

A bit more about tensors

In order to compute various tensors from the metric tensor we need to learn a few concepts. The most elementary is the Einstein's summation notation (that we have already used in eq. (1)): when in a mathematical formula two objects have the same indices, one up and one down, this means summation over that index over the range of its values. For example

TμUμ=μ=03TμUμ=T0U0+T1U1+T2U2+T3U3.(4)T^{\mu}U_{\mu}=\sum_{\mu=0}^{3}T^{\mu}U_{\mu}=T^{0}U_{0}+T^{1}U_{1}+T^{2}U_{2}+T^{3}U_{3} \, . \tag{4}

A more complicated expression is, for example,

TμαUμν=μ=03TμαUμν=T0αU0ν+T1αU1ν+T2αU2ν+T3αU3ν.(5)T^{\mu}{}_{\alpha}U_{\mu\nu}=\sum_{\mu=0}^{3}T^{\mu}{}_{\alpha}U_{\mu\nu}=T^{0}{}_{\alpha}U_{0\nu}+T^{1}{}_{\alpha}U_{1\nu}+T^{2}{}_{\alpha}U_{2\nu}+T^{3}{}_{\alpha}U_{3\nu}\, . \tag{5}

Special attention must be given to where the indices are up or down. Down indices (eg: gμνg_{\mu\nu}) represent (0,n)(0, n) tensors, where nn is the number of indices, while up indices (eg: UμU^\mu) represent (m,0)(m, 0) tensors, where mm is the number of indices. Only for the metric tensor gμνg_{\mu\nu}, its inverse is given by gμνg^{\mu\nu} such that gμνgνρ=δρμg^{\mu\nu}g_{\nu\rho} = \delta^\mu_\rho where δρμ\delta^\mu_\rho is the Kronecker delta. Using this, one can raise and lower the indices of any tensor. For example, if TμνT_{\mu\nu} is a tensor then Tνμ=gμρTρνT^\mu_\nu = g^{\mu\rho}T_{\rho\nu} and Tμν=gμρgνσTρσT^{\mu\nu} = g^{\mu\rho}g^{\nu\sigma}T_{\rho\sigma}.

The following exercises will consist in the computation of the Einstein tensor GμνG_{\mu\nu} step by step for a given metric, and then in computing the Einstein's equations, eq. (3) for this given metric.

from sympy import * init_printing() from sympy.vector import CoordSys3D from sympy.tensor.tensor import TensorIndexType import sympy as sp

Friedmann-Lemaître-Robertson-Walker metric

One of the most important application of General Relativity is Cosmology. Cosmology is the study of the Universe as a physical object, and its theory follows direclty from GR. Our Universe seems to be described by the Friedmann-Lemaître-Robertson-Walker (FLRW) metric, that can be written in the case of a spatially flat universe and in Cartesian coordinates as:

gμνFLRW(t)=(10000a2(t)0000a2(t)0000a2(t)),(6)g_{\mu\nu}^{\text{FLRW}}(t)= \left ( \begin{matrix} 1 & 0 & 0 & 0 \\ 0 & -a^2(t) & 0 & 0 \\ 0 & 0 & -a^2(t) & 0 \\ 0 & 0 & 0 & -a^2(t) \end{matrix} \right ) \, , \tag{6}

i.e. g00=1g_{00} = 1 and gij=a2(t)δijg_{ij} = -a^2 (t) \, \delta_{ij} (so g11=g22=g33=a2(t)g_{11} = g_{22} = g_{33} = -a^2(t) and all the other terms are 0). a(t)a(t) is a function of the time tt only and is called the scale factor. Hence the metric only depends on the time tt.

Christoffel Symbols

Mathematically the Christoffel symbols, Γμνρ\Gamma^\rho_{\mu\nu}, are defined as:

Γμνρ=12gργ(gγνxμ+gγμxνgμνxγ).(7)\Gamma^\rho_{\mu\nu} = \frac{1}{2}g^{\rho \gamma}\left( \frac{\partial g_{\gamma \nu} }{\partial x^\mu} + \frac{\partial g_{\gamma \mu} }{\partial x^\nu} - \frac{\partial g_{\mu \nu} }{\partial x^\gamma} \right) \, . \tag{7}

Important notes:

  1. Despite their notation, the Christoffel symbols are not the components of a tensor!

  2. The Christoffel symbols are symmetric under permutation of the lower indices: Γμνρ=Γνμρ. \Gamma^\rho_{\mu\nu} = \Gamma^\rho_{\nu\mu} \, .

Exercise 1:

Compute the Christoffel symbols Γμνρ\Gamma^\rho_{\mu\nu} for the Friedmann-Lemaître-Robertson-Walker metric gμνFLRWg_{\mu\nu}^\text{FLRW}, eq. (6):

Γμνρ=12gFLRWργ(gγνFLRWxμ+gγμFLRWxνgμνFLRWxγ).(8)\Gamma^\rho_{\mu\nu} = \frac{1}{2}g^{\rho \gamma}_\text{FLRW}\left( \frac{\partial g_{\gamma \nu}^\text{FLRW}}{\partial x^\mu} + \frac{\partial g_{\gamma \mu}^\text{FLRW} }{\partial x^\nu} - \frac{\partial g_{\mu \nu}^\text{FLRW} }{\partial x^\gamma} \right). \tag{8}
# your answer to exercise 1 here:

You should find that the non-zero terms of the Christoffel symbols are:

Γij0=a˙(t)a(t)δij,(9)\Gamma^0_{ij}=\dot{a}(t)a(t)\delta_{ij} \, , \tag{9}Γj0i=a˙(t)a(t)δji,(10)\Gamma^i_{j0}=\frac{\dot{a}(t)}{a(t)}\delta^i_j \, , \tag{10}

or are related to them by symmetry (remember that Γμνρ=Γνμρ \Gamma^\rho_{\mu\nu} = \Gamma^\rho_{\nu\mu}). We introduced a˙=a/t\dot{a} = \partial a / \partial t.

Riemann tensor

The Riemann tensor is a rank 4 tensor RαβγδR_{\alpha\beta\gamma\delta} that depends only on the metric gμνg_{\mu\nu} and can be computed from the Christoffel symbols you obtained in exercise 1 and their derivatives:

Rμσνρ=ΓνμρxσΓσμρxν+ΓσλρΓνμλΓνλρΓσμλ.(11)R^{\rho}_{\mu\sigma\nu} = \frac{\partial \Gamma^\rho_{\nu\mu}}{\partial x^\sigma} - \frac{\partial \Gamma^\rho_{\sigma\mu}}{\partial x^\nu} + \Gamma^\rho_{\sigma\lambda} \, \Gamma^\lambda_{\nu\mu} - \Gamma^\rho_{\nu\lambda} \, \Gamma^\lambda_{\sigma\mu} \, . \tag{11}

Exercise 2:

Compute the Riemann tensor of the Friedmann-Lemaître-Robertson-Walker metric, using the Christoffel symbols you obtained in the exercice 1.

# your answer to exercise 2 here:

Ricci tensor

The Ricci tensor RμνR_{\mu\nu} is a contraction of the Riemann tensor RμσνρR^\rho_{\mu\sigma\nu}:

RμνRμανα.(12)R_{\mu\nu} \equiv R^\alpha_{\mu\alpha\nu} \, . \tag{12}

Of course since the Ricci tensor is a particular case of the Riemann tensor, we can also compute it directly from the Christoffel symbols and their derivatives, as in eq. (11): Rμν=αΓμνανΓμαα+ΓαλαΓμνλΓνλαΓμαλ.(13) R_{\mu\nu}=\partial_\alpha\Gamma^\alpha_{\mu\nu}-\partial_\nu\Gamma^\alpha_{\mu\alpha}+\Gamma^\alpha_{\alpha\lambda}\, \Gamma^\lambda_{\mu\nu}-\Gamma^\alpha_{\nu\lambda}\, \Gamma^\lambda_{\mu\alpha} \, . \tag{13}

The Ricci tensor appears in the left-hand side of the Einstein's equations, eq. (3)!

Exercise 3:

Compute the Ricci tensor of the Friedmann-Lemaître-Robertson-Walker metric, using the Riemann tensor you obtained in the exercise 2.

# your answer to exercise 3 here:

You should find that for the FLRW metric the non-zero components of the Ricci tensor are: R00=3a¨a,(14) R_{00} = -3 \frac{\ddot{a}}{a} \, , \tag{14}

Rij=(a¨a+2a˙2)δij,(15)R_{ij} = \left ( \ddot{a}a + 2\dot{a}^2 \right ) \delta_{ij} \, , \tag{15}

where a¨=2a/t2\ddot{a} = \partial^2 a / \partial t^2.

Ricci scalar

The Ricci scalar RR is defined as the contraction (the trace) of the Ricci tensor:

R=Rνν=gνμRμν.(16)R=R^\nu_\nu=g^{\nu\mu}R_{\mu\nu} \, . \tag{16}

Exercise 4:

Compute the Ricci scalar for the FLRW metric.

# your answer to exercise 4 here:

The Ricci scalar for the FLRW metric is:

R=6[a¨a+(a˙a)2].(17)R = -6 \left [ \frac{\ddot{a}}{a} + \left ( \frac{\dot{a}}{a} \right )^2 \right ] \, . \tag{17}

Einstein tensor

The Einstein tensor GμνG_{\mu\nu} (i.e. the left-hand side of the Einstein's equations, eq. (3)) is defined by:

GμνRμν12gμνR.(18)G_{\mu\nu}\equiv R_{\mu\nu} - \frac{1}{2}g_{\mu\nu}R \, . \tag{18}

Exercise 5:

Compute G00G^0_0\,, Gi0G^0_i and GjiG^i_j from Gνμ=gμλGλνG^\mu_\nu = g^{\mu \lambda}G_{\lambda\nu} for the FLRW metric.

# your answer to exercise 5 here:

You should find:

G00=3(a˙a)2,(19)G^0_0 = 3 \left ( \frac{\dot{a}}{a} \right )^2 \, , \tag{19}Gi0=0,(20)G^0_i = 0 \, , \tag{20}Gji=[2a¨a+(a˙a)2]δji.(21)G^i_j = \left [ 2 \frac{\ddot{a}}{a} + \left ( \frac{\dot{a}}{a} \right )^2 \right ] \, \delta^i_j \, . \tag{21}

We then have all the components of the Einstein tensor, together with the stress-energy tensor, we can use the Einstein’s equations!

Perfect fluid stress-energy tensor

Now that we have the left-hand side of the Einstein's equations, eq. (3), we need to describe the mass-energy content of the Universe (i.e. the left-hand side of the equations). At first order we can assume that in average, matter in the Universe behaves as a perfect fluid. The stress-energy tensor of a perfect fluid in the rest frame is very easy and is given by (for c=1c=1):

Tνμ=(ρ0000P0000P0000P),(22)T^\mu_{\nu}=\left(\begin{array}{rrr} \rho & 0 & 0 & 0 \\ 0 & -P & 0 & 0 \\ 0 & 0 & -P & 0 \\ 0 & 0 & 0 & -P \\ \end{array}\right) \, , \tag{22}

or equivalently T00=ρT^0_0 = \rho and Tji=PδjiT^i_j = -P \, \delta^i_j, where ρ\rho is the density of the fluid and PP is its pressure. We can see by looking at Fig. 1 that a perfect fluid stress-energy tensor is obtained by having only diagonal terms.

Exercise 6:

Compute the Einstein's equations for c=1c=1:

Gνμ=8πGTνμ.(23)G^\mu_{\nu} = 8\pi G \, T^\mu_{\nu} \, . \tag{23}

Hint: We have seen in exercise 5 and in equation (22) that both GνμG^\mu_\nu and TνμT^\mu_\nu have only 4 non-zeros components with the spatial components being all the same. Hence the 16 Einstein's equations give only two non trivial equations in the case of a Friedmann-Lemaître-Robertson-Walker metric: G00=8πGT00,(24) G^0_0 = 8\pi G \, T^0_0 \, , \tag{24} and Gji=8πGTji,wheni=j.(25) G^i_j = 8\pi G \, T^i_j \, , \quad \text{when} \, i=j \, . \tag{25}

You may use a pen and a paper to do that exercise.

# your answer to exercise 6 here:

You should find two equations:

(a˙a)2=8πG3ρ,(26)\left ( \frac{\dot{a}}{a} \right )^2 = \frac{8 \pi G}{3} \rho \, , \tag{26}

and

a¨a=4πG3(3P+ρ).(27)\frac{\ddot{a}}{a} = -\frac{4 \pi G}{3} \left ( 3P + \rho \right ) \, . \tag{27}

Equations (26) and (27) are known as the Friedmann equations: (eq. (26)) is sometimes called the first Friedmann equation or the velocity equation [it gives a˙\dot{a}], while eq. (27) is sometimes called the second Friedmann equation or the acceleration equation [it gives a¨\ddot{a}]).

The Friedmann equations are the two fundamental equations of cosmology: they describe the evolution of the universe!

Bonus part.

Exercises 7 and 8 are given as a bonus.

In order to understand better the Friedmann equations, eqs (26) and (27), let's see what happens to the scale factor a(t)a(t) for different universes filled by different types of matter.

De Sitter universe

Let's first suppose that the only energy component of a given flat universe is a vacuum energy with the following equation of state:

P=ρ=const.(28)P = - \rho = \text{const.} \tag{28}

Such a universe is called a de Sitter universe (of short "dS universe"). The de Sitter universe seems to be a good approximation for the asymptotic past and future of our universe (we are yet in the dark-energy-dominated era of the universe).

Exercise 7:

From the first Friedmann equation (eq. (26)) find a(t)a(t) of a flat de Sitter universe and plot its evolution as a function of tt.

# your answer to exercise 7 here:

Dust universe

Let's now suppose that a universe is full of "dust", i.e. classical non-relativistic matter. The equation of state of such a matter component is:

P=0.(29)P = 0 \, . \tag{29}

One can show that such an equation of state implies:

ρ=ρ0a3.(30)\rho = \rho_0 a^{-3} \, . \tag{30}

Exercise 8:

From eq. (30) and from the first Friedmann equation, eq. (26), find a(t)a(t) for a flat universe filled of dust and plot its evolution as a function of tt.

# your answer to exercise 8 here: