# Use of ctensor for calculating the affine connection and the curvature of a metric

## Introduction and general instructions:

Sources for reading about Maxima: see the Help menu!
https://wxmaxima-developers.github.io/wxmaxima/help.html
https://maxima.sourceforge.io/documentation.html
https://maxima.sourceforge.io/docs/manual/maxima_toc.html
file:///usr/share/doc/wxmaxima/wxmaxima.html#Introduction

Introductory videos by the instructor (in Greek):
https://youtu.be/RmF_MECumyI
https://youtu.be/kvtrETJotx8

Typing special characters:
[Esc] <char> 
char     result
L         Λ
ee        ⅇ          p           π     ii        ⅈ  (imaginary i)
inf       ∞          hb          ℏ     in        ∈
partial ∂          integral ∫       
^2        ²           ^3         ³        
sq        √         impl       ⇒    equiv     ⇔
=>        ⇒        <=>       ⇔


Ctrl+Tab or Ctrl+Shift  triggers the auto-completion mechanism.
Ctrl+Shift+Delete       deletes a complete cell.

.mac files read with e.g. read("test.mac");

## ctensor package

Documentation:   https://maxima.sourceforge.io/docs/manual/maxima_126.html#ctensor

Read also: arXiv:cs/0503073, Viktor Toth, Tensor Manipulation with GPL Maxima       https://arxiv.org/abs/cs/0503073

Tensors: (not all, see documentation)
lg    [i,j]                     g_{i j}
ug   [i,j]                     g^{i j}
mcs[i,j,k]                   Γ^k_{i j}      = (1/2) g^{k m} ( ∂_i g_{j m} + ∂_ j g_{i m} - ∂_m g_{i j})
riem[i,j,k,m]             -R^m_{i j k} = -[ ∂_j Γ^m_{k i} - ∂_k Γ^m_{j i} + Γ^m_{j n} Γ^n_{ki} - Γ^m_{k n} Γ^n_{ji} ]   (Carroll convention for R^m_{i j k})
lriem[i,j,k,m]            -R_{m i j k}
ric   [i j]                      R_{i j}
lein [i,j]                      G_{i j}
geod[i]                       Geodesic equations

Variables:
dim                            dimension of space
gdet                           determinant of metric
ct_coords[ ]              list of coordinates, e.g. ct_coords[theta,phi]

Functions:
load("ctensor")         loads the session
csetup()                     interactive initialization of the package
cmetric()                    computes inverse metric, gdet,  after metric has been defined
ct_coordsys(coord): sets a predifined coordinate system, e.g.  coord= exteriorschwarzschild, interiorschwarzschild, kerr_newman
christoff(mcs)            compute and display mcs[i,j,k] = Γ^k_{i j}
riemann(true)            compute and display riem[i,j,k,m] =  -R^m_{i j k}  (Carroll convention)
lriemann(true)          compute and display lriem[i,j,k,m] = - R_{m i j k}
ricci(true)                   compute and display ric[i,j] = R_{i j}
scurvature()              compute the scalar curvature
leinstein(true)           compute G_{i j}
rinvariant()                compute Kretschmann-invariant  R_{i j k m} R^{i j k m}. 
                                   Must have calculated lriem and uriem. Call as: lriemann(false);uriemann(false); rinvariant()
cgeodesic(true)        computes geodesic equations, stored in geod[i]

Utilities:
init_tensor()              reinitializes the ctensor package
cdisplay(tensor)       displays tensor as multidimensional array, e.g. cdisplay(mcs)

The routine:
load(ctensor);                                                 load the package
init_ctensor();                                                  or reset the variables of the package to start all over
dim:4;                                                               set the dimension of the manifold
lg:matrix(.... put a matrix here...);                  define the metric
cmetric();ug;gdet;                                           compute the inverse of metric, its determinant, and other necessary stuff
christof(mcs);                                                  Christoffel symbols
riemann(true);                                                 Riemann tensor
ricci(true);                                                        Ricci tensor
scurvature();                                                    Scalar curvature
leinstein(true);
cgeodesic(true);
uriemann(false);lriemann(true);rinvariant();

