Utilities

Sections in this chapter:

Introduction
The compacted calculus in TTC
Tensor simplifications
Saving and loading files
How to save a TTC session
How to clear
Big calculus

For other chapters go to Index

Introduction

In this chapter we shall describe some tools that help you in the use of TTC. Most of them have been introduced or used in others chapters. Nevertheless we will introduce a new TTC function called Compact with it's associated functions TTC and TTCR.In fact through all this guide TTC has used them in a hidden manner. Now we want to show the structure off this new functions and how you can use them to save time and RAM memory in large calculations.

The compacted calculus in TTC

The essential trick to understand compacted calculus is to take into account some functions don't need the whole of the structure of an expression in order to perform the operation. Also some times it is not desirable to take into account a lot of simplifying rules if at the end (or in the middle ) the collapse of an expression will be due to a simple operation like a minus between a very large but equal expressions. If F(x,y,z,....) is a very large expression we don't need to simplify it in order to obtain the result

F(x,y,z,....)-F(x,y,z,....)=0

because it does not depend on such structure!
When dealing with tensors this is very common, due to symmetries and other properties of tensors, to have a lot of equal or quasi-equal expressions. Algebraic tensor calculus is in some sense a very simple calculus because it use essentially sums and products of components of tensors. The combination of this operators can be very large, of course, but the possibility of collapse of quasi-equal terms is high. TTC exploit this fact internally. Also the user can use them in a controlled way as we shall see in Big calculus.
One of the functions which use a lot the compact utilities of TTC is TensorSimplify

Tensor simplifications

One of the key features of the computer algebra systems is the possibility of simplify and convert the expressions that one obtains. In TTC there are some adapted tools which take it easier to deal with the tensorial results.
TensorSimplify is used to simplify tensorial objects. It can simplify either scalars, tensors or forms. It goes through the tensor and simplifies each component instead

of trying to simplify the tensor as a whole.
One can choose the conversion operators ( Simplify, Expand, Together, ...) to be used through a list in first argument of TensorSimplify. The syntax is

TensorSimplify[list][t]

where t is the tensor one wants to simplify.

Here we can appreciate the way tensor simplify works. We define a tensor in a raw way. Next we use SetCompactTensor or it's short syntax "=>". The effect of this is to join terms of equal basis element also it has the effect to attach the right hand side at the left whatever could happen at the right, as we shall see..... After we simplify the output using TensorSimplify This has the effect also to simplify the tensor T!!. If we define a new tensor Q as the not simplified version of T and then use TensorSimplify over the output the tensor Q will not be simplified. BUT if we use "=>" to define R as the same not simplified expression used in the definition of Q the effect is that R will we automatically defined as the simplified version . We use TensorSimplify[{Factor} over the not simplified expression an see what effect has over the tensor T,Q,R.Finally we use CompactTensor in order to see the actual simplified version of the not simplified expression.

T=2 X1(1/X1 X2+1/X1 X3) XX[1,2]+X3^3 X1 XX[1,3]+1/X1 XX[1,2]

 1                   X2   X3
 -- dX1*.dX2 + 2 X1 (-- + --) dX1*.dX2 + 
 X1                  X1   X1
 
       3
 >X1 X3  dX1*.dX3

T=>%
  1          X2   X3                   3
(-- + 2 X1 (-- + --)) dX1*.dX2 + X1 X3  dX1*.dX3
 X1         X1   X1

Teq=%;

TensorSimplify[{Simplify}][%]
  1                                3
(-- + 2 X2 + 2 X3) dX1*.dX2 + X1 X3  dX1*.dX3
 X1

T
  1                                 3
(-- + 2 X2 + 2 X3) dX1*.dX2 + X1 X3  dX1*.dX3
 X1

Q=%2

 1                   X2   X3
=-- dX1*.dX2 + 2 X1 (-- + --) dX1*.dX2 + 
 X1                  X1   X1
 
          3
   > X1 X3  dX1*.dX3

TensorSimplify[{Simplify}][%]

 1                                 3
(-- + 2 X2 + 2 X3) dX1*.dX2 + X1 X3  dX1*.dX3
 X1

Q

 1                   X2   X3
