Covariant and contravariant components of a generic metric, its determinant and Christoffel symbols

Loading EinS... Be sure to change the next input line to the directory you placed file Eins.m

SetDirectory["/Users/sergeiklioner/users/klioner/PROJECTS/EinS/"];

<<EinS.m;

Now EinS is ready to work. In this demo notebook we will show one way to program within EinS and Mathematica in general.
This example is conceived to show some basic features of EinS, but by no means to show a preferable style of programming in
EinS or Mathematica. Mathematica language is powerful enough to give user an opportunity to program in many styles: from
procedure-oriented (PASCAL-like) or pure functional (LISP-like) to logical (PROLOG-like).

Definition of a general expansion of covariant components of the metric tensor

Here we define various objects entering in the expansion of the metric tensor with the aid of DefObject.
Let us look on the online help message about this procedure

?DefObject

Well. Let us try...

DefObject[U,0]

DefObject[R,1]

DefObject[U,1]

DefObject[U,2,{1,2}]

DefObject[W,1]

DefObject[W,2,{1,2}]

DefObject[g,2,{1,2},ESIndicesLow -> True]

Here is a rule defining convariant components of the metric. Rules are one of the ways to program within Mathematica.

CovariantComponents={
g[0,0]:> 1+c1^2 U+c1^4 W+O[c1]^5,

g[0,i_]:>c1 R[i]+c1^3 U[i]+c1^5 W[i]+O[c1]^6,

g[i_,j_]:>-Delta[i,j]+c1^2 U[i,j]+ c1^4 W[i,j]+O[c1]^5};

Now we can print covariant metric as symbols:

PrintES[g[0,0]]

Print[g[0,i]]

Print[g[i,j]]

or substitute their expansions s defined above:

PrintES[g[0,0] /. CovariantComponents]

PrintES[g[0,i] /. CovariantComponents]

PrintES[g[i,0]  /. CovariantComponents]

PrintES[g[i,j] /. CovariantComponents]

Definition of contravariant components of the metric

Defining contravariant components of the metric as EinS's object. Note that we want to output the contravariant components
with the same name "g" as covariant ones. EinS in fact does not know anyhow that two object "gc" and "g" (as defined in the
previous section) represent covariant and contravariant components of the same tensor. We want just to tell him to output the
object "gc" with the print name "g".

DefObject[gc,2,"g",{1,2}]

In principle EinS could help to find expansions of the contravariant components of metric from the given expansions of the
covariant ones, but here we prefer to specify rules for computing the expansions of the contravariant components "manually"
(of course, they have been found with EinS!) and then check that the two matrices are really invert of each other.

ContravariantComponents={
gc[0,0]:>Module[{k,l},
                1+c1^2 (-U-DefES[R[k] R[k],{k}])+
                  c1^4 (U^2-W+2U DefES[R[k] R[k],{k}]+
                        DefES[R[k] R[k] R[l] R[l],{k,l}]-
                        2DefES[R[k] U[k],{k}]-
                        DefES[U[k,l]R[k]R[l],{k,l}])+
                  O[c1]^5],
gc[0,i_]:>Module[{k,l},
                 c1   R[i]+
                 c1^3 (U[i]-U R[i]-
                       R[i] DefES[R[k] R[k],{k}]+
                       DefES[U[i,k]R[k],{k}])+
                 c1^5 (R[i] (U^2-W+
                             2U DefES[R[k] R[k],{k}]-
                             2 DefES[R[k] U[k],{k}]+
                             DefES[R[k] R[k] R[l] R[l],{k,l}]-
                             DefES[U[k,l]R[k]R[l],{k,l}])+
                       W[i]+DefES[R[k] W[i,k],{k}]-
                       U U[i]-
                       DefES[R[k] R[k],{k}] U[i]+
                       DefES[U[i,k]U[k],{k}]-
                       U DefES[U[i,k]R[k],{k}]+
                       DefES[R[l]U[i,k]U[l,k],{k,l}]-
                       DefES[U[i,k]R[k]R[l]R[l],{k,l}])+
                 O[c1]^6],
gc[i_,j_]:>Module[{k},
                  -Delta[i,j]+
                  c1^2 (-U[i,j]+R[i] R[j])+
                  c1^4 (-W[i,j]-U R[i] R[j]-
                        R[i]R[j] DefES[R[k] R[k],{k}]+
                        R[i]U[j]+R[j]U[i]-
                        DefES[U[i,k]U[j,k],{k}]+
                        R[j]DefES[U[i,k]R[k],{k}]+
                        R[i]DefES[U[j,k]R[k],{k}])+
                  O[c1]^5]};

