{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Friedmann equations\n", "\n", "This worksheet demonstrates a few capabilities of [SageManifolds](http://sagemanifolds.obspm.fr) (version 1.0, as included in SageMath 7.5) in computations regarding cosmological spacetimes with Friedmann-Lemaître-Robertson-Walker (FLRW) metrics.\n", "\n", "Click [here](https://raw.githubusercontent.com/sagemanifolds/SageManifolds/master/Worksheets/v1.0/SM_Friedmann_equations.ipynb) to download the worksheet file (ipynb format). To run it, you must start SageMath within the Jupyter notebook, via the command sage -n jupyter" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "*NB:* a version of SageMath at least equal to 7.5 is required to run this worksheet:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "'SageMath version 7.5.1, Release Date: 2017-01-15'" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "version()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First we set up the notebook to display mathematical objects using LaTeX formatting:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "%display latex" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We declare the spacetime M as a 4-dimensional manifold:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "4-dimensional differentiable manifold M\n" ] } ], "source": [ "M = Manifold(4, 'M')\n", "print(M)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We introduce the standard FLRW coordinates, via the method chart(), the argument of which is a string expressing the coordinates names, their ranges (the default is $(-\\infty,+\\infty)$) and their LaTeX symbols:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "Chart (M, (t, r, th, ph))" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fr. = M.chart(r't r:[0,+oo) th:[0,pi]:\\theta ph:[0,2*pi):\\phi')\n", "fr" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Assuming that the speed of light c=1, let us define a few variables: Newton's constant $G$, the cosmological constant $\\Lambda$, the spatial curvature constant $k$, the scale factor $a(t)$, the fluid proper density $\\rho(t)$ and the fluid pressure $p(t)$:

" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [], "source": [ "var('G, Lambda, k', domain='real')\n", "a = M.scalar_field(function('a')(t), name='a')\n", "rho = M.scalar_field(function('rho')(t), name='rho')\n", "p = M.scalar_field(function('p')(t), name='p')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The FLRW metric is defined by its components in the manifold's default frame, i.e. the frame associated with the FLRW coordinates:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "g = -dt*dt - a(t)^2/(k*r^2 - 1) dr*dr + r^2*a(t)^2 dth*dth + r^2*a(t)^2*sin(th)^2 dph*dph" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g = M.lorentzian_metric('g')\n", "g[0,0] = -1\n", "g[1,1] = a*a/(1 - k*r^2)\n", "g[2,2] = a*a*r^2\n", "g[3,3] = a*a*(r*sin(th))^2\n", "g.display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

A matrix view of the metric components:

" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[ -1 0 0 0]\n", "[ 0 -a(t)^2/(k*r^2 - 1) 0 0]\n", "[ 0 0 r^2*a(t)^2 0]\n", "[ 0 0 0 r^2*a(t)^2*sin(th)^2]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g[:]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

The Levi-Civita connection associated with the metric is computed:

" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "Gam^t_r,r = -a(t)*d(a)/dt/(k*r^2 - 1) \n", "Gam^t_th,th = r^2*a(t)*d(a)/dt \n", "Gam^t_ph,ph = r^2*a(t)*sin(th)^2*d(a)/dt \n", "Gam^r_t,r = d(a)/dt/a(t) \n", "Gam^r_r,r = -k*r/(k*r^2 - 1) \n", "Gam^r_th,th = k*r^3 - r \n", "Gam^r_ph,ph = (k*r^3 - r)*sin(th)^2 \n", "Gam^th_t,th = d(a)/dt/a(t) \n", "Gam^th_r,th = 1/r \n", "Gam^th_ph,ph = -cos(th)*sin(th) \n", "Gam^ph_t,ph = d(a)/dt/a(t) \n", "Gam^ph_r,ph = 1/r \n", "Gam^ph_th,ph = cos(th)/sin(th) " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nabla = g.connection()\n", "g.christoffel_symbols_display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Ricci tensor:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "Ric(g) = -3*d^2(a)/dt^2/a(t) dt*dt - (2*(d(a)/dt)^2 + a(t)*d^2(a)/dt^2 + 2*k)/(k*r^2 - 1) dr*dr + (2*r^2*(d(a)/dt)^2 + r^2*a(t)*d^2(a)/dt^2 + 2*k*r^2) dth*dth + (2*r^2*(d(a)/dt)^2 + r^2*a(t)*d^2(a)/dt^2 + 2*k*r^2)*sin(th)^2 dph*dph" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Ricci = nabla.ricci()\n", "Ricci.display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Ricci scalar ($R^\\mu_{\\ \\, \\mu}$):

" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "r(g): M --> R\n", " (t, r, th, ph) |--> 6*((d(a)/dt)^2 + a(t)*d^2(a)/dt^2 + k)/a(t)^2" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Ricci_scalar = g.ricci_scalar()\n", "Ricci_scalar.display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

The fluid 4-velocity:

" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "u = d/dt" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "u = M.vector_field('u')\n", "u[0] = 1\n", "u.display()" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "-1" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g(u,u).expr()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Perfect fluid energy-momentum tensor $T$:

" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Field of symmetric bilinear forms T on the 4-dimensional differentiable manifold M\n" ] }, { "data": { "text/html": [ "" ], "text/plain": [ "T = rho(t) dt*dt - a(t)^2*p(t)/(k*r^2 - 1) dr*dr + r^2*a(t)^2*p(t) dth*dth + r^2*a(t)^2*p(t)*sin(th)^2 dph*dph" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "u_form = u.down(g) # the 1-form associated to u by metric duality\n", "T = (rho+p)*(u_form*u_form) + p*g\n", "T.set_name('T')\n", "print(T)\n", "T.display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

The trace of $T$ (we use index notation to denote the double contraction $g^{ab} T_{ab}$):

" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "M --> R\n", "(t, r, th, ph) |--> 3*p(t) - rho(t)" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Ttrace = g.inverse()['^ab']*T['_ab']\n", "Ttrace.display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Einstein equation: $R_{\\mu \\nu} - {1 \\over 2} R g_{\\mu \\nu} + \\Lambda g_{\\mu \\nu} = {8 \\pi G} T_{\\mu \\nu}$

" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "First Friedmann equation:\n", "\n" ] }, { "data": { "text/html": [ "" ], "text/plain": [ "-8*pi*G*rho(t) - Lambda + 3*diff(a(t), t)^2/a(t)^2 + 3*k/a(t)^2 == 0" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "E1 = Ricci - Ricci_scalar/2*g + Lambda*g - (8*pi*G)*T\n", "print(\"First Friedmann equation:\\n\")\n", "E1[0,0].expr().expand() == 0" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Trace-reversed version of the Einstein equation: $R_{\\mu \\nu} - \\Lambda g_{\\mu \\nu} = {8 \\pi G} \\left(T_{\\mu \\nu} - {1 \\over 2}T\\,g_{\\mu \\nu}\\right)$

" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Second Friedmann equation:\n", "\n" ] }, { "data": { "text/html": [ "" ], "text/plain": [ "-12*pi*G*p(t) - 4*pi*G*rho(t) + Lambda - 3*diff(a(t), t, t)/a(t) == 0" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "E2 = Ricci - Lambda*g - (8*pi*G)*(T - Ttrace/2*g)\n", "print(\"Second Friedmann equation:\\n\")\n", "E2[0,0].expr().expand() == 0" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "SageMath 7.5.1", "language": "", "name": "sagemath" }, "language": "python", "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.13" } }, "nbformat": 4, "nbformat_minor": 0 }