A Complete Guide for performing Tensors computations using Physics
The Physics package, developed by Maplesoft, is an integral part of the Maple system. The package includes commands for Classical and Quantum Mechanics, Classical Field Theory and General Relativity. It also includes 5 subpackages: Vectors, StandardModel, FeynmanIntegral, and Tetrads and ThreePlusOne which are related to General Relativity.
Section I of this guide includes the information needed to compute with tensors in Classical and Quantum Mechanics, Electrodynamics and Special Relativity, using the Physics package. This section is also relevant for computations in General Relativity. Section II is completely devoted to working with tensors in curved spacetimes. Section III is about transformations of coordinates.
To transform this page into an active computational worksheet that enables you to reproduce its contents, click the corresponding icon on the toolbar.
For an alphabetical list of the Physics commands with one-line descriptions and links to the corresponding help pages see Physics: Brief description of each command.
I. Spacetime and tensors in Physics
Default metric, signature and coordinates
Systems of coordinates
Tensors, their definition, symmetries and operations
Defining a tensor by passing the tensor itself
Defining a tensor by passing a tensorial equation
Automatic formatting of repeated tensor indices and handling of their collisions in products
Tensor symmetries
Substituting tensors and tensor indices
Simplifying tensorial expressions
Sum over repeated indices
Visualizing tensor components - Library:-TensorComponents and TensorArray
Modifying tensor components - Library:-RedefineTensorComponent
Using CompactDisplay to enhance the display of tensorial expressions involving tensor functions and derivatives
The LeviCivita tensor and KroneckerDelta
The 3D space metric and decomposing 4D tensors into their 3D space part and the rest
Total differentials, the d_[mu] and dAlembertian operators
Tensorial differential operators in algebraic expressions
Inert tensors
Functional differentiation of tensorial expressions with respect to tensor functions
The Pauli matrices and the spacetime Psigma[mu] 4-vector
The Dirac matrices and the spacetime Dgamma[mu] 4-vector
Quantum not-commutative operators using tensor notation
II. Curved spacetimes
Loading metrics from the database of solutions to Einstein's equations
Setting the spacetime metric indicating the line element or a Matrix
Covariant differentiation: the D_[mu] operator and the Christoffel symbols
The LeviCivita tensor in curved spacetimes and the determinant of the metric
The Einstein, Ricci, Riemann and Weyl tensors of General Relativity
The EnergyMomentum tensor
Killing vectors
Geodesics
A conversion network for the tensors of General Relativity
Tetrads and the local system of reference - the Newman-Penrose formalism
Differentiating the spacetime metric, the tetrad, and their determinants, with respect to each other
The ThreePlusOne package and the 3 + 1 splitting of Einstein's equations
III. Transformations of coordinates
This section contains the information needed to compute with tensors in Classical and Quantum Mechanics, Electrodynamics and Special Relativity, using the Physics package. This material is also relevant for computing with tensors in General Relativity, for which there is a dedicated Section II: Curved spacetimes.
Default metric and signature, coordinate systems
To load Physics enter
withPhysics
`*`,`.`,Annihilation,AntiCommutator,Antisymmetrize,Assume,Bra,Bracket,Check,Christoffel,Coefficients,Commutator,CompactDisplay,Coordinates,Creation,D_,Dagger,Decompose,Define,Dγ,Einstein,EnergyMomentum,Expand,ExteriorDerivative,Factor,FeynmanDiagrams,FeynmanIntegral,Fundiff,Geodesics,GrassmannParity,Gtaylor,Intc,Inverse,Ket,KillingVectors,KroneckerDelta,LagrangeEquations,LeviCivita,Library,LieBracket,LieDerivative,Normal,NumericalRelativity,Parameters,PerformOnAnticommutativeSystem,Projector,Psigma,Redefine,Ricci,Riemann,Setup,Simplify,SortProducts,SpaceTimeVector,StandardModel,Substitute,SubstituteTensor,SubstituteTensorIndices,SumOverRepeatedIndices,Symmetrize,TensorArray,Tetrads,ThreePlusOne,ToContravariant,ToCovariant,ToFieldComponents,ToSuperfields,Trace,TransformCoordinates,Vectors,Weyl,`^`,dAlembertian,d_,diff,g_,gamma_
By default, the spacetime metric is 4-dimensional, of Minkowski type, with the signature (- - - +). You can verify the metric, signature and dimension at any time in different ways, the simplest being:
g_
g_μ,ν=−10000−10000−100001
In Physics, everything is set up using the Setup command. Likewise, you can query one or several settings simultaneously using the same command, for example:
Setupcoordinates, dimension, signature,metric
_______________________________________________________
coordinatesystems=none,dimension=4,metric=1,1=−1,2,2=−1,3,3=−1,4,4=1,signature=- - - +
The dimension, signature and metric, as well as all other Physics settings, can also be changed using Setup and Redefine. For example, to change the default signature you can enter Setupsignature = `+++ -`. To change the signature, reorder the coordinates and the lines and columns in the metric all in one go enter Redefine⁡setall,tosignature=`+ + + -`. The five signatures understood by Physics are:
(- - - +), default.
(+ - - - ), same line element as a.
(+ + + -), used in the ThreePlusOne package and ADM formalism, and in the database of exact solutions to Einstein equations.
(- + + +), same line element as c.
(+ + + +), used to set a Euclidean spacetime.
These signatures generalize naturally when you change the spacetime dimension.
In a flat spacetime, the value of the signature defines the signs in the line element
g_lineelement;
⁢Systems of spacetime coordinates are:⁢X=x1,x2,x3,x4
−ⅆ⁡x12−ⅆ⁡x22−ⅆ⁡x32+ⅆ⁡x42
In a curved spacetime you can always define, at any point, a local system of reference of Minkowski type, also referred to in Maple as the tetrad system. The value of the signature defines the line element in that local system of reference.
The signature also indicates the position of the time-like component
Library:-PositionOfTimelikeComponent;
4
and therefore the ordering of lines and columns in the matrix representation of the metric (2).
To redefine a metric, the coordinates, or both according to a change you make in the signature you can use Setup or, more simply, use the Redefine command.
You can also visualize and change all the Physics settings at once using the Setup applet, launched entering Setup⁡. The following image shows the left half of that applet.
Setup
A coordinate system is not set by default when you load the package. You can set it by indicating an uppercase letter that will work as a label representing the sequence of the four coordinates (this is internally implemented using alias).
Setupcoordinates = X
coordinatesystems=X
For historical reasons, to set coordinate systems there is also the Coordinates command, which can be used for the same purpose as Setup.
Setting a coordinate system is necessary when computing with curved spacetimes in order to compute the derivatives of the metric that enter the Christoffel symbols, which are then used to compute the components of all the general relativity tensors - an operation performed in the background, automatically, when you define the metric.
In a flat spacetime setting a coordinates system is optional, although it can be useful for different purposes as explained below.
The coordinates of the first system of coordinates you set are used by the d_, D_ and dAlembertian commands as the default differentiation variables.
You can define several coordinates systems at the same time
Setupcoordinates = Y
⁢Systems of spacetime coordinates are:⁢X=x1,x2,x3,x4,Y=y1,y2,y3,y4
coordinatesystems=X,Y
To change the coordinates used by the differential operators d_, D_ and dAlembertian, for example from X to Y, enter Setup⁡differentiationvariables=Y.
All the coordinates of coordinates systems that are defined using Setup or Coordinates are automatically assumed to be real, so coulditbe, is and getassumptions, and through them all the Maple library, know about the coordinates' properties
getassumptionsx2
x2::real
Often one works with Cartesian, spherical or cylindrical coordinates. These three keywords are understood by Setup and, when using any of them, you can, but do not need to, specify the label representing the coordinates. In that case, the label of the differentiation coordinates system is reused. If no coordinates system is defined then X is used. You can thus also set the coordinates via
Setupcoordinates = spherical
⁢Default differentiation variables for d_, D_ and dAlembertian are:⁢X=r,θ,φ,t
⁢Systems of spacetime coordinates are:⁢X=r,θ,φ,t,Y=y1,y2,y3,y4
Note that the coordinate t, complementing the three spherical coordinates, is positioned according to the signature (- - - +). To change the signature, see Setup. In the case of spherical and cylindrical coordinates, the assumptions automatically placed on them are the expected ones:
mapgetassumptions,X
r::0,∞,θ::0,π,φ::0,2⁢π,t::0,∞
Finally, you can also specify any coordinates to constitute a coordinates system and, in doing so, you can also redefine a previously used label. For example:
Setupcoordinates = X=u,v,w,t,Z=z__1,z__2,z__3,z__4
⁢Systems of spacetime coordinates are:⁢X=u,v,w,t,Y=y1,y2,y3,y4,Z=z__1,z__2,z__3,z__4
coordinatesystems=X,Y,Z
When the coordinates you define have specific geometrical meaning, e.g. (10), you can indicate that using the Assume command so that any restriction in their range is automatically taken into account, for example, when simplifying expressions.
Different uses of a coordinates system label
Due to the use of alias, the label of a coordinate system - say X - actually represents the sequence of the four coordinates, and so you can use this label to refer to all the coordinates at once, for example, when specifying the functionality of functions
FX
F⁡X
where FXis a function of four variables. You can check the number of its operands, or get any one of its variables via
nops
op4,FX
t
It is often useful to avoid a redundant display of the coordinate's dependencyXin functions. For that purpose use CompactDisplay.
CompactDisplayFX
F⁡u,v,w,t⁢will now be displayed as⁢F
The dependency of FXis now omitted from the display
In Maple, the indices of tensors are represented through normal indexing []. Thus you can use the label of a coordinates system to represent the SpaceTimeVector
Xmu
Xμ
In the context of Physics, contravariant indices are entered preceded by ~
X~mu
X⁢μ⁢μ
The distinction between covariant and contravariant indices is relevant in non-Euclidean spacetimes (you can set the spacetime to be Euclidean by entering Setup⁡metric=Euclidean). For example, in a flat Minkowski spacetime, when summing over the repeated indices of tensorial expressions (see SumOverRepeatedIndices)
Xmu2
Xμ⁢X⁢μ⁢μ
SumOverRepeatedIndices
t2−u2−v2−w2
Defining more than one coordinates system is also convenient when transforming coordinates using the TransformCoordinates command, as explained in the next sections.
Tensors: their definition, symmetries and operations
Physics comes with a set of predefined tensors, mainly the spacetime metric gμ,ν, the space metric γj,k, and all the standard tensors of General Relativity. To check their definition, index the tensor with the keyword definition, for example: γdefinition. In addition, one of the strengths of Physics is that you can define tensors, in natural ways, by indicating a matrix or array with its components, or by indicating any generic tensorial expression involving other tensors.
In Maple tensor indices are letters, lowercase or uppercase, Latin or Greek, just like when computing with paper and pencil. The indices are entered using indexation, as in Amu, and are displayed as subscripts as in Aμ. To change or set the kind of letter (greek, lowercaselatin, etc.) used to represent a kind of index (spacetime, space, etc.) see Setup.
Contravariant indices are entered with ~ preceding the letter, as in A~mu, and are displayed as superscripts, as in A⁢μ⁢μ. You can work with two or more kinds of indices at the same time, e.g., spacetime and space indices.
To input Greek letters you can spell them, as in mu for μ, or simpler: use the shortcuts for entering Greek characters. Right-click your input and choose Convert To → 2-D Math input to give your spelled tensorial expression a textbook high-quality typesetting.
However, not every indexed object or function is automatically a tensor. You need to define it as such first with the Define command. You can do that in two ways:
Passing the tensor being defined, say Fμ,ν, to the Define command, possibly indicating symmetries and/or antisymmetries for its indices.
Passing a tensorial equation where the left-hand side is the tensor being defined, as in item 1., and the right-hand side is a tensorial expression - or an Array or Matrix - such that the components of the tensor being defined become equal to the components of the tensorial expression.
After defining a tensor, say Fμ,ν, you can perform the following operations on algebraic expressions involving it:
Automatic formatting of repeated indices, one covariant the other contravariant
Automatic handling of collisions of repeated indices in products of tensors
Simplify products using Einstein's sum rule for repeated indices
SumOverRepeatedIndices of the tensorial expression
Use TensorArray to compute the expression's components
TransformCoordinates
If you define a tensor using a tensorial equation you can additionally:
Get each tensor component by indexing, as in A1 or A⁢1⁢1
Get all the covariant and contravariant components by respectively using the shortcut notation A and A~
Use any of the special indexing keywords valid for the pre-defined tensors of Physics. They are definition, nonzero, and for tensors with 2 indices also trace and determinant
Forgo specifying the tensor dependency for differentiation purposes - it is inferred automatically from its definition
Redefine any particular tensor component using Library:-RedefineTensorComponent
Minimizing the number of independent tensor components using Library:-MinimizeTensorComponent
Compute the number of independent tensor components - relevant for tensors with many indices and different symmetries - using Library:-NumberOfTensorComponents
The following sections showcase these two ways of defining a tensor, the features described above, and the basic functionality in the Physics package for computing with tensors.
The simplest way to define a spacetime or any other type of tensor is passing the tensor itself as a name indexed by one or several indices of the corresponding type.
By default, spacetime indices are represented by Greek letters
restart;withPhysics:Setupspacetimeindices
spacetimeindices=greek
To change the type of letter used for a kind of index see Setup. Therefore, the simplest way to define a spacetime tensor is, for instance
DefineAmu
Defined objects with tensor properties
Aμ,γμ,σμ,∂μ,gμ,ν,εα,β,μ,ν
The output of Define is always a set with all the tensors defined so far (it includes the predefined tensors, and all the coordinates systems as SpaceTimeVectors). To avoid the verbosity of Define's output use the quiet option.
To clear a tensor definition, like the one above, enter Defineclear, A.
Once Aμ is defined as a tensor you can refer to any of its components by indexing with the corresponding covariant or contravariant number
A1
A~1
A⁢1⁢1
To retrieve all the components at once you can use TensorArray or Library:-TensorComponents, the respective output will be an Array or a list
TensorArrayAmu
A1A2A3A4
Library:-TensorComponentsA~mu
A⁢1⁢1,A⁢2⁢2,A⁢3⁢3,A⁢4⁢4
When the spacetime is not Euclidean the repeated indices are automatically reformatted: one covariant the other contravariant
Amu g_mu,nu
gμ,ν⁢A⁢μ⁢μ
When the automatic choice of which one is contravariant is not the one you prefer, you can indicate your preference by using ~ for the contravariant one
Amu g_~mu,nu
Aμ⁢g_ν,~mu
Tensorial expressions, i.e. expressions that have any of the predefined tensors of Physics or tensors defined by you using Define, can be simplified using Simplify. That simplification takes into account the symmetry properties of tensorial subexpressions and makes use of the sum rule for repeated indices
Simplify
Aν
Repeated indices - some or all - can be summed over using SumOverRepeatedIndices
g1,ν⁢A⁢1⁢1+g2,ν⁢A⁢2⁢2+g3,ν⁢A⁢3⁢3+g4,ν⁢A⁢4⁢4
Recalling the current value of the metric
a tensor array with the components of, for example, the relationship Aν=gμ,ν⁢A⁢μ⁢μ, can be computed using TensorArray
TensorArray⁡Aν=gμ,ν⁢A⁢μ⁢μ
A1=−A~1A2=−A~2A3=−A~3A4=A~4
Note the textbook typesetting of the input above. That input line includes subscripts and superscripts for the tensor indices. You can achieve this input with typesetting by entering the expression using standard Maple notation, as in: TensorArrayAnu = g_mu, nu A~mu, then right-clicking the expression and following the pop-up menu 2-D Math → Convert To → 2-D Math input. This is particularly useful:
when the input and output are the same so you can terminate the input with : to avoid displaying the output,
when the input without typesetting is not easy to read/understand
for presentation purposes.
When you perform a coordinate transformation, tensors change according to specific rules. For that purpose, start by setting two coordinate systems, as shown in the previous section
CoordinatesX=u,v,w,t,Z=z__1,z__2,z__3,z__4
⁢Systems of spacetime coordinates are:⁢X=u,v,w,t,Z=z__1,z__2,z__3,z__4
X,Z
You can now transform coordinates using TransformCoordinates, for example from X to Z usingu=z__1+z__2,v=z__1−z__2, as follows:
tr ≔ u=z__1+z__2,v=z__1−z__2:
TransformCoordinatestr, Amu
A1+A2A1−A2A3A4
Note the different transformation rule for the covariant components (above) and the contravariant ones:
TransformCoordinatestr, A~mu
12⁢A~1+12⁢A~212⁢A~1−12⁢A~2A~3A~4
Tensors defined by passing a tensorial equation have all the features mentioned in the previous section, which enable you to Simplify, SumOverRepeatedIndices, TensorArray, and TransformCoordinates, as well as several additional ones.
A simple example is that of a 4-vector. This time, we also want to specify its components. You can indicate them in a list on the right-hand side of the definition
Definepμ = p__x,p__y,p__z,Ec
Aμ,γμ,σμ,∂μ,gμ,ν,pμ,εα,β,μ,ν,Xμ,Zμ
On the right-hand side of the definition you can also use a Vector construction, as in p__x,p__y,p__z,Ec, or a Matrix. See Define for all the possible ways you can use to indicate the components.
Having defined p passing a tensorial equation, you can now get each of its components via indexing
p1
p__x
p0
Ec
Note that the value 0 of the index points to the position of the timelike component, that is, the position of the different sign in the signature. You can query that using Setup
Setupsignature
signature=- - - +
or Library:-PositionOfTimelikeComponent
Library:-PositionOfTimelikeComponent
When the tensor is defined using a tensorial equation and a coordinates system is set you can also use the coordinates as tensor indices to select tensor components. For example,
Setupcoordinates = cartesian, usecoordinates = true
* Partial match of 'usecoordinates' against keyword 'usecoordinatesastensorindices'
⁢Default differentiation variables for d_, D_ and dAlembertian are:⁢X=x,y,z,t
⁢Systems of spacetime coordinates are:⁢X=x,y,z,t,Z=z__1,z__2,z__3,z__4
coordinatesystems=X,Z,usecoordinatesastensorindices=true
p1 = px
p__x=p__x
p4 = pt
Ec=Ec
You can get all the covariant and contravariant components by respectively using the following shortcut notation
p
pμ=p__xp__yp__zEc
p~
p~mu=−p__x−p__y−p__zEc
The indexing keywords valid for all the pre-defined tensors of Physics, definition, determinant, nonzero, and trace, can also be used for tensors you define using tensorial equations
pdefinition
pμ=p__x,p__y,p__z,Ec
pnonzero
pμ=1=p__x,2=p__y,3=p__z,4=Ec
The trace and determinant keywords are only for tensors with two indices. To illustrate this, first define a tensor by indicating a 2x2 generic matrix
Fmu,nu = Matrix4,symbol=F
Fμ,ν=F1,1F1,2F1,3F1,4F2,1F2,2F2,3F2,4F3,1F3,2F3,3F3,4F4,1F4,2F4,3F4,4
Define
Aμ,γμ,Fμ,ν,σμ,∂μ,gμ,ν,pμ,εα,β,μ,ν,Xμ,Zμ
F~
F~mu,~nu=F1,1F1,2F1,3−F1,4F2,1F2,2F2,3−F2,4F3,1F3,2F3,3−F3,4−F4,1−F4,2−F4,3F4,4
Fmu,mu = Ftrace
Fμμμμ=−F1,1−F2,2−F3,3+F4,4
Fdeterminant
F1,1⁢F2,2⁢F3,3⁢F4,4−F1,1⁢F2,2⁢F3,4⁢F4,3−F1,1⁢F2,3⁢F3,2⁢F4,4+F1,1⁢F2,3⁢F3,4⁢F4,2+F1,1⁢F2,4⁢F3,2⁢F4,3−F1,1⁢F2,4⁢F3,3⁢F4,2−F1,2⁢F2,1⁢F3,3⁢F4,4+F1,2⁢F2,1⁢F3,4⁢F4,3+F1,2⁢F2,3⁢F3,1⁢F4,4−F1,2⁢F2,3⁢F3,4⁢F4,1−F1,2⁢F2,4⁢F3,1⁢F4,3+F1,2⁢F2,4⁢F3,3⁢F4,1+F1,3⁢F2,1⁢F3,2⁢F4,4−F1,3⁢F2,1⁢F3,4⁢F4,2−F1,3⁢F2,2⁢F3,1⁢F4,4+F1,3⁢F2,2⁢F3,4⁢F4,1+F1,3⁢F2,4⁢F3,1⁢F4,2−F1,3⁢F2,4⁢F3,2⁢F4,1−F1,4⁢F2,1⁢F3,2⁢F4,3+F1,4⁢F2,1⁢F3,3⁢F4,2+F1,4⁢F2,2⁢F3,1⁢F4,3−F1,4⁢F2,2⁢F3,3⁢F4,1−F1,4⁢F2,3⁢F3,1⁢F4,2+F1,4⁢F2,3⁢F3,2⁢F4,1
To work with the determinant without having it computed you can use the inert version of the tensor and activate the computation only when that is desired using value
%Fdeterminant
value
The matrix keyword shows the matrix form that corresponds to the indicated indices, which is particularly useful when the indices are a mixture of covariant and contravariant
F~mu,nu,matrix
F~mu,ν=−F1,1−F1,2−F1,3−F1,4−F2,1−F2,2−F2,3−F2,4−F3,1−F3,2−F3,3−F3,4F4,1F4,2F4,3F4,4
All these keywords work the same way in the case of a curved spacetime.
You can redefine any tensor component using Library:-RedefineTensorComponent, for example redefine F2,1=−F1,2
Library:-RedefineTensorComponentF2,1 = −F1,2
Fμ,ν=F1,1F1,2F1,3F1,4−F1,2F2,2F2,3F2,4F3,1F3,2F3,3F3,4F4,1F4,2F4,3F4,4
When you define a tensor you can also minimize the number of its independent components all in one go. Consider for instance redoing the definition of Fμ,ν, this time indicating that it is antisymmetric and minimizing the amount of independent components by taking that fact into account
Define, antisymmetric, minimizetensorcomponents
F
Fμ,ν=0F1,2F1,3F1,4−F1,20F2,3F2,4−F1,3−F2,30F3,4−F1,4−F2,4−F3,40
Library:-NumberOfIndependentTensorComponentsF
6
Defining tensors that represent tensorial expressions
One of the most useful features of defining tensors using tensorial equations is that the right-hand side of the equation can be any desired tensorial expression, not just a list or table of components. For example, at this point we have defined the tensor Aμ
Library:-TensorComponentsAμ
A1,A2,A3,A4
Taking Aμ to represent the 4D potential in electrodynamics, the corresponding electromagnetic field is
Fmu,nu = 2⋅ Antisymmetrized_muAnuX
Fμ,ν=∂μ⁡Aν⁡X−∂ν⁡Aμ⁡X
To have a compact display that avoids redundancy use CompactDisplay
CompactDisplayAX
A⁡x,y,z,t⁢will now be displayed as⁢A
Now redo the definition of Fμ,ν using (62)
Defineredo,,minimizetensorcomponents
Fμ,ν=0∂∂x⁢A2⁡x,y,z,t−∂∂y⁢A1⁡x,y,z,t∂∂x⁢A3⁡x,y,z,t−∂∂z⁢A1⁡x,y,z,t∂∂x⁢A4⁡x,y,z,t−∂∂t⁢A1⁡x,y,z,t∂∂y⁢A1⁡x,y,z,t−∂∂x⁢A2⁡x,y,z,t0∂∂y⁢A3⁡x,y,z,t−∂∂z⁢A2⁡x,y,z,t∂∂y⁢A4⁡x,y,z,t−∂∂t⁢A2⁡x,y,z,t∂∂z⁢A1⁡x,y,z,t−∂∂x⁢A3⁡x,y,z,t∂∂z⁢A2⁡x,y,z,t−∂∂y⁢A3⁡x,y,z,t0∂∂z⁢A4⁡x,y,z,t−∂∂t⁢A3⁡x,y,z,t∂∂t⁢A1⁡x,y,z,t−∂∂x⁢A4⁡x,y,z,t∂∂t⁢A2⁡x,y,z,t−∂∂y⁢A4⁡x,y,z,t∂∂t⁢A3⁡x,y,z,t−∂∂z⁢A4⁡x,y,z,t0
Note that the derivatives - constructed using the diff command - are compactly displayed in index notation. Another common situation where defining a tensor by using a tensorial expression is useful is constructing a traceless tensor from a given one. For example, in the case of a tensor with 2 indices Cα,β,
Cα,β=Matrix4,symbol=C
Cα,β=C1,1C1,2C1,3C1,4C2,1C2,2C2,3C2,4C3,1C3,2C3,3C3,4C4,1C4,2C4,3C4,4
Aμ,Cα,β,γμ,Fμ,ν,σμ,∂μ,gμ,ν,pμ,εα,β,μ,ν,Xμ,Zμ
Tα, β = Cα, β − Cμ,μ⋅g_α, β4
Tα,β=Cα,β−gα,β⁢Cμμμμ4
Aμ,Cα,β,γμ,Fμ,ν,σμ,Tα,β,∂μ,gμ,ν,pμ,εα,β,μ,ν,Xμ,Zμ
T
Tμ,ν=34⁢C1,1−14⁢C2,2−14⁢C3,3+14⁢C4,4C1,2C1,3C1,4C2,134⁢C2,2−14⁢C1,1−14⁢C3,3+14⁢C4,4C2,3C2,4C3,1C3,234⁢C3,3−14⁢C1,1−14⁢C2,2+14⁢C4,4C3,4C4,1C4,2C4,334⁢C4,4+14⁢C1,1+14⁢C2,2+14⁢C3,3
Talpha, alpha = Ttrace
Tαααα=0
The distinction between covariant and contravariant indices in the input of tensors is made by prefixing contravariant indices with ~, as in ~mu. In the output, contravariant indices are displayed as superscripts. However, for contracted tensor indices it is not relevant which one is covariant and which one contravariant. Taking advantage of that, contracted indices can both be entered (input) as covariant, in which case they will be automatically rewritten as one covariant and one contravariant. You can override this behavior by indicating which index you want to be contravariant in the output
restart;withPhysics:
Define two tensors
DefineAmu, Bmu
Aμ,Bμ,γμ,σμ,∂μ,gμ,ν,εα,β,μ,ν
The contraction of A with itself and with B can be entered with all repeated indices as covariant - the output shows these indices reformatted appropriately
Amu2
Aμ⁢A⁢μ⁢μ
Amu Bmu
Aμ⁢B⁢μ⁢μ
Entering all the repeated indices as covariant not only removes the burden of having to type one index as contravariant each time there is a contraction, it also automatically results in a normal form for a contraction that the system remembers, so the indices are always reformatted in the same way.
In cases where the choice, made by the system, of which index is contravariant is not the one you prefer, you can override the system's choice by indicating your preference using ~ to prefix the contravariant index. For example
A~mu Bmu
A⁢μ⁢μ⁢Bμ
Automatic handling of collisions of contracted indices in products Consider two tensorial expressions, say E__1 and E__2, that have the same contracted indices, for example (74) and (75)
E__1 ≔
E__1≔Aμ⁢B⁢μ⁢μ
E__2 ≔
E__2≔A⁢μ⁢μ⁢Bμ
If you multiply E__1⋅E__2 there shouldn't be any problem. However, from the point of view of the summation rule for repeated indices the index μ would be repeated four times, which is incorrect; we say this is a case of collision of indices in products. These cases are handled automatically by replacing the (dummy) repeated indices in one of the factors such that every contracted index is repeated only once. For example, we see in the following input/output that the repeated index μ in E__2 is replaced by ν
E__1 ⋅ E__2
Aμ⁢B⁢μ⁢μ⁢A⁢ν⁢ν⁢Bν
This expression now has two pairs of repeated indices and checks out
Check
The repeated and free indices in the given expression check ok.
Therefore, multiplying it by itself should not be a problem
2
Aμ⁢B⁢μ⁢μ⁢A⁢ν⁢ν⁢Bν⁢Aα⁢B⁢α⁢α⁢A⁢β⁢β⁢Bβ
Note that a collision of indices in products can also happen between a free index in one factor and a repeated index in another factor. Those cases are also handled automatically, for example
E__1
Amu ⋅ E__1
Aμ⁢Aν⁢B⁢ν⁢ν
When introducing replacements to resolve the collision of repeated indices in products, special care is taken such that the introduced indices:
are of the same kind as the ones being replaced;
were not already present in the expression where they are being introduced;
To prevent the system from introducing a certain index, say ν, before multiplying E__1⋅E__2 you can assign it to _Env_Physics_indices_in_use
_Env_Physics_indices_in_use ≔ nu
_Env_Physics_indices_in_use≔ν
Now you have
Aμ⁢B⁢μ⁢μ⁢A⁢α⁢α⁢Bα
_Env_Physics_indices_in_use ≔ nu, alpha
_Env_Physics_indices_in_use≔ν,α
Aμ⁢B⁢μ⁢μ⁢A⁢β⁢β⁢Bβ
Your definition of a tensor can include symmetries and antisymmetries for its indices. For a totally symmetric or antisymmetric tensor it suffices to add the corresponding keyword symmetric or antisymmetric.
DefineBmu,nu, symmetric
Bμ,ν,γμ,σμ,∂μ,gμ,ν,εα,β,μ,ν
When defining a tensor this way, without passing a tensorial equation or the keyword minimizetensorcomponents, the symmetry indicated is not automatically taken into account. That allows for further abstract manipulations, and when you want the symmetry to be taken into account you can use Simplify
Bmu,nu − Bnu,mu
Bμ,ν−Bν,μ
0
Alternatively, by passing the keyword minimizetensorcomponents the symmetry indicated is automatically taken into account
DefineBmu,nu, symmetric,minimizetensorcomponents
Consider now a tensor with four indices Rα,β,μ,ν which has the symmetries of the Riemann tensor. This tensor is antisymmetric with respect to interchanging the positions ofα↔β or μ↔ν, and symmetric with respect to interchanging the positions of the 1st and 2nd pairs of indicesα,β ↔ μ,ν. You can indicate these symmetries by specifying the indices themselves or their numerical position
DefineRα,β,μ,ν, symmetric = α,β, μ,ν, antisymmetric = α,β,μ,ν
Bμ,ν,γμ,σμ,Rα,β,μ,ν,∂μ,gμ,ν,εα,β,μ,ν
To retrieve the symmetries of a tensor, use Library:-GetTensorSymmetryProperties
Library:-GetTensorSymmetryPropertiesR
1,2,3,4,1,2,3,4
Redoing the definition of Rα,β,μ,ν, this time using minimizetensorcomponents, allows, among other things, for counting of the number of independent components of R
DefineRα,β,μ,ν, symmetric = α,β, μ,ν, antisymmetric = α,β,μ,ν,minimizetensorcomponents
Bμ,ν,γμ,σμ,Rμ,ν,α,β,∂μ,gμ,ν,εα,β,μ,ν
Out of the 44=256 components only 21 are independent, due to the symmetries indicated
Library:-NumberOfIndependentTensorComponentsR
21
In the case of the Riemann tensor, taking into account the first Bianchi identity, this number is further reduced to 20.
Traceless tensors
As previously mentioned, you can use tensorial equations to define tensors representing arbitrary tensorial expressions that involve other tensors. A more advanced example of that is the construction of a traceless version of Rα,β,μ,ν, the tensor with the symmetries of the Riemann tensor defined in the previous section. For this tensor, the sum over any possible pair of repeated indices (contraction of two indices) returns 0. The formula used is the same as the one used to define the Weyl tensor in terms of the Riemann and Ricci tensors
Weyldefinition
Cα,β,μ,ν=Rα,β,μ,ν−Rα,μ⁢gβ,ν2+Rα,ν⁢gβ,μ2+Rβ,μ⁢gα,ν2−Rβ,ν⁢gα,μ2+gα,μ⁢gβ,ν6−gα,ν⁢gβ,μ6⁢Rκκκκ
Converting it to Riemann, without evaluating tensors, and substituting Riemann with R and Weyl with W, you get
subsRiemann=R, Weyl=W,convertWeyldefinition,Riemann,only=Ricci,evaluatetensor=false
Wα,β,μ,ν=Rα,β,μ,ν−R⁢κα,κ,μ⁢κα,κ,μ⁢gβ,ν2+R⁢κα,κ,ν⁢κα,κ,ν⁢gβ,μ2+R⁢κβ,κ,μ⁢κβ,κ,μ⁢gα,ν2−R⁢κβ,κ,ν⁢κβ,κ,ν⁢gα,μ2+gα,μ⁢gβ,ν6−gα,ν⁢gβ,μ6⁢R⁢λκ,λκ⁢λκ,λκ
Now define Wα,β,μ,ν using this tensorial equation
Define, minimizetensorcomponents
Bμ,ν,γμ,σμ,Rμ,ν,α,β,Wα,β,μ,ν,∂μ,gμ,ν,εα,β,μ,ν
While the number of independent components of R is 21, W only has the expected 10 and is traceless
Library:-NumberOfIndependentTensorComponentsW
10
W⁢αα,μ,ν⁢αα,μ,ν
Symmetrization and Antisymmetrization of tensors
You can create new tensorial expressions by symmetrizing or antisymmetrizing existing tensors or tensorial expressions, with respect to all or part of their free indices. The resulting tensorial expressions can be used to define new tensors with the corresponding symmetries. For example, construct a tensorial expression by symmetrizing Wα,β,μ,ν with respect to α↔μ and antisymmetrizing the result with respect to β↔μ, then define a new tensor Uα,β,μ,ν using the resulting tensorial expression. Note that Uα,β,μ,ν will also have the symmetries and tracelessness of Wα,β,μ,ν.
Symmetrize⁡Wα,β,μ,ν,α,μ
Wα,β,μ,ν2−Wβ,μ,α,ν2
Uα,β,μ,ν=Antisymmetrize,β,μ
Uα,β,μ,ν=Wα,β,μ,ν4−Wβ,μ,α,ν2−Wα,μ,β,ν4
Define,minimizetensorcomponents
Bμ,ν,γμ,σμ,Rμ,ν,α,β,Uα,β,μ,ν,Wα,β,μ,ν,∂μ,gμ,ν,εα,β,μ,ν
The number of independent tensor components of Uα,β,μ,ν is
Library:-NumberOfIndependentTensorComponentsU
8
Two common operations with tensorial expressions are substituting tensors and substituting tensor indices. The Physics commands for these purposes are SubstituteTensor and SubstituteTensorIndices.
restart; withPhysics:
DefineA,B,C,F,G
A,B,C,F,G,γμ,σμ,∂μ,gμ,ν,εα,β,μ,ν
EQ≔Aμ=Gν,α⁢Aα⁢Fμ,ν
EQ≔Aμ=Gν,α⁢A⁢α⁢α⁢Fμνμν
The repeated and free indices of the left and right-hand sides of this equation are
Check⁡EQ,all
The repeated indices per term are: ...,...,..., the free indices are: ...
∅,μ=α,ν,μ
The easy case: using EQ to substitute Aμin Aμ itself
SubstituteTensor⁡EQ,Aμ
Gν,α⁢A⁢α⁢α⁢Fμνμν
The same operation, but now the free index in the target expression is ν instead of μ
SubstituteTensor⁡EQ,Aν
Gβ,α⁢A⁢α⁢α⁢Fνβνβ
The same operation, but now the target is A⁢ν⁢ν
SubstituteTensor⁡EQ,A⁢ν⁢ν
Gβ,α⁢A⁢α⁢α⁢F⁢ν,β⁢ν,β
An example where the index ν, which is repeated in the right-hand side of EQ, is also repeated in the target expression:
ee≔Aν⁢Aν
ee≔Aν⁢A⁢ν⁢ν
The collision of indices is resolved automatically
res≔SubstituteTensor⁡EQ,ee
res≔Gλ,κ⁢A⁢κ⁢κ⁢Fνλνλ⁢Gβ,α⁢A⁢α⁢α⁢F⁢ν,β⁢ν,β
The repeated and free indices of this result are
Check⁡res,all
α,β,κ,λ,ν,∅
The functionality of tensor functions is also considered a parameter when substituting tensors. For example, consider the following substitution equation
EQ__2 ≔ Aμ⁡X=Bμ⁡X
EQ__2≔Aμ⁡X=Bμ⁡X
Now substitute in Aν⁡Y
SubstituteTensorEQ__2, AνY
Bν⁡Y
SubstituteTensor also substitutes sub-expressions like algsubs. For example
EQ__3≔AμX⁢BνY=Gμ,νX
EQ__3≔Aμ⁡X⁢Bν⁡Y=Gμ,ν⁡X
The target expression is
AαX⁢BβY⁢AρX⁢BρY
Aα⁡X⁢Bβ⁡Y⁢Aρ⁡X⁢B⁢ρ⁢ρ⁡Y
When substituting EQ__3 into (118), the sub-expression A⁢⋅B appears twice, once with repeated indices and once without, and is not part of the indeterminates of (118)
indets⁡
X,Y,Aα⁡X,Aρ⁡X,Bβ⁡Y,B⁢ρ⁢ρ⁡Y
SubstituteTensorEQ__3,
Gα,β⁡X⁢Gρρρρ⁡X
Tensor indices can be substituted in a similar way
Consider the following target tensorial expression
ee__1 ≔ g_α,μ⁢A~mu⁢g_~alpha,~nu⁢Cν,σ,~rho
ee__1≔gα,μ⁢A⁢μ⁢μ⁢g⁢α,ν⁢α,ν⁢Cν,σρν,σρ
Checkee__1,all
α,μ,ν,σ,~rho
Substitute the repeated index α that appears in covariant and contravariant forms in ee__1
SubstituteTensorIndicesα=β, ee__1
gβ,μ⁢A⁢μ⁢μ⁢g⁢β,ν⁢β,ν⁢Cν,σρν,σρ
Now substitute the contravariant index ~ρ= ~β : a) you don't need to prefix contravariant indices with ~ in the substitution equations; and b) the index β already exists as a dummy (repeated) index in the target expression; you don't need to be concerned with that, this kind of collision of indices is also handled automatically
SubstituteTensorIndicesρ = β,ee__1
gα,μ⁢A⁢μ⁢μ⁢g⁢α,ν⁢α,ν⁢Cν,σβν,σβ
To substitute several indices at once, enclose the substitution equations in a set or a list
SubstituteTensorIndices⁡ρ=β,α=γ,ee__1
gγ,μ⁢A⁢μ⁢μ⁢