Now we can print contravariant metric as symbols:

Print[gc[0,0]]

Print[gc[0,i]]

Print[gc[i,j]]

or substitute their expansions as defined above:

PrintES[gc[0,0] /. ContravariantComponents]

PrintES[gc[0,i] /. ContravariantComponents]

PrintES[gc[i,0]  /. ContravariantComponents]

PrintES[gc[i,j] /. ContravariantComponents]

Are the contravariant components correct? Various tests

Let us check if the contravariant components as we specified them in the list of rules named ContravariantComponents are
in agreement with the covariant components as we specified them in the list of rules named CovariantComponents. Namely
we have to check that the two matrices defined by the covariant and contravariant components are inverse of each other.
We can check this in a variety of ways. Two ways are described below. Note the use of EinS's function ToComponents
allowing one to re-write all implicit summation in explicit form.

Way 1: we check that matrix product of g[i,j] and gc[k,l] is identity matrix within truncation errors of our expansions

unit=ExpandAll[Table[g[i-1,j-1] /. CovariantComponents,
                {i,4},{j,4}] .
          Table[gc[i-1,j-1]  /. ContravariantComponents,
                {i,4},{j,4}]];

Do[Print[i-1,":",j-1,":",
   ToComponents[ComputeES[unit[[i,j]]]]],{i,4},{j,4}]

Way 2: We directly Invert matrix of covariant components and check that the inverse does coincide with matrix of
contravariant components within the truncation errors of our expansions

inver=Inverse[Table[g[i,j] /. CovariantComponents,{i,0,3},{j,0,3}]];

Do[Print[i,":",j,":",
ToComponents[ComputeES[gc[i,j] /. ContravariantComponents]]-inver[[i+1,j+1]]],
{i,0,3},{j,0,3}]

Defining and checking the determinant of the metric

We introduce the definition of the determinant and check that this definition really coincides with the determinant of the matrix
of the covariant components and with the inverse of the determinant of the matrix of the contravariant components as defined
above.

detg:=-1+c1^2(-U-DefES[R[i]R[i],{i}]+
               DefES[U[i,i],{i}])+
        c1^4(-W-2DefES[R[i]U[i],{i}]+
              U DefES[U[i,i],{i}]+
              DefES[W[i,i],{i}]+
              1/2 DefES[U[i,j]^2,{i,j}]-
              1/2 DefES[U[i,i] U[j,j],{i,j}]-
              DefES[R[i]R[j]U[i,j],{i,j}]+
              DefES[R[i]^2 U[j,j],{i,j}])+
        O[c1]^6;

determinant1=Det[Table[g[i,j] /. CovariantComponents,
                       {i,0,3},{j,0,3}]];

Expand[ToComponents[ComputeES[detg-determinant1]]]

determinant2=Det[Table[gc[i,j] /. ContravariantComponents,
                       {i,0,3},{j,0,3}]];

Expand[ToComponents[ComputeES[detg-1/determinant2]]]

Computing Christoffel symbols of the second kind

We define object "Gam" with 3 indices. This object will  represent Christoffel symbol of the second kind.

DefObject[Gam,3,"Γ",{2,3},{},{2,3}]

We define a set of coordinates. This automatically generate simplification rules as well as output formats for partial
derivatives with respect to these coordinates.

DefRS[x,t]

Now we are ready to define Christoffel symbols in terms of metric. Let us recall that we have defined objects "g" and "gc" above.

withmetric ={
     Gam[i_,k_,l_] :>
        Module[{m},
               DefES[1/2 gc[i,m]*
                     (PD[g[m,k],x[l]]+
                      PD[g[m,l],x[k]]-
                      PD[g[k,l],x[m]]),{m},
                     ESRange -> $ESDimension]]};

We can operate now with Christoffel symbols. We can treat them as symbols (below we work with Gam[i,0,0], but we could
do the same for any Christoffel symbol):

Print[Gam[i,0,0]]

We can compute them in terms of metric components to be hold as symbols (note that "space-time" indices are printed with
apostroph " ' " ):

PrintES[Gam[i,0,0] /. withmetric]

We can separate zero ("time") value of the dummy indices and non-zero ("spatial") values with the aid of function SplitTime

PrintES[SplitTime[Gam[i,0,0] /. withmetric]]

and compute Christoffel symbols in terms of expansion of metric components