## Load the package:

load(ctensor);

## A simple example: The two sphere S^2

First set the dimensionality of the manifold and the names of the coodinates:

dim:2;
ct_coords:[theta,phi];

Define the metric:

lg:matrix(
[a^2,0                            ],
[0    ,a^2 * sin(theta)^2]);

Compute the inverse metric, the determinant and initialize various variables:

cmetric();

ug;
gdet;

Compute the Christoffel symbols:     mcs[i,j,k]    Γ^k_{i j}      = (1/2) g^{k m} ( ∂_i g_{j m} + ∂_ j g_{i m} - ∂_m g_{i j})
and display the nonzero components. Compare with (3.154) Carroll:
Γ^2_{1 2} =  cos(θ) / sin(θ)
Γ^1_{2 2} = -cos(θ)   sin(θ)

christof(mcs);

riem[i,j,k,m]             -R^m_{i j k} = -[ ∂_j Γ^m_{k i} - ∂_k Γ^m_{j i} + Γ^m_{j n} Γ^n_{ki} - Γ^m_{k n} Γ^n_{ji} ]

Compute: riem[i,j,k,m]             -R^m_{i j k} = -[ ∂_j Γ^m_{k i} - ∂_k Γ^m_{j i} + Γ^m_{j n} Γ^n_{ki} - Γ^m_{k n} Γ^n_{ji} ]
Gives: R^2_{1 2 1} = 1
            R^1_{2 2 1} = -sin(θ)^2     Compare with (3.155) Carroll

riemann(true);

Compute: lriem[i,j,k,m]           -R_{m i j k}
Gives: R_{1 2 2 1} = a^2 sin(θ)^2  Compare with (3.156) Carroll

lriemann(true);

Compute Ricci tensor: Compare with (3.157) Carroll

ricci(true);

Compute Scalar Curvature: compare with (3.158) Carroll

scurvature();

Use cdisplay(tensor) to see components in a matrix like display, but be careful, the indices are not the same order as in Carroll.

cdisplay(lriem);

cdisplay(ric);

cdisplay(mcs);

Compute the geodesic equations:

cgeodesic(true);

They are stored in the array geod[i]:

geod[1];geod[2];

## Friedmann metric

First, reinitialize ctensor:

init_ctensor();

dim:4;
ct_coords:[t,chi,theta,phi];

The metric:

lg:matrix(
[-1,0       ,0                         ,0                                               ],
[  0,a(t)^2,0                         ,0                                               ],
[  0,0       ,a(t)^2*sin(chi)^2  ,0                                               ],
[  0,0       ,0                          , a(t)^2*sin(chi)^2*sin(theta)^2  ]);

cmetric();

christof(mcs);

riemann(true);

ricci(true);

scurvature();

leinstein(true);

cgeodesic(true);

uriemann(false);lriemann(false);rinvariant();

## Schwarzschild Metric

init_ctensor();

The Schwarzschild coordinate system (r,t,θ,φ) is predefined:

ct_coordsys(exteriorschwarzschild);

cmetric();

lg;ug;gdet;

Compare with Carroll (5.52), p 206

christof(mcs);

riemann(true);

You may simplify any of the above expressions: (use the "Simplify" menu of wxMaxima in this window to see other options)

ratsimp(riem[1,2,1,2]);

Observe that R_{i j} = 0

ricci(true);

We need to simplify in order to check that the above results are zero:

ratsimp(ric[1,1]);ratsimp(ric[2,2]);

scurvature();

Compare with Carroll (5.50) p 205:  R^2=48 m^2/r^6

uriemann(false);lriemann(true);rinvariant();

cgeodesic(true);

Simplyfy some of the expressions above:

expand(geod[3]);expand(geod[4]);

trigreduce(expand(geod[3]));trigreduce(expand(geod[4]));