Symbolic Tensor Calculus Using Index Notation

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/243666441

Symbolic tensor calculus using index notation

Article  in  Computers in Physics · January 1995


DOI: 10.1063/1.168532

CITATIONS READS

3 738

3 authors, including:

Xavier Jaén
Universitat Politècnica de Catalunya
64 PUBLICATIONS   448 CITATIONS   

SEE PROFILE

All content following this page was uploaded by Xavier Jaén on 09 November 2016.

The user has requested enhancement of the downloaded file.


Computers in Physics
Symbolic tensor calculus using index notation
P. Castellví, X. Jaén, and E. Llanta

Citation: Computers in Physics 9, 335 (1995); doi: 10.1063/1.168532


View online: http://dx.doi.org/10.1063/1.168532
View Table of Contents: http://scitation.aip.org/content/aip/journal/cip/9/3?ver=pdfcov
Published by the AIP Publishing

Articles you may be interested in


TTC: Symbolic tensor calculus with indices
Comput. Phys. 12, 286 (1998); 10.1063/1.168656

TTC: Symbolic tensor and exterior calculus


Comput. Phys. 8, 360 (1994); 10.1063/1.168499

A useful notation for relativistic kinematics


Am. J. Phys. 54, 750 (1986); 10.1119/1.14472

Graded tensor calculus


J. Math. Phys. 24, 2658 (1983); 10.1063/1.525641

Galilean Tensor Calculus


J. Math. Phys. 9, 1927 (1968); 10.1063/1.1664527

Reuse of AIP Publishing content is subject to the terms at: https://publishing.aip.org/authors/rights-and-permissions. Download to IP: 104.249.167.47 On: Wed,
09 Nov 2016 10:00:08
Symbolictensor calculus using index notation
P. Castellvi
Department de Fisica Aplicada, Universitat Politknica de Catalunya, Dr. Maraticb 44,
08028 Barcelona, Spain
X. Ja&?’ and E. Llanta”‘3b’
Department de Fisica i Enginyeria Nucleal; Universitat Politbica de Catalunya Mhdul BI-Campus
Nord, Gran Capith sin., 08034 Barcelona, Spain
(Receh*ed 20 June 1994; accepted 2 February 1995)

We present a Mathematics program which implements tensor calculus using index notation.
Common operations, such as contractions, lowering and raising of indices, symmetrization and
antisymmetrization, and covariant derivatives, are implemented in such a manner that the notation
for the inputs is close to that found iri textbooks. The optimization of the time to perform the
calculations has been one of the main objectives when writing the code. This program has been
merged with the package TTC, recently published in this journal, so the user can use both intrinsic
notation and index expressions when performing tensor calculus. 0 1995 American Institute of
Physics.

KuTROoUCnoN applications and gives a powerful working tool to the user.