-- dX1*.dX2 + 2 X1 (-- + --) dX1*.dX2 + 
X1                  X1   X1
 
         3
  > X1 X3  dX1*.dX3

R=>Teq
 1                                 3
(-- + 2 X2 + 2 X3) dX1*.dX2 + X1 X3  dX1*.dX3
 X1

TensorSimplify[{Factor}][ Teq]
1 + 2 X1 X2 + 2 X1 X3                 3
--------------------- dX1*.dX2 + X1 X3  dX1*.dX3
        X1

R
1 + 2 X1 X2 + 2 X1 X3                 3
--------------------- dX1*.dX2 + X1 X3  dX1*.dX3
         X1

Q
1                   X2   X3
-- dX1*.dX2 + 2 X1 (-- + --) dX1*.dX2 + 
X1                  X1   X1
 
          3
   > X1 X3  dX1*.dX3

T
1 + 2 X1 X2 + 2 X1 X3                 3
--------------------- dX1*.dX2 + X1 X3  dX1*.dX3
         X1

CompactTensor[Teq]
1 + 2 X1 X2 + 2 X1 X3                 3
--------------------- dX1*.dX2 + X1 X3  dX1*.dX3
        X1
A you can see each time you use TensorSimplify the simplifications performed in an object is used also in other objects.
If you don't want to do this you can use simple Simplify or whatever simplifying function you want over each of the components, using TensorComponent.

TensorSimplify is also used in internal simplifications. In this case, the variable TTCSimplify stores the list of simplification operators that have to be used. You can modify this variable at will. The frequency of internal simplifications is regulated with SimplifyLevel, which runs from 0 through 4. A value of 0 disables internal simplifications. The value SimplifyLevel is declared with InputSimplifyLevel.
 
 

Saving and loading files

A possible way of using TTC is by putting the inputs in a file. In this way, the definitions of coordinates, metrics, coordinate changes, etc. are typed only the first time they are used and afterwards one can retrieve them when necessary. To load such a file in a Mathematica session you casn use Get[ file.ext] or << file.ext, however, if in a file you write any of the symbols for tensorial product *., exterior product *^, symmetrization .< >.}, antisymmetrization .<< >>. derivative .;, ., or the symbol of SetCompactTensor: => or if you have used the setting Compact[On] when saving the file within TTC the TTC command TTCGet[file.ext]has to be used instead of Get. The way to be rigth is to use TCGet[file.ext] always.

Mathematica has the function Save to store in a file the object definitions that are going to be used later on. To be able to proceed the same way once TTC has been loaded TTCSave has to be used. The complete syntax of this command is TTCSave[ file.ext, format, exp1, exp2, ...]
being file.ext the name of the file where the expressions are to be saved. The parameter format can take two values: In and Out. When format takes the value In, TTC stores exp1, exp2,... in a format suitable to be read in from Mathematica in another session in the file file.ext. If format is equal to Out, exp1, exp2,,,, are stored in the file file.ext in an easy-to-read way.
If the format parameter and .ext are omitted, TTC creates two files: file.in and file.out with the two types of formats.