PrintES[gi00=ComputeES[SplitTime[Gam[i,0,0] /. withmetric] /.
                  CovariantComponents /. ContravariantComponents]]

How many terms (monomials which may involve implicit summation) do we have in the result?

SeriesLength[gi00]

EinS can produce LaTeX form of any expression with aligned form with specified number of terms per line

$TermsPerLine=4;
EinS2TeX[gi00]

or save it directly to the file. For example, in plain TeX form (you should add only "\bye" at the end of file, then run TeX
and enjoy the publication quality printout of your expression in traditional notations):

$TeXDialect=$PlainTeX;
SaveTeX["demo1tex.tex",gi00]

At last we can substitute more specific form of the metric by giving definitions for the potentials entering in the metric.
Namely we want now to compute Christoffel symbols in a reference system rigidly rotating relative to harmonic ones.
In this we will use lower precision by substituting zero for higher order potentials. We have first to define new object which
will appear in our calculations: omega[i] represents the angular velocity of rotation of the rotating reference system relative
to non-rotating one.

DefObject[omega,1,"ω"]

Standard procedure DefObject does not allow to define separately output name and name for TeX output, but we want to
have \omega for our object omega in TeX output. It is easy. Look what we have now:

Print[omega[i]]

$TeXDialect=None;
EinS2TeXString[omega[i]]

We can define a better TeX name:

EinS2TeXString[omega]="\\omega";

Print[omega[i]]

EinS2TeXString[omega[i]]

Note that  this print name "\omega" will shadow all other print name for any object with name "omega" with any indices until
it is removed by the user.

Now we have to declare that omage[i] does not depend on spatial coordinates

DeclareIndependent[omega,1,{x}]

Now, for example, partial derivative of omega with respect to spatial coordinates x[i] are zero

PD[omega[i],x[i]]

However, it is not so relative to time "t"

PD[omega[i],t]

or

PD[omega[i],x[0]]

We need one more object: orthogonal matrix of rotation

DefObject[P,2]

DeclareIndependent[P,2,{x}]

We define w and w[i] to be usual Newtonian and vector potentials in nonrotating harmonic reference system. We do not have
necessarly to define objects with zero arguments, but we can

DefObject[w,0]

DefObject[w,1]

Now we can specify the set of rule for potentials entering in the metric. Note that the order of rules in the following list is
important since the rules are applied in this order, and therefore, you should place more specific rules before more general
ones. When you give several definitions for the same fucntions through ":=", the order is not always important since
Mathematica itself places more specific rules before more general in its internal database. Otherwise more specific rules
would be shadowed by the more general ones.

rotating=
 {
(* g[i,j] *)
  U[i_,j_] :> -Delta[i,j] 2 w,
  W[_,_] :> O[c1]^4,
(* g[0,i] *)
  R[i_] :> Module[{j,k},-DefES[LeviCivita[i,j,k] omega[j] x[k],{j,k}]],
  U[i_] :> Module[{j,k},
                            4 DefES[P[i,j] w[j],{j}]-
                            2 w DefES[LeviCivita[i,j,k] omega[j] x[k],{j,k}]],
  W[_] :> O[c1]^5,
(* g[0,0] *)
U :> -2w-Module[{i,j,k,l,m},
                  DefES[LeviCivita[i,j,k] omega[i] x[k]*
                        LeviCivita[i,l,m] omega[l] x[m],
                        {i,j,k,l,m}]],
  W :> 2 w^2+
       8 Module[{i,j,k,l},DefES[LeviCivita[i,j,l] omega[j] P[k,l] w[i] x[k],
                                {i,j,k,l}]]-
       2 w Module[{i,j,k,l,m},
                  DefES[LeviCivita[i,j,k] omega[i] x[k]*
                        LeviCivita[i,l,m] omega[l] x[m],
                        {i,j,k,l,m}]]};

Covariant metric in this case

PrintES[ComputeES[g[0,0] /. CovariantComponents /. rotating]]

PrintES[ComputeES[g[0,i] /. CovariantComponents /. rotating]]

PrintES[ComputeES[g[i,j] /. CovariantComponents /. rotating]]

Finally for the Christoffel symbol Gam[i,0,0] we have

PrintES[gi00rot=ComputeES[gi00 /. rotating]]

SeriesLength[gi00rot]

Test for nonrotating metric: we have the well known result

PrintES[ComputeES[gi00rot /. {omega[_] -> 0, P[i_,j_] :> Delta[i,j]}]]