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
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
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
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
I. Spacetime and tensors in Physics
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
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:
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
⁢Systems of spacetime coordinates are:⁢X=x1,x2,x3,x4
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
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.
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
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
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
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:
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
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
where FXis a function of four variables. You can check the number of its operands, or get any one of its variables via
It is often useful to avoid a redundant display of the coordinate's dependencyXin functions. For that purpose use CompactDisplay.
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
In the context of Physics, contravariant indices are entered preceded by ~
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)
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
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
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
Defined objects with tensor properties
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
To retrieve all the components at once you can use TensorArray or Library:-TensorComponents, the respective output will be an Array or a list
When the spacetime is not Euclidean the repeated indices are automatically reformatted: one covariant the other contravariant
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
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
Repeated indices - some or all - can be summed over using SumOverRepeatedIndices
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
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
⁢Systems of spacetime coordinates are:⁢X=u,v,w,t,Z=z__1,z__2,z__3,z__4
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:
Note the different transformation rule for the covariant components (above) and the contravariant ones:
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
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
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
signature=- - - +
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
p1 = px
p4 = pt
You can get all the covariant and contravariant components by respectively using the following shortcut notation
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
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
Fmu,mu = Ftrace
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
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
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
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
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μ
Taking Aμ to represent the 4D potential in electrodynamics, the corresponding electromagnetic field is
Fmu,nu = 2⋅ Antisymmetrized_muAnuX
To have a compact display that avoids redundancy use CompactDisplay
A⁡x,y,z,t⁢will now be displayed as⁢A
Now redo the definition of Fμ,ν using (62)
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α,β,
Tα, β = Cα, β − Cμ,μ⋅g_α, β4
Talpha, alpha = Ttrace
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
Define two tensors
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
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
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)
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
This expression now has two pairs of repeated indices and checks out
The repeated and free indices in the given expression check ok.
Therefore, multiplying it by itself should not be a problem
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
Amu ⋅ E__1
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
Now you have
_Env_Physics_indices_in_use ≔ nu, alpha
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.
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
Alternatively, by passing the keyword minimizetensorcomponents the symmetry indicated is automatically taken into account
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 = α,β,μ,ν
To retrieve the symmetries of a tensor, use Library:-GetTensorSymmetryProperties
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
Out of the 44=256 components only 21 are independent, due to the symmetries indicated
In the case of the Riemann tensor, taking into account the first Bianchi identity, this number is further reduced to 20.
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
Converting it to Riemann, without evaluating tensors, and substituting Riemann with R and Weyl with W, you get
Now define Wα,β,μ,ν using this tensorial equation
While the number of independent components of R is 21, W only has the expected 10 and is traceless
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α,β,μ,ν.
The number of independent tensor components of Uα,β,μ,ν is
Two common operations with tensorial expressions are substituting tensors and substituting tensor indices. The Physics commands for these purposes are SubstituteTensor and SubstituteTensorIndices.
The repeated and free indices of the left and right-hand sides of this equation are
The repeated indices per term are: ...,...,..., the free indices are: ...
The easy case: using EQ to substitute Aμin Aμ itself
The same operation, but now the free index in the target expression is ν instead of μ
The same operation, but now the target is A⁢ν⁢ν
An example where the index ν, which is repeated in the right-hand side of EQ, is also repeated in the target expression:
The collision of indices is resolved automatically
The repeated and free indices of this result are
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
Now substitute in Aν⁡Y
SubstituteTensor also substitutes sub-expressions like algsubs. For example
The target expression is
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
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
Substitute the repeated index α that appears in covariant and contravariant forms in ee__1
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
To substitute several indices at once, enclose the substitution equations in a set or a list