You can save things like Riemann[g,x]or Metric[g,x ], Coordinates[x], BasisSymbols[{x,b} . Is your own responsibility to control if such objects are coherently stored and can be reused in a correctly mathematical way. For example if you store the Riemann but not the coordinates, metric ..etc. and then get the file in a session TTC probably ask for the coordinate system metric ...and you must enter it in a coherently way or interrupt the session!

In general it is useful to save space to use TTCSave with the option Compact[On] Se the subsection below...

How to save a TTC session

Suppose you have used TTC in a session and defined a Riemann manifold and calculated Riemann and Ricci tensors among other tensors. How can you save it correctly? Let's suppose that the coordinate system is called xn and the metric gn then
TTCSave[path/file(.ext/
),(In/Out/omitted),{Coordinates[xn],Metric[gn,xn],
        ChristoffelTensor[gn,xn],Riemann[gn,xn],Ricci[gn,xn],T,Q,....}]
will save in the file file the session in a order that it will be correctly used later.

Note: If Compact[Off] TTCSave saves objects uncompacted. If Compact[On] TTCSave use the compact utilities to save objects.

How to clear

Sometimes, it is convenient to remove a coordinate system, a basis, a metric or change and forget it or declare it again. TTC has functions that clear things in an easy and coherent way.

It's strongly recomended that you don´t use these fucntions to clear objects and continue with a new sesion. If you want to make a NEW sesion is much more recomended to restart the Mathematica program and restart TTC . These functions are useful went you make a mistake in an Input function like InputCoordinates, InputMetric ....After the mistake there are no problem to use them.

They are:

ClearCoordinates                ClearBasis
ClearMetric                     ClearChange
ClearTTC
If you clear a basis named {cc, bb} using ClearBasis[{cc,bb}] all objects that depends on it will be cleared. Hence, TTC clears not only the basis but also all objets related to it. The same it is true for the remaining three functions. Finally ClearTTC clear all things related to TTC .

Big calculus

In this section we show how you can use Compact[On/Off] in order to save space and time when big calculus has to be done. Here we use the kerr metric us a example of big. More big is the calculus more useful can be the present advises.

First we calculate the ricci tensor for the kerr metric by using Compact[Off] and a simplifylevel=1 in order to sure that expression will not be very large. The time and memory used must be take as a reference numbers in order to compare with the second way to do the same calculus:

In[1]:=(
InputSimplifyLevel[1];
Compact[Off];
TTCSimplify={SinTosin,Together,sinToSin});
In[2]:=(
InputCoordinates[Boyer, {r, th, ph, t}];
ScalarBasis=Boyer;
A = r^2 - 2 M r + a^2 ;
B = r^2 + a^2 Cos[th]^2;
e = ZZ[Boyer];
g = -A/B e[4,4]+
   A/B a Sin[th]^2 (e[3,4]+e[4,3])-
   A/B a^2 Sin[th]^4 e[3,3]+
   Sin[th]^2 /B (r^2+a^2)^2 e[3,3]+
   Sin[th]^2 /B a^2 e[4,4]-
   Sin[th]^2 /B (r^2+a^2) a (e[3,4]+e[4,3])+
   B/A e[1,1]+
   B e[2,2] ;
InputMetric[KERR, Boyer, g]);

In[3]:=Ricci[KERR,Boyer]//Timing

Out[3]={29.33 Second, 0}

In[4]:=MaxMemoryUsed[]

Out[4]=2021116
In the second way we use SimplifyLevel=0, that is no simplifications at all, but we set Compact[On]. When the ricci tensor has been calculated we simplify it (in fact all objects used in the calculus of Ricci will be also simplified!!). You can see that the time is almost the half and the memory used is less than in the first way!!
In[1]:=(
InputSimplifyLevel[0];
Compact[On];
TTCSimplify={SinTosin,Together,sinToSin});
In[2]:=(
InputCoordinates[Boyer, {r, th, ph, t}];
ScalarBasis=Boyer;
A = r^2 - 2 M r + a^2 ;
B = r^2 + a^2 Cos[th]^2;
e = ZZ[Boyer];
g = -A/B e[4,4]+
   A/B a Sin[th]^2 (e[3,4]+e[4,3])-
   A/B a^2 Sin[th]^4 e[3,3]+
   Sin[th]^2 /B (r^2+a^2)^2 e[3,3]+
   Sin[th]^2 /B a^2 e[4,4]-
   Sin[th]^2 /B (r^2+a^2) a (e[3,4]+e[4,3])+
   B/A e[1,1]+
   B e[2,2] ;
InputMetric[KERR, Boyer, g]);

In[3]:=Ricci[KERR,Boyer];//Timing

Out[3]={6.54 Second, Null}

In[4]:=TensorSimplify[TTCSimplify][Ricci[KERR,Boyer]]//Timing

Out[4]={10.16 Second, 0}

In[5]:=MaxMemoryUsed[]

Out[5]=1383964
You must take into account that in both cases TensorSimplify is able to recognize the symmetries of Ricci and other objects. That is the fall in time is due essentially to the manipulation of expression within Mathematica . In the first case when Mathematica do something over an expression it takes the expression itself. In the second case Mathematica takes only a little object related to the expression. Only when TensorSimplify acts all this little objects are set to the related expressions.

This page is maintained by XavierJaén.