For instance, as there is no accepted way to indicate a Lie
The computer algebra system Mathematical has been the derivative using the index notation, one uses the intrinsic
framework of several applications to perform tensor and notation in this case and finally mixes both notations.
exterior calculus.‘-4 In a recent article5 (article 7°K) we But we want to establish clearly that for us the index
presented our package named TTC, Tools of Tensor Calcu- notation indicates nothing more than a practical way to
lus, that implements the majority of the basic tools of ten- write the desired manipulations of tensors. Before perform-
sor and exterior calculus in a differentiable manifold. ing the manipulation, one has to define all the tensors in-
We emphasized that the mathematical intrinsic nota- volved in it and the results turn out to be full tensors that
tion for tensor calculus is surprisingly well suited to be can be used in intrinsic expressions. Following the frame-
implemented in a modern computer algebra system like work of the intrinsic part of TIC, each tensor has to be
Mathematics. On the other hand, everybody who has expressed as a linear combination of basis elements.
worked with tensors knows that the so-called index nota- The main purposes of this work are the following two:
tion is extremely powerful to express and manipulate ten- To make an internal code able to do, in a reasonable time,
sors. Contractions, lowering and raising of indices, symme- sophisticated mixed index operations like
trization and antisymmetrization, covariant derivatives
(semicolon...) are examples of operations which are usu- ( TS[‘,tQ”ls);‘; (1)
ally expressed for mathematicians and physicists by using
index notation. As an example, think of how to express the To have an easy way to write the inputs, i.e., to have a
operation of lowering or raising an index using an intrinsic close to textbook notation for the inputs. The input of Eq.
language. A simple operation involving several contractions (1) will be
can appear very complicated and cumbersome in an intrin-
sic notation. On the other hand, the index notation is not so (T[s,.<‘i,.;-l]Q[m+.,-s])[.;l]//Index[g]
precise in expressing things as the intrinsic one. There are
some ambiguities which are solved, when needed, in the where g is the name of the metric tensor in use. In what
mind of the person who is using it. follows we will explain the meaning of the symbols used
The work we present here is a Mathematics imple- in this expression.
mentation of an index notation for tensor calculus. It works The size of the complete code is of about 100 kbytes and
on TTC and in fact we have merged the index notation part can be used on every machine which can support Math-
with the intrinsic part into a new package with the same ematica using, when loaded, about 250 kbytes of RAM
name. The possibility of mixing the standard notation of memory. The extra amount of memory needed depends on
TTC with the index notation opens a large spectrum of the size of the intermediate expressions generated by the
operations the user wants to perform.
“Also at Laboratoride Fisica Matemitica,SocietatCatalanade Fisica, I. Since the internal code is quite complicated to be ex-
E. C.. Barcelona, Spain. plained here, we will make a demonstration of how TIC
h’E-mail: [email protected] index notation can be used in a short and self-contained
Reuse of AIP Publishing content is subject to the terms at: https://publishing.aip.org/authors/rights-and-permissions. Download to IP: 104.249.167.47 On: Wed,
09 Nov 2016 10:00:08 COMPUTERSIN PHYSICS,VOL. 9, NO. 3, MAYDUN 1995 335
session. This will be the purpose of the next section. The In ?TC the elements of the basis are ZZ [x, i 1, where x
last section is devoted to some final remarks. is the name of the system of coordinates and i is the
index of the element of the basis. As a general conven-
I. MANAGING
INDiCE! tion, in all the package, i>O means an upper index and
iC0 means a lower one. The input of the elements of the
We present in this section a complete, self-contained and
natural basis is
annotated session of the index part of TTC, with the hope
of convincing the reader that TTC is a powerful tool that e,+ZZ[x,-11, (2)
combines the capacity of calculus and ease of use, in the
sense that inputs and outputs are very natural. w’-+ZZ[x,l], (3)
Some notions about how to express tensors in ITC
have to be given before starting the index notation session. where the symbol +Y is used to establish a correspondence
In TTC a tensor is just a linear combination of the basis between the usual notation and the one used in TTC. zz is
elements. Actually this basis has to be a natural one and so also used to input the elements of the basis of the tensors of
a coordinate system has to be declared beforehand. any kind. The tensors of the basis are represented by
l Inputcoordinates [x,(x1, x2, . . .}] is used to ZZ[x,i,j,... ] with the above-mentioned conventions;
introduce the name of the coordinate system and the sym- for example,
bols to use for the coordinates. When entering the list of e,@w2@0J3+ZZ[x,-1,2,3] . (4)
the coordinates TTC also gets the dimension of the mani-
fold. Now we can start the TTC session. First, we load the
l Z Z [ x , i ] : Given a system of coordinates x, the natural TTC package. A message will inform us that we have a
basis for vectors is ei = d/ax’ and tii= dxj for dual forms. default metric and coordinate system:

Mathematica2.1 for MS-DOS386/7


Copyright 1988-92 Wolfram Research, Inc.
In[ l] :=<ttc.m
******************************* TOOLS OFTENSOR C&(‘JJ,US (mc) *******************************
TTC version 3.0
Copyright 1992-94 by P. Castellvi, X. Jaen and E. Llanta.
All conventions follow from: C. W. Misner, K. S. Thorne and J. A. Wheeler, “Gravi-
tation t’
Ed. Freeman, San Francisco (1973)
Default coordinate system:
Coordinates [XX] =(X1, X2, X3)
Default metric tensor:
Metric[Euclidean, XX]=dXl*.dXl+dX2*.dX2+dX3*.dX3
************************************************************~***********************************
The Schwarzschild space time in general relativity is a good playground to show TTC index performances. We need a
convenient coordinate system, so we choose the name cs to label it and the symbols r, th,ph, t to stand for r, O,C#J,~:
In[2]:=InputCoordinates[cs,{r,th,ph,t}]

Out[2]={XX,{X1,X2,X3}}

{cs,{r,th,ph,tH
The output informs us about all the coordinate systems that are actually in use in TTC:
In[3]:=e=ZZ[cs,];
This is a convenient input to avoid writing every time ZZ [ cs , . . . 1. Now the symbol for the basis elements will be
just e (or any other user symbol). We can practice a little by making several inputs of basis tensor elements:
In[4]:={e[t,-r],e[t]*.e[-r],e[t,t],e[t]^2,e[{r,t}],e[r]*-e[t]}

Out[4]={dt*.Dr,dt*.Dr,dt*.dt,dt*.dt,dr*^dt,dr*~dt}
Note that there is more than one way to make the same input. The symbol * . means in this system an outer product and
it is used for inputs and outputs. An integer power of a tensor is understood with the outer product instead of times, as is

Reuse of AIP Publishing


336 content
COMPUTERS is subject
IN PHYSICS, to the
VOL. terms
9,NO. at: https://publishing.aip.org/authors/rights-and-permissions.
3,MAY/JUN 1995 Download to IP: 104.249.167.47 On: Wed, 09
Nov 2016 10:00:08
natural. Similarly, * * means an exterior product and it is used for inputs and outputs. As an argument of e [ ] we can use
integers which are labels for the coordinates or the coordinates themselves. The sign will mean vector (minus) or form (plus).
Now we introduce the Schwarzschild metric tensor (we choose the name SW to label it, and cs is the label of the
coordinate system), as follows:
In[5]:=InputMetric[sw,cs, -(l-2 m/r)e[t]^2+1/(1-2 m/r) e[r]-2+
r-2 (e[th]^2+Sin[th]-2 e[ph]^2 ) ]
1 2 2 2m
Ouf-[5]= ------- dr*.dr+r(dth*.dth+Sin[th] dph*.dph)-(1 - ---)dt*.dt
2m r
1 - ---
r
Now we define R as the Riemann tensor of the Schwarzschild metric in the coordinates labeled cs, suppressing the
output:
In[6]:=R=Riemann[sw,cs];
The next input is the first one where the index notation appears. In fact, there is no practical operation in it, but it is
suitable to show the philosophy used in the programming index notation. Sometimes we have shortened the output. This is
indicated by “. . . “. Thus, for the Riemann tensor we have,
In[7]:=R[-i,-j,-k,-1] //Index[sw]
m m
Out[ 7]= ------- dr*.dth*.dr*.dth + -------- dr*.dth*.dthd*.dr+ ...
2m-r -2m+r

Note that R itself is the (covariant) Riemann tensor. The has to be understood in the index notation sense. Index
input In [ 7 ] is analogous to writing Rijkr , when one is itself has an argument which is the label of the metric we
using index notation to express, in fact, the whole tensor. want to use if needed. If there is no metric, and conse-
R,jk, does not mean one component or a set of components quently the input has not metric operations, just write In-
more or less ordered. It just means the tensor R is its co- dex [I. The indexes i,j,k,l... in R[-i,-j,-k,
variant version, and the use of the index is a useful way to -11, and in the rest of the session, have to be symbols and
indicate the covariant character of R. The output is just R.
can be substituted by another set of symbols.
The function Index[ SW] is the way we indicate to TTC
that the input (more exactly, the argument of Index[ SW]) To raise the first index of R we have to just input:

In[8]:=R[i,-j,-k,-l]//Index[sw]
2m 2m
Out[8]= ------------ Dt*.dr*.dr*.dt + __----------- Dt*.dr*.dt*.dr + ...
(2m-r)r* r*(-2m+r)
In this case, In [ 7 ] is analogous to Rikl. Note that we use the same symbol R, i.e., the covariant version of the Riemann
tensor, but now the result is another tensor (also in the tensorial type sense) and the operation-the raising of the first
index-is indicated by the signs of the indexes.
Another similar input and output is
In[g]:=R[-i,-j,k,-l]//Index[sw]

m m
Out[9]= ------------- dr*.dth*.Dth*.dr - - dr*.dth*.Dr*.dth + . ..
r* ( -2m+r ) r
To indicate contraction we just repeat the index, as in the convention summation of Einstein:
Reuse of AIP Publishing content is subject to the terms at: https://publishing.aip.org/authors/rights-and-permissions. Download to IP: 104.249.167.47 On: Wed,
09 Nov 2016 10:00:08 COMPUTERS IN PHYSICS,
VOL.9, NO.3, MAY/JUN 1995 331
In[lO]:=R[i,-j,-i,-l]//Index[sw]

Out[ lO]=O

In [ 10 ] is just the Ricci tensor or Rji, where, as usual, a sum over i= 1 , . . . ,n is understood. The dimension of the manifold
is n, in our case the space-time dimension, i.e., 4. The output is 0, since Schwarzschild space time is a vacuum solution of
Einstein’s field equations.
To indicate the symmetrization of indices we use the symbols .( and ). enclosing the indices that we want to
symmetrize. Analogously to indicate antisymmetrizations we use . (( and )) . .
The ciclicity property of the Riemann tensor can be checked:

InlIIl:=R[-i,.c-j,-k,-l>.]//Index[sw]

Out[ ll]=O

In [ 111 is analogous t0 Ri(j&[) .


In the next input the symmetrization is applied only to the indices j and I:

In[l2]:=R[-i ,.C-j,k,-l>.] //Index[sw]

m m
Out[12]= ------------ dr*.dr*.Dt*.dt + ---------mm--_- dr*.dr*.Dph*.dph + ...
(2m-r)r* 2r2 ( -2m+r )

where In1 12 ] stands for R~~jl and, as usual, we have to understand that the index k is not symmetrized.
In the next input we intro d uce the way to express covariant derivatives. For example, the differential Bianchi identities
are

In[l3]:=R[-i,-j,.<-k,-l,.;-p>.]//Index[sw]

Out[ 13]=0

where the symbol . ; followed by an index is used to mimic the semicolon notation for the covariant derivative. Now the
tensor has five indexes. The new index can be treated as the others, and we can, for example, symmetrize it. In [ 13 ] stands
for Rij(kl;p) .
Another usual index operation is a multiple contraction, as in the following example:

In[14]:=R[-i,-j,-k,-l]R[i,j,k,l]//Index[sw]

48m2
Out[ 14]= -----
r6

In [ 14 ] stands for RijklRijki.


The following example is interesting, since it puts the emphasis on things that are or seem to be obvious when using
index notation. Suppose that we want to construct the tensor S defined by Sij&l= ~(Rikjl+Riljk). Note that this expression
informs us not only that the indices k and I are symmetrized. It also tells us that the result must be the one indicated by the
indices on S in the right-hand side of the expression. How can we make an input exactly analogous to this? We have
programmed Index [g] in such a way that it takes as indices of the final result the ones that appear in the first term of the
input expression and have not been contracted. So we can force the order of the indices by simply making an input using as
first term the tensor 0 with the indices in the required order. A possible input to calculate S is then:

Reuse of AIP
338Publishing content
COMPUTERS is subject
IN PHYSICS, to the
VOL. terms
9,NO. at: https://publishing.aip.org/authors/rights-and-permissions.
3,MAY/JUN 1995 Download to IP: 104.249.167.47 On: Wed, 09
Nov 2016 10:00:08
. _ * _-.I,-- _ _
In[15 ] :=s=o [-i,-j,-k,-11
+1/3(R[-i,-k,-j,-l]+R[-i,-l,-],-k])//Inciex[sw]
‘~ . -

2m 2m Sin[th]*
Out[15]= --------- dr*.dr*.dth*.dth + _____------- dr*.dr*.dph*.dph - ...
6m-3r 6m-3r
Note that the S in the right-hand side appears without indices, since the result of Index [SW] in the left-hand side is
a tensor and indices constitute only a suitable way to indicate some operations. In this way, the components of the tensor S
will be ordered as indicated by the indices in the 0 tensor.
In the next example we make some tensor operations on a scalar function:
In[l7]:=f[r][.;i,.;-i]//Index[sw]
Enter the name of the coordinates of f [r], Interrupt [] or Dialog []
=cs
-2 m f’[r]+ 2 r f’[r]-2 m r f”[r]+r* f”[r]

r*

I
In [ 17 ] stands for f’ being f a function of r. TTC asks for where the square brackets [ and ] are used to indicate an-
the basis or coordinate system of the scalar function f [ r ] tisymmetrization of indices. Note that in this expression,
which is cs in this case. and as is usual, the symbol R is used for the Riemann and
In all of these examples,as we have commented,the Ricci tensors and also for the curvature scalar. This is indi-
indexes i, j,k,l.. . have to be symbols. In interacting cated by the number of indices they have in each case.
with Mathematics as in the above session, this will not Obviously, in TIC we cannot use an analogy to this, since
produce any problem, but if we want to define some func- knowledge of the number of indices does not suffice to
tion using index notation and save it in a file for future use distinguish the algorithms for the Riemann and Ricci ten-
this can be a problem. Let us see how we can proceed.
sors. For this reason, we have to use different symbols for
Suppose we want to define an algorithm for the Weyl tensor
IV(Ref. 6, p. 325, Eq. 13.50): the Riemann and Ricci tensors when writing inputs for
TIT.
We write in a file that we call weyl .m the following
Wabcd= Rnbcd- 2&@[b,l+ f 8=EC$]dlR, (5) code:
I
Weyl[g-,x-]:=Weyl[g,x]=

Module[{Rie,Ric,R,Dl,a,b,c,d},

Rie=Riemann[g,x];

Ric=Ricci[g,x];

R=Curvature[g,x];
Dl=IdentityTensor[x,l,-l]

Index[gl[

Rie[a,b,-c,-d] -

2 Dl[.=Ga,. 4-c]Ric[b%.,-dB.]+

l/3 Dl[.+a,.+-c]Dl[b+.,-dB.1 R

Reuse of AIP Publishing content is subject to the terms at: https://publishing.aip.org/authors/rights-and-permissions. Download to IP: 104.249.167.47 On: Wed,
09 Nov 2016 10:00:08 COMPUTERS INPHYSICS,VOL.9,NO.3,MAY/JUN 1995 339
Note that we use the Mathematics utility Module to course, the computing time and the amount of memory
define local variables Rie, Ric, R, Dl, in order to needed increase with the difficulty of the desired manipu-
shorten and make more readable our code for the Weyl lation.
tensor. Also, we define the indices as local variables. In this The target user of TTC is a person needing to perform
way, we are sure that in this expression a, b, c, d are tensor calculus for research or academic purposes. We have
indices and will not be shadowed by future uses of them. incorporated some warnings and flags in the code to pre-
Obviously, the result will be the Weyl tensor, independent vent the misuse of the functions of the package, but con-
of the particular set of indexes used to define it. ceptual errors in the inputs can produce wrong results.
In the form we have written weyl .m, we cannot use Therefore the user is assumed to know enough differential
the Mathematics function Getl$ename] since there are geometry to write mathematically correct inputs.
some symbols in it (. e, . ;) that are not part of the The scope of applications of TIC is going to be broad-
standard Mathematics inputs. So we have to use a TIC ened in the near future with the inclusion of calculus in
function called TTCGet that works the same way as Get noncoordinate bases and the symbolic treatment of tensors.
but understands the input index notation.
ACKNOWlB6MENTS
LFNAlflHHARKS One of us (X.J.) should like to acknowledge the Comision
Asesora de Investigation Cientifica y Tecnica for financial
It is clear from the previous section that we have built a support under Contract No. PB90-0482-C02-01. S.
Mathematics package that has a very friendly input formal-
ism for index tensor operations and preserves, at the same
time, the intrinsic character of tensor objects. We think that
this constitutes an essential interface of the basic package 1. S. Wolfram, Mathematics: A System for Doing Math-
TTC, in the sense that this index notation gives the user a ematics by Computer, 2nd ed. (Addison-Wesley, Read-
tool to perform a very easy translation of the expressions ing, MA, 1991).
that would be written by hand. So, anybody with a very 2. J. M. Aguirregabiria, Math. J. 1, 51 (1990).
small knowledge of the Mathematics commands is able to 3. D. G. B. Edelen, Math. J. 1, 92 (1991).
use the computer to perform tensor calculus. 4. S. M. Christensen and L. Parker, Math. J. 1, 51 (1990).
It must also be pointed out that the examples presented 5. P. Castellvi, X. Jadn, and E. LLanta, Comput. Phys. 8,
in the previous section are of intermediate level difficulty. 360 (1994).
In fact, we have tested TTC with more complicated ex- 6. C. W. Misner, K. S. Thorne, and J. A. Wheeler, Gruvi-
amples taken from our research work in gravitation. Of tation (Freeman, San Francisco, CA, 1973).

Reuse of AIP Publishing content is subject to the terms at: https://publishing.aip.org/authors/rights-and-permissions. Download to IP: 104.249.167.47 On: Wed,
340 COMPUTERS IN PHYSICS, VOL.9, NO.3,MAY/JUN 1995
09 Nov 2016 10:00:08
View publication stats

You might also like