 Tensors - a complete guide - Maple Help

Home : Support : Online Help : Physics : Tensors - a complete guide

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.

 a
 d
 5

 15
 16
 17 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

 > $\mathrm{with}\left(\mathrm{Physics}\right)$
 $\left[{\mathrm{*}}{,}{\mathrm{.}}{,}{\mathrm{Annihilation}}{,}{\mathrm{AntiCommutator}}{,}{\mathrm{Antisymmetrize}}{,}{\mathrm{Assume}}{,}{\mathrm{Bra}}{,}{\mathrm{Bracket}}{,}{\mathrm{Check}}{,}{\mathrm{Christoffel}}{,}{\mathrm{Coefficients}}{,}{\mathrm{Commutator}}{,}{\mathrm{CompactDisplay}}{,}{\mathrm{Coordinates}}{,}{\mathrm{Creation}}{,}{\mathrm{D_}}{,}{\mathrm{Dagger}}{,}{\mathrm{Decompose}}{,}{\mathrm{Define}}{,}{\mathrm{Dγ}}{,}{\mathrm{Einstein}}{,}{\mathrm{EnergyMomentum}}{,}{\mathrm{Expand}}{,}{\mathrm{ExteriorDerivative}}{,}{\mathrm{Factor}}{,}{\mathrm{FeynmanDiagrams}}{,}{\mathrm{FeynmanIntegral}}{,}{\mathrm{Fundiff}}{,}{\mathrm{Geodesics}}{,}{\mathrm{GrassmannParity}}{,}{\mathrm{Gtaylor}}{,}{\mathrm{Intc}}{,}{\mathrm{Inverse}}{,}{\mathrm{Ket}}{,}{\mathrm{KillingVectors}}{,}{\mathrm{KroneckerDelta}}{,}{\mathrm{LagrangeEquations}}{,}{\mathrm{LeviCivita}}{,}{\mathrm{Library}}{,}{\mathrm{LieBracket}}{,}{\mathrm{LieDerivative}}{,}{\mathrm{Normal}}{,}{\mathrm{NumericalRelativity}}{,}{\mathrm{Parameters}}{,}{\mathrm{PerformOnAnticommutativeSystem}}{,}{\mathrm{Projector}}{,}{\mathrm{Psigma}}{,}{\mathrm{Redefine}}{,}{\mathrm{Ricci}}{,}{\mathrm{Riemann}}{,}{\mathrm{Setup}}{,}{\mathrm{Simplify}}{,}{\mathrm{SortProducts}}{,}{\mathrm{SpaceTimeVector}}{,}{\mathrm{StandardModel}}{,}{\mathrm{Substitute}}{,}{\mathrm{SubstituteTensor}}{,}{\mathrm{SubstituteTensorIndices}}{,}{\mathrm{SumOverRepeatedIndices}}{,}{\mathrm{Symmetrize}}{,}{\mathrm{TensorArray}}{,}{\mathrm{Tetrads}}{,}{\mathrm{ThreePlusOne}}{,}{\mathrm{ToContravariant}}{,}{\mathrm{ToCovariant}}{,}{\mathrm{ToFieldComponents}}{,}{\mathrm{ToSuperfields}}{,}{\mathrm{Trace}}{,}{\mathrm{TransformCoordinates}}{,}{\mathrm{Vectors}}{,}{\mathrm{Weyl}}{,}{\mathrm{^}}{,}{\mathrm{dAlembertian}}{,}{\mathrm{d_}}{,}{\mathrm{diff}}{,}{\mathrm{g_}}{,}{\mathrm{gamma_}}\right]$ (1)

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:

 > $\mathrm{g_}\left[\right]$
 ${{\mathrm{g_}}}_{{\mathrm{μ}}{,}{\mathrm{ν}}}{=}\left(\left[\begin{array}{rrrr}-1& 0& 0& 0\\ 0& -1& 0& 0\\ 0& 0& -1& 0\\ 0& 0& 0& 1\end{array}\right]\right)$ (2)

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:

 >
 ${{\mathrm{g_}}}_{{\mathrm{μ}}{,}{\mathrm{ν}}}{=}\left(\left[\begin{array}{rrrr}-1& 0& 0& 0\\ 0& -1& 0& 0\\ 0& 0& -1& 0\\ 0& 0& 0& 1\end{array}\right]\right)$
 $\mathrm{_______________________________________________________}$
 $\left[{\mathrm{coordinatesystems}}{=}{\mathrm{none}}{,}{\mathrm{dimension}}{=}{4}{,}{\mathrm{metric}}{=}\left\{\left({1}{,}{1}\right){=}{-1}{,}\left({2}{,}{2}\right){=}{-1}{,}\left({3}{,}{3}\right){=}{-1}{,}\left({4}{,}{4}\right){=}{1}\right\}{,}{\mathrm{signature}}{=}{\mathrm{- - - +}}\right]$ (3)

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 . To change the signature, reorder the coordinates and the lines and columns in the metric all in one go enter $\mathrm{Redefine}\left(\mathrm{setall},\mathrm{tosignature}=\mathrm{+ + + -}\right)$. The five signatures understood by Physics are:

 a (- - - +), default.
 b (+ - - - ), same line element as a.
 c (+ + + -), used in the ThreePlusOne package and ADM formalism, and in the database of exact solutions to Einstein equations.
 d (- + + +), same line element as c.
 e (+ + + +), 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

 > $\mathrm{g_}\left[\mathrm{lineelement}\right];$
 ${}\mathrm{Systems of spacetime coordinates are:}{}\left\{X=\left(\mathrm{x1}{,}\mathrm{x2}{,}\mathrm{x3}{,}\mathrm{x4}\right)\right\}$
 ${-}{{\mathbf{ⅆ}}{}\left({\mathrm{x1}}\right)}^{{2}}{-}{{\mathbf{ⅆ}}{}\left({\mathrm{x2}}\right)}^{{2}}{-}{{\mathbf{ⅆ}}{}\left({\mathrm{x3}}\right)}^{{2}}{+}{{\mathbf{ⅆ}}{}\left({\mathrm{x4}}\right)}^{{2}}$ (4)

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

 > $\mathrm{Library}:-\mathrm{PositionOfTimelikeComponent}\left(\right);$
 ${4}$ (5)

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 $\mathrm{Setup}\left(\right)$. The following image shows the left half of that applet.

 > $\mathrm{Setup}\left(\right)$  Systems of coordinates

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).

 >
 ${}\mathrm{Systems of spacetime coordinates are:}{}\left\{X=\left(\mathrm{x1}{,}\mathrm{x2}{,}\mathrm{x3}{,}\mathrm{x4}\right)\right\}$
 $\mathrm{_______________________________________________________}$
 $\left[{\mathrm{coordinatesystems}}{=}\left\{{X}\right\}\right]$ (6)

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

 >
 ${}\mathrm{Systems of spacetime coordinates are:}{}\left\{X=\left(\mathrm{x1}{,}\mathrm{x2}{,}\mathrm{x3}{,}\mathrm{x4}\right){,}Y=\left(\mathrm{y1}{,}\mathrm{y2}{,}\mathrm{y3}{,}\mathrm{y4}\right)\right\}$
 $\mathrm{_______________________________________________________}$
 $\left[{\mathrm{coordinatesystems}}{=}\left\{{X}{,}{Y}\right\}\right]$ (7)

To change the coordinates used by the differential operators d_, D_ and dAlembertian, for example from X to Y, enter $\mathrm{Setup}\left(\mathrm{differentiationvariables}=Y\right)$.

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

 > $\mathrm{getassumptions}\left(\mathrm{x2}\right)$
 $\left\{{\mathrm{x2}}{::}{\mathrm{real}}\right\}$ (8)

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

 >
 ${}\mathrm{Default differentiation variables for d_, D_ and dAlembertian are:}{}\left\{X=\left(r{,}\mathrm{\theta }{,}\mathrm{\phi }{,}t\right)\right\}$
 ${}\mathrm{Systems of spacetime coordinates are:}{}\left\{X=\left(r{,}\mathrm{\theta }{,}\mathrm{\phi }{,}t\right){,}Y=\left(\mathrm{y1}{,}\mathrm{y2}{,}\mathrm{y3}{,}\mathrm{y4}\right)\right\}$
 $\mathrm{_______________________________________________________}$
 $\left[{\mathrm{coordinatesystems}}{=}\left\{{X}{,}{Y}\right\}\right]$ (9)

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:

 > $\mathrm{map}\left(\mathrm{getassumptions},\left[X\right]\right)$
 $\left[\left\{{r}{::}\left[{0}{,}{\mathrm{\infty }}\right)\right\}{,}\left\{{\mathrm{\theta }}{::}\left[{0}{,}{\mathrm{\pi }}\right]\right\}{,}\left\{{\mathrm{\phi }}{::}\left[{0}{,}{2}{}{\mathrm{\pi }}\right]\right\}{,}\left\{{t}{::}\left[{0}{,}{\mathrm{\infty }}\right)\right\}\right]$ (10)

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:

 >
 ${}\mathrm{Systems of spacetime coordinates are:}{}\left\{X=\left(u{,}v{,}w{,}t\right){,}Y=\left(\mathrm{y1}{,}\mathrm{y2}{,}\mathrm{y3}{,}\mathrm{y4}\right){,}Z=\left(\mathrm{z__1}{,}\mathrm{z__2}{,}\mathrm{z__3}{,}\mathrm{z__4}\right)\right\}$
 $\mathrm{_______________________________________________________}$
 $\left[{\mathrm{coordinatesystems}}{=}\left\{{X}{,}{Y}{,}{Z}\right\}\right]$ (11)

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

 > $F\left(X\right)$
 ${F}{}\left({X}\right)$ (12)

where $F\left(X\right)$is a function of four variables. You can check the number of its operands, or get any one of its variables via

 > $\mathrm{nops}\left(\right)$
 ${4}$ (13)
 > $\mathrm{op}\left(4,F\left(X\right)\right)$
 ${t}$ (14)

It is often useful to avoid a redundant display of the coordinate's dependency$\left(X\right)$in functions. For that purpose use CompactDisplay.

 > $\mathrm{CompactDisplay}\left(F\left(X\right)\right)$
 ${F}{}\left({u}{,}{v}{,}{w}{,}{t}\right){}{\mathrm{will now be displayed as}}{}{F}$ (15)

The dependency of $F\left(X\right)$is now omitted from the display

 ${F}{}\left({X}\right)$ (16)
 > $F\left(X\right)$
 ${F}{}\left({X}\right)$ (17)

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

 > $X\left[\mathrm{mu}\right]$
 ${{X}}_{{\mathrm{\mu }}}$ (18)

In the context of Physics, contravariant indices are entered preceded by ~

 > $X\left[~\mathrm{mu}\right]$
 ${{X}}_{\phantom{{}}\phantom{{\mathrm{\mu }}}}^{\phantom{{}}{\mathrm{\mu }}}$ (19)

The distinction between covariant and contravariant indices is relevant in non-Euclidean spacetimes (you can set the spacetime to be Euclidean by entering $\mathrm{Setup}\left(\mathrm{metric}=\mathrm{Euclidean}\right)$). For example, in a flat Minkowski spacetime, when summing over the repeated indices of tensorial expressions (see SumOverRepeatedIndices)

 > $X{\left[\mathrm{mu}\right]}^{2}$
 ${{X}}_{{\mathrm{\mu }}}{}{{X}}_{\phantom{{}}\phantom{{\mathrm{\mu }}}}^{\phantom{{}}{\mathrm{\mu }}}$ (20)
 > $\mathrm{SumOverRepeatedIndices}\left(\right)$
 ${{t}}^{{2}}{-}{{u}}^{{2}}{-}{{v}}^{{2}}{-}{{w}}^{{2}}$ (21)

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}_{\mathrm{\mu },\mathrm{\nu }}$, the space metric ${\mathrm{\gamma }}_{j,k}$, and all the standard tensors of General Relativity. To check their definition, index the tensor with the keyword definition, for example: ${\mathrm{\gamma }}_{\mathrm{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 $A\left[\mathrm{mu}\right]$, and are displayed as subscripts as in ${A}_{\mathrm{\mu }}$. 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\left[~\mathrm{mu}\right]$, and are displayed as superscripts, as in ${A}_{\phantom{}\phantom{\mathrm{\mu }}}^{\phantom{}\mathrm{\mu }}$. 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 $\mathrm{μ}$, 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:

 1 Passing the tensor being defined, say ${F}_{\mathrm{μ},\mathrm{ν}}$, to the Define command, possibly indicating symmetries and/or antisymmetries for its indices.
 2 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}_{\mathrm{μ},\mathrm{ν}}$, 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 ${A}_{1}$ or ${A}_{\phantom{}\phantom{1}}^{\phantom{}1}$
 • Get all the covariant and contravariant components by respectively using the shortcut notation $A\left[\right]$ and $A\left[~\right]$
 • 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. Defining a tensor by passing the tensor itself

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

 > $\mathrm{restart};\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathrm{with}\left(\mathrm{Physics}\right):\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathrm{Setup}\left(\mathrm{spacetimeindices}\right)$
 $\left[{\mathrm{spacetimeindices}}{=}{\mathrm{greek}}\right]$ (22)

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

 > $\mathrm{Define}\left(A\left[\mathrm{mu}\right]\right)$
 $\mathrm{Defined objects with tensor properties}$
 $\left\{{{A}}_{{\mathrm{\mu }}}{,}{{\mathrm{\gamma }}}_{{\mathrm{\mu }}}{,}{{\mathrm{\sigma }}}_{{\mathrm{\mu }}}{,}{{\partial }}_{{\mathrm{\mu }}}{,}{{g}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{\mathrm{\epsilon }}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}\right\}$ (23)

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 .

Once ${A}_{\mathrm{\mu }}$ is defined as a tensor you can refer to any of its components by indexing with the corresponding covariant or contravariant number

 > $A\left[1\right]$
 ${{A}}_{{1}}$ (24)
 > $A\left[~1\right]$
 ${{A}}_{\phantom{{}}\phantom{{1}}}^{\phantom{{}}{1}}$ (25)

To retrieve all the components at once you can use TensorArray or Library:-TensorComponents, the respective output will be an Array or a list

 > $\mathrm{TensorArray}\left(A\left[\mathrm{mu}\right]\right)$
 $\left[\begin{array}{cccc}{A}_{1}& {A}_{2}& {A}_{3}& {A}_{4}\end{array}\right]$ (26)
 > $\mathrm{Library}:-\mathrm{TensorComponents}\left(A\left[~\mathrm{mu}\right]\right)$
 $\left[{{A}}_{\phantom{{}}\phantom{{1}}}^{\phantom{{}}{1}}{,}{{A}}_{\phantom{{}}\phantom{{2}}}^{\phantom{{}}{2}}{,}{{A}}_{\phantom{{}}\phantom{{3}}}^{\phantom{{}}{3}}{,}{{A}}_{\phantom{{}}\phantom{{4}}}^{\phantom{{}}{4}}\right]$ (27)

When the spacetime is not Euclidean the repeated indices are automatically reformatted: one covariant the other contravariant

 >
 ${{g}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{}{{A}}_{\phantom{{}}\phantom{{\mathrm{\mu }}}}^{\phantom{{}}{\mathrm{\mu }}}$ (28)

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

 >
 ${{A}}_{{\mathrm{\mu }}}{}{{\mathrm{g_}}}_{{\mathrm{ν}}{,}{\mathrm{~mu}}}$ (29)

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

 > $\mathrm{Simplify}\left(\right)$
 ${{A}}_{{\mathrm{\nu }}}$ (30)

Repeated indices - some or all - can be summed over using SumOverRepeatedIndices

 > $\mathrm{SumOverRepeatedIndices}\left(\right)$
 ${{g}}_{{1}{,}{\mathrm{\nu }}}{}{{A}}_{\phantom{{}}\phantom{{1}}}^{\phantom{{}}{1}}{+}{{g}}_{{2}{,}{\mathrm{\nu }}}{}{{A}}_{\phantom{{}}\phantom{{2}}}^{\phantom{{}}{2}}{+}{{g}}_{{3}{,}{\mathrm{\nu }}}{}{{A}}_{\phantom{{}}\phantom{{3}}}^{\phantom{{}}{3}}{+}{{g}}_{{4}{,}{\mathrm{\nu }}}{}{{A}}_{\phantom{{}}\phantom{{4}}}^{\phantom{{}}{4}}$ (31)

Recalling the current value of the metric

 > $\mathrm{g_}\left[\right]$
 ${{\mathrm{g_}}}_{{\mathrm{μ}}{,}{\mathrm{ν}}}{=}\left(\left[\begin{array}{rrrr}-1& 0& 0& 0\\ 0& -1& 0& 0\\ 0& 0& -1& 0\\ 0& 0& 0& 1\end{array}\right]\right)$ (32)

a tensor array with the components of, for example, the relationship ${A}_{\mathrm{\nu }}={g}_{\mathrm{\mu },\mathrm{\nu }}{A}_{\phantom{\mathrm{\mu }}}^{\phantom{}\mathrm{\mu }}$, can be computed using TensorArray

 > $\mathrm{TensorArray}\left({A}_{\mathrm{\nu }}={g}_{\mathrm{\mu },\mathrm{\nu }}{A}_{\phantom{}\phantom{\mathrm{\mu }}}^{\phantom{}\mathrm{\mu }}\right)$
 $\left[\begin{array}{cccc}{A}_{1}=-{A}_{\mathrm{~1}}& {A}_{2}=-{A}_{\mathrm{~2}}& {A}_{3}=-{A}_{\mathrm{~3}}& {A}_{4}={A}_{\mathrm{~4}}\end{array}\right]$ (33)

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: , then right-clicking the expression and following the pop-up menu 2-D Math → Convert To → 2-D Math input. This is particularly useful:

 1 when the input and output are the same so you can terminate the input with : to avoid displaying the output,
 2 when the input without typesetting is not easy to read/understand
 3 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

 > $\mathrm{Coordinates}\left(X=\left[u,v,w,t\right],Z=\left[\mathrm{z__1},\mathrm{z__2},\mathrm{z__3},\mathrm{z__4}\right]\right)$
 ${}\mathrm{Systems of spacetime coordinates are:}{}\left\{X=\left(u{,}v{,}w{,}t\right){,}Z=\left(\mathrm{z__1}{,}\mathrm{z__2}{,}\mathrm{z__3}{,}\mathrm{z__4}\right)\right\}$
 $\left\{{X}{,}{Z}\right\}$ (34)

You can now transform coordinates using TransformCoordinates, for example from X to Z using$\left\{u=\mathrm{z__1}+\mathrm{z__2},v=\mathrm{z__1}-\mathrm{z__2}\right\}$, as follows:

 >
 >
 $\left[\begin{array}{c}{A}_{1}+{A}_{2}\\ {A}_{1}-{A}_{2}\\ {A}_{3}\\ {A}_{4}\end{array}\right]$ (35)

Note the different transformation rule for the covariant components (above) and the contravariant ones:

 >
 $\left[\begin{array}{c}\frac{1}{2}{}{A}_{\mathrm{~1}}+\frac{1}{2}{}{A}_{\mathrm{~2}}\\ \frac{1}{2}{}{A}_{\mathrm{~1}}-\frac{1}{2}{}{A}_{\mathrm{~2}}\\ {A}_{\mathrm{~3}}\\ {A}_{\mathrm{~4}}\end{array}\right]$ (36) Defining a tensor by passing a tensorial equation

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

 >
 $\mathrm{Defined objects with tensor properties}$
 $\left\{{{A}}_{{\mathrm{\mu }}}{,}{{\mathrm{\gamma }}}_{{\mathrm{\mu }}}{,}{{\mathrm{\sigma }}}_{{\mathrm{\mu }}}{,}{{\partial }}_{{\mathrm{\mu }}}{,}{{g}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{p}}_{{\mathrm{\mu }}}{,}{{\mathrm{\epsilon }}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{X}}_{{\mathrm{\mu }}}{,}{{Z}}_{{\mathrm{\mu }}}\right\}$ (37)

On the right-hand side of the definition you can also use a Vector construction, as in $⟨\mathrm{p__x},\mathrm{p__y},\mathrm{p__z},\frac{E}{c}⟩$, 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

 > $p\left[1\right]$
 $\mathrm{p__x}$ (38)
 > $p\left[0\right]$
 $\frac{{E}}{{c}}$ (39)

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

 > $\mathrm{Setup}\left(\mathrm{signature}\right)$
 $\left[{\mathrm{signature}}{=}{\mathrm{- - - +}}\right]$ (40)
 > $\mathrm{Library}:-\mathrm{PositionOfTimelikeComponent}\left(\right)$
 ${4}$ (41)

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,

 >
 $\mathrm{* Partial match of \text{'}}\mathrm{usecoordinates}\mathrm{\text{'} against keyword \text{'}}\mathrm{usecoordinatesastensorindices}\text{'}$
 ${}\mathrm{Default differentiation variables for d_, D_ and dAlembertian are:}{}\left\{X=\left(x{,}y{,}z{,}t\right)\right\}$
 ${}\mathrm{Systems of spacetime coordinates are:}{}\left\{X=\left(x{,}y{,}z{,}t\right){,}Z=\left(\mathrm{z__1}{,}\mathrm{z__2}{,}\mathrm{z__3}{,}\mathrm{z__4}\right)\right\}$
 $\mathrm{_______________________________________________________}$
 $\left[{\mathrm{coordinatesystems}}{=}\left\{{X}{,}{Z}\right\}{,}{\mathrm{usecoordinatesastensorindices}}{=}{\mathrm{true}}\right]$ (42)
 >
 $\mathrm{p__x}{=}\mathrm{p__x}$ (43)
 >
 $\frac{{E}}{{c}}{=}\frac{{E}}{{c}}$ (44)

You can get all the covariant and contravariant components by respectively using the following shortcut notation

 > $p\left[\right]$
 ${{p}}_{{\mathrm{μ}}}{=}\left(\left[\begin{array}{cccc}\mathrm{p__x}& \mathrm{p__y}& \mathrm{p__z}& \frac{E}{c}\end{array}\right]\right)$ (45)
 > $p\left[~\right]$
 ${{p}}_{{\mathrm{~mu}}}{=}\left(\left[\begin{array}{cccc}-\mathrm{p__x}& -\mathrm{p__y}& -\mathrm{p__z}& \frac{E}{c}\end{array}\right]\right)$ (46)

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

 > $p\left[\mathrm{definition}\right]$
 ${{p}}_{{\mathrm{\mu }}}{=}\left[\mathrm{p__x}{,}\mathrm{p__y}{,}\mathrm{p__z}{,}\frac{{E}}{{c}}\right]$ (47)
 > $p\left[\mathrm{nonzero}\right]$
 ${{p}}_{{\mathrm{\mu }}}{=}\left\{{1}{=}\mathrm{p__x}{,}{2}{=}\mathrm{p__y}{,}{3}{=}\mathrm{p__z}{,}{4}{=}\frac{{E}}{{c}}\right\}$ (48)

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

 >
 ${{F}}_{{\mathrm{μ}}{,}{\mathrm{ν}}}{=}\left(\left[\begin{array}{cccc}{F}_{1,1}& {F}_{1,2}& {F}_{1,3}& {F}_{1,4}\\ {F}_{2,1}& {F}_{2,2}& {F}_{2,3}& {F}_{2,4}\\ {F}_{3,1}& {F}_{3,2}& {F}_{3,3}& {F}_{3,4}\\ {F}_{4,1}& {F}_{4,2}& {F}_{4,3}& {F}_{4,4}\end{array}\right]\right)$ (49)
 > $\mathrm{Define}\left(\right)$
 $\mathrm{Defined objects with tensor properties}$
 $\left\{{{A}}_{{\mathrm{\mu }}}{,}{{\mathrm{\gamma }}}_{{\mathrm{\mu }}}{,}{{F}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{\mathrm{\sigma }}}_{{\mathrm{\mu }}}{,}{{\partial }}_{{\mathrm{\mu }}}{,}{{g}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{p}}_{{\mathrm{\mu }}}{,}{{\mathrm{\epsilon }}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{X}}_{{\mathrm{\mu }}}{,}{{Z}}_{{\mathrm{\mu }}}\right\}$ (50)
 > $F\left[~\right]$
 ${{F}}_{{\mathrm{~mu}}{,}{\mathrm{~nu}}}{=}\left(\left[\begin{array}{cccc}{F}_{1,1}& {F}_{1,2}& {F}_{1,3}& -{F}_{1,4}\\ {F}_{2,1}& {F}_{2,2}& {F}_{2,3}& -{F}_{2,4}\\ {F}_{3,1}& {F}_{3,2}& {F}_{3,3}& -{F}_{3,4}\\ -{F}_{4,1}& -{F}_{4,2}& -{F}_{4,3}& {F}_{4,4}\end{array}\right]\right)$ (51)
 >
 ${{F}}_{{\mathrm{\mu }}\phantom{{\mathrm{\mu }}}}^{\phantom{{\mathrm{\mu }}}{\mathrm{\mu }}}{=}{-}{{F}}_{{1}{,}{1}}{-}{{F}}_{{2}{,}{2}}{-}{{F}}_{{3}{,}{3}}{+}{{F}}_{{4}{,}{4}}$ (52)
 > $F\left[\mathrm{determinant}\right]$
 ${{F}}_{{1}{,}{1}}{}{{F}}_{{2}{,}{2}}{}{{F}}_{{3}{,}{3}}{}{{F}}_{{4}{,}{4}}{-}{{F}}_{{1}{,}{1}}{}{{F}}_{{2}{,}{2}}{}{{F}}_{{3}{,}{4}}{}{{F}}_{{4}{,}{3}}{-}{{F}}_{{1}{,}{1}}{}{{F}}_{{2}{,}{3}}{}{{F}}_{{3}{,}{2}}{}{{F}}_{{4}{,}{4}}{+}{{F}}_{{1}{,}{1}}{}{{F}}_{{2}{,}{3}}{}{{F}}_{{3}{,}{4}}{}{{F}}_{{4}{,}{2}}{+}{{F}}_{{1}{,}{1}}{}{{F}}_{{2}{,}{4}}{}{{F}}_{{3}{,}{2}}{}{{F}}_{{4}{,}{3}}{-}{{F}}_{{1}{,}{1}}{}{{F}}_{{2}{,}{4}}{}{{F}}_{{3}{,}{3}}{}{{F}}_{{4}{,}{2}}{-}{{F}}_{{1}{,}{2}}{}{{F}}_{{2}{,}{1}}{}{{F}}_{{3}{,}{3}}{}{{F}}_{{4}{,}{4}}{+}{{F}}_{{1}{,}{2}}{}{{F}}_{{2}{,}{1}}{}{{F}}_{{3}{,}{4}}{}{{F}}_{{4}{,}{3}}{+}{{F}}_{{1}{,}{2}}{}{{F}}_{{2}{,}{3}}{}{{F}}_{{3}{,}{1}}{}{{F}}_{{4}{,}{4}}{-}{{F}}_{{1}{,}{2}}{}{{F}}_{{2}{,}{3}}{}{{F}}_{{3}{,}{4}}{}{{F}}_{{4}{,}{1}}{-}{{F}}_{{1}{,}{2}}{}{{F}}_{{2}{,}{4}}{}{{F}}_{{3}{,}{1}}{}{{F}}_{{4}{,}{3}}{+}{{F}}_{{1}{,}{2}}{}{{F}}_{{2}{,}{4}}{}{{F}}_{{3}{,}{3}}{}{{F}}_{{4}{,}{1}}{+}{{F}}_{{1}{,}{3}}{}{{F}}_{{2}{,}{1}}{}{{F}}_{{3}{,}{2}}{}{{F}}_{{4}{,}{4}}{-}{{F}}_{{1}{,}{3}}{}{{F}}_{{2}{,}{1}}{}{{F}}_{{3}{,}{4}}{}{{F}}_{{4}{,}{2}}{-}{{F}}_{{1}{,}{3}}{}{{F}}_{{2}{,}{2}}{}{{F}}_{{3}{,}{1}}{}{{F}}_{{4}{,}{4}}{+}{{F}}_{{1}{,}{3}}{}{{F}}_{{2}{,}{2}}{}{{F}}_{{3}{,}{4}}{}{{F}}_{{4}{,}{1}}{+}{{F}}_{{1}{,}{3}}{}{{F}}_{{2}{,}{4}}{}{{F}}_{{3}{,}{1}}{}{{F}}_{{4}{,}{2}}{-}{{F}}_{{1}{,}{3}}{}{{F}}_{{2}{,}{4}}{}{{F}}_{{3}{,}{2}}{}{{F}}_{{4}{,}{1}}{-}{{F}}_{{1}{,}{4}}{}{{F}}_{{2}{,}{1}}{}{{F}}_{{3}{,}{2}}{}{{F}}_{{4}{,}{3}}{+}{{F}}_{{1}{,}{4}}{}{{F}}_{{2}{,}{1}}{}{{F}}_{{3}{,}{3}}{}{{F}}_{{4}{,}{2}}{+}{{F}}_{{1}{,}{4}}{}{{F}}_{{2}{,}{2}}{}{{F}}_{{3}{,}{1}}{}{{F}}_{{4}{,}{3}}{-}{{F}}_{{1}{,}{4}}{}{{F}}_{{2}{,}{2}}{}{{F}}_{{3}{,}{3}}{}{{F}}_{{4}{,}{1}}{-}{{F}}_{{1}{,}{4}}{}{{F}}_{{2}{,}{3}}{}{{F}}_{{3}{,}{1}}{}{{F}}_{{4}{,}{2}}{+}{{F}}_{{1}{,}{4}}{}{{F}}_{{2}{,}{3}}{}{{F}}_{{3}{,}{2}}{}{{F}}_{{4}{,}{1}}$ (53)

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

 > $\mathrm{%F}\left[\mathrm{determinant}\right]$
 ${{\mathrm{%F}}}_{{\mathrm{determinant}}}$ (54)
 > $\mathrm{value}\left(\right)$
 ${{F}}_{{1}{,}{1}}{}{{F}}_{{2}{,}{2}}{}{{F}}_{{3}{,}{3}}{}{{F}}_{{4}{,}{4}}{-}{{F}}_{{1}{,}{1}}{}{{F}}_{{2}{,}{2}}{}{{F}}_{{3}{,}{4}}{}{{F}}_{{4}{,}{3}}{-}{{F}}_{{1}{,}{1}}{}{{F}}_{{2}{,}{3}}{}{{F}}_{{3}{,}{2}}{}{{F}}_{{4}{,}{4}}{+}{{F}}_{{1}{,}{1}}{}{{F}}_{{2}{,}{3}}{}{{F}}_{{3}{,}{4}}{}{{F}}_{{4}{,}{2}}{+}{{F}}_{{1}{,}{1}}{}{{F}}_{{2}{,}{4}}{}{{F}}_{{3}{,}{2}}{}{{F}}_{{4}{,}{3}}{-}{{F}}_{{1}{,}{1}}{}{{F}}_{{2}{,}{4}}{}{{F}}_{{3}{,}{3}}{}{{F}}_{{4}{,}{2}}{-}{{F}}_{{1}{,}{2}}{}{{F}}_{{2}{,}{1}}{}{{F}}_{{3}{,}{3}}{}{{F}}_{{4}{,}{4}}{+}{{F}}_{{1}{,}{2}}{}{{F}}_{{2}{,}{1}}{}{{F}}_{{3}{,}{4}}{}{{F}}_{{4}{,}{3}}{+}{{F}}_{{1}{,}{2}}{}{{F}}_{{2}{,}{3}}{}{{F}}_{{3}{,}{1}}{}{{F}}_{{4}{,}{4}}{-}{{F}}_{{1}{,}{2}}{}{{F}}_{{2}{,}{3}}{}{{F}}_{{3}{,}{4}}{}{{F}}_{{4}{,}{1}}{-}{{F}}_{{1}{,}{2}}{}{{F}}_{{2}{,}{4}}{}{{F}}_{{3}{,}{1}}{}{{F}}_{{4}{,}{3}}{+}{{F}}_{{1}{,}{2}}{}{{F}}_{{2}{,}{4}}{}{{F}}_{{3}{,}{3}}{}{{F}}_{{4}{,}{1}}{+}{{F}}_{{1}{,}{3}}{}{{F}}_{{2}{,}{1}}{}{{F}}_{{3}{,}{2}}{}{{F}}_{{4}{,}{4}}{-}{{F}}_{{1}{,}{3}}{}{{F}}_{{2}{,}{1}}{}{{F}}_{{3}{,}{4}}{}{{F}}_{{4}{,}{2}}{-}{{F}}_{{1}{,}{3}}{}{{F}}_{{2}{,}{2}}{}{{F}}_{{3}{,}{1}}{}{{F}}_{{4}{,}{4}}{+}{{F}}_{{1}{,}{3}}{}{{F}}_{{2}{,}{2}}{}{{F}}_{{3}{,}{4}}{}{{F}}_{{4}{,}{1}}{+}{{F}}_{{1}{,}{3}}{}{{F}}_{{2}{,}{4}}{}{{F}}_{{3}{,}{1}}{}{{F}}_{{4}{,}{2}}{-}{{F}}_{{1}{,}{3}}{}{{F}}_{{2}{,}{4}}{}{{F}}_{{3}{,}{2}}{}{{F}}_{{4}{,}{1}}{-}{{F}}_{{1}{,}{4}}{}{{F}}_{{2}{,}{1}}{}{{F}}_{{3}{,}{2}}{}{{F}}_{{4}{,}{3}}{+}{{F}}_{{1}{,}{4}}{}{{F}}_{{2}{,}{1}}{}{{F}}_{{3}{,}{3}}{}{{F}}_{{4}{,}{2}}{+}{{F}}_{{1}{,}{4}}{}{{F}}_{{2}{,}{2}}{}{{F}}_{{3}{,}{1}}{}{{F}}_{{4}{,}{3}}{-}{{F}}_{{1}{,}{4}}{}{{F}}_{{2}{,}{2}}{}{{F}}_{{3}{,}{3}}{}{{F}}_{{4}{,}{1}}{-}{{F}}_{{1}{,}{4}}{}{{F}}_{{2}{,}{3}}{}{{F}}_{{3}{,}{1}}{}{{F}}_{{4}{,}{2}}{+}{{F}}_{{1}{,}{4}}{}{{F}}_{{2}{,}{3}}{}{{F}}_{{3}{,}{2}}{}{{F}}_{{4}{,}{1}}$ (55)

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\left[~\mathrm{mu},\mathrm{nu},\mathrm{matrix}\right]$
 ${{F}}_{{\mathrm{~mu}}{,}{\mathrm{ν}}}{=}\left(\left[\begin{array}{cccc}-{F}_{1,1}& -{F}_{1,2}& -{F}_{1,3}& -{F}_{1,4}\\ -{F}_{2,1}& -{F}_{2,2}& -{F}_{2,3}& -{F}_{2,4}\\ -{F}_{3,1}& -{F}_{3,2}& -{F}_{3,3}& -{F}_{3,4}\\ {F}_{4,1}& {F}_{4,2}& {F}_{4,3}& {F}_{4,4}\end{array}\right]\right)$ (56)

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

 >
 ${{F}}_{{\mathrm{μ}}{,}{\mathrm{ν}}}{=}\left(\left[\begin{array}{cccc}{F}_{1,1}& {F}_{1,2}& {F}_{1,3}& {F}_{1,4}\\ -{F}_{1,2}& {F}_{2,2}& {F}_{2,3}& {F}_{2,4}\\ {F}_{3,1}& {F}_{3,2}& {F}_{3,3}& {F}_{3,4}\\ {F}_{4,1}& {F}_{4,2}& {F}_{4,3}& {F}_{4,4}\end{array}\right]\right)$ (57)

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 this time indicating that it is antisymmetric and minimizing the amount of independent components by taking that fact into account

 >
 $\mathrm{Defined objects with tensor properties}$
 $\left\{{{A}}_{{\mathrm{\mu }}}{,}{{\mathrm{\gamma }}}_{{\mathrm{\mu }}}{,}{{F}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{\mathrm{\sigma }}}_{{\mathrm{\mu }}}{,}{{\partial }}_{{\mathrm{\mu }}}{,}{{g}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{p}}_{{\mathrm{\mu }}}{,}{{\mathrm{\epsilon }}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{X}}_{{\mathrm{\mu }}}{,}{{Z}}_{{\mathrm{\mu }}}\right\}$ (58)
 > $F\left[\right]$
 ${{F}}_{{\mathrm{μ}}{,}{\mathrm{ν}}}{=}\left(\left[\begin{array}{cccc}0& {F}_{1,2}& {F}_{1,3}& {F}_{1,4}\\ -{F}_{1,2}& 0& {F}_{2,3}& {F}_{2,4}\\ -{F}_{1,3}& -{F}_{2,3}& 0& {F}_{3,4}\\ -{F}_{1,4}& -{F}_{2,4}& -{F}_{3,4}& 0\end{array}\right]\right)$ (59)
 > $\mathrm{Library}:-\mathrm{NumberOfIndependentTensorComponents}\left(F\right)$
 ${6}$ (60)
 • 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}_{\mathrm{μ}}$

 > $\mathrm{Library}:-\mathrm{TensorComponents}\left({A}_{\mathrm{μ}}\right)$
 $\left[{{A}}_{{1}}{,}{{A}}_{{2}}{,}{{A}}_{{3}}{,}{{A}}_{{4}}\right]$ (61)

Taking ${A}_{\mathrm{\mu }}$ to represent the 4D potential in electrodynamics, the corresponding electromagnetic field is

 >
 ${{F}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{=}{{\partial }}_{{\mathrm{\mu }}}{}\left({{A}}_{{\mathrm{\nu }}}{}\left({X}\right)\right){-}{{\partial }}_{{\mathrm{\nu }}}{}\left({{A}}_{{\mathrm{\mu }}}{}\left({X}\right)\right)$ (62)

To have a compact display that avoids redundancy use CompactDisplay

 > $\mathrm{CompactDisplay}\left(A\left(X\right)\right)$
 ${A}{}\left({x}{,}{y}{,}{z}{,}{t}\right){}{\mathrm{will now be displayed as}}{}{A}$ (63)

Now redo the definition of ${F}_{\mathrm{μ},\mathrm{ν}}$ using (62)

 > $\mathrm{Define}\left(\mathrm{redo},,\mathrm{minimizetensorcomponents}\right)$
 $\mathrm{Defined objects with tensor properties}$
 $\left\{{{A}}_{{\mathrm{\mu }}}{,}{{\mathrm{\gamma }}}_{{\mathrm{\mu }}}{,}{{F}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{\mathrm{\sigma }}}_{{\mathrm{\mu }}}{,}{{\partial }}_{{\mathrm{\mu }}}{,}{{g}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{p}}_{{\mathrm{\mu }}}{,}{{\mathrm{\epsilon }}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{X}}_{{\mathrm{\mu }}}{,}{{Z}}_{{\mathrm{\mu }}}\right\}$ (64)

 > $F\left[\right]$
 ${{F}}_{{\mathrm{μ}}{,}{\mathrm{ν}}}{=}\left(\left[\begin{array}{cccc}0& \frac{\partial }{\partial x}{}{A}_{2}{}\left(x,y,z,t\right)-\left(\frac{\partial }{\partial y}{}{A}_{1}{}\left(x,y,z,t\right)\right)& \frac{\partial }{\partial x}{}{A}_{3}{}\left(x,y,z,t\right)-\left(\frac{\partial }{\partial z}{}{A}_{1}{}\left(x,y,z,t\right)\right)& \frac{\partial }{\partial x}{}{A}_{4}{}\left(x,y,z,t\right)-\left(\frac{\partial }{\partial t}{}{A}_{1}{}\left(x,y,z,t\right)\right)\\ \frac{\partial }{\partial y}{}{A}_{1}{}\left(x,y,z,t\right)-\left(\frac{\partial }{\partial x}{}{A}_{2}{}\left(x,y,z,t\right)\right)& 0& \frac{\partial }{\partial y}{}{A}_{3}{}\left(x,y,z,t\right)-\left(\frac{\partial }{\partial z}{}{A}_{2}{}\left(x,y,z,t\right)\right)& \frac{\partial }{\partial y}{}{A}_{4}{}\left(x,y,z,t\right)-\left(\frac{\partial }{\partial t}{}{A}_{2}{}\left(x,y,z,t\right)\right)\\ \frac{\partial }{\partial z}{}{A}_{1}{}\left(x,y,z,t\right)-\left(\frac{\partial }{\partial x}{}{A}_{3}{}\left(x,y,z,t\right)\right)& \frac{\partial }{\partial z}{}{A}_{2}{}\left(x,y,z,t\right)-\left(\frac{\partial }{\partial y}{}{A}_{3}{}\left(x,y,z,t\right)\right)& 0& \frac{\partial }{\partial z}{}{A}_{4}{}\left(x,y,z,t\right)-\left(\frac{\partial }{\partial t}{}{A}_{3}{}\left(x,y,z,t\right)\right)\\ \frac{\partial }{\partial t}{}{A}_{1}{}\left(x,y,z,t\right)-\left(\frac{\partial }{\partial x}{}{A}_{4}{}\left(x,y,z,t\right)\right)& \frac{\partial }{\partial t}{}{A}_{2}{}\left(x,y,z,t\right)-\left(\frac{\partial }{\partial y}{}{A}_{4}{}\left(x,y,z,t\right)\right)& \frac{\partial }{\partial t}{}{A}_{3}{}\left(x,y,z,t\right)-\left(\frac{\partial }{\partial z}{}{A}_{4}{}\left(x,y,z,t\right)\right)& 0\end{array}\right]\right)$ (65)

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}_{\mathrm{α},\mathrm{β}}$,

 > ${C}_{\mathrm{α},\mathrm{β}}=\mathrm{Matrix}\left(4,\mathrm{symbol}=C\right)$
 ${{C}}_{{\mathrm{α}}{,}{\mathrm{β}}}{=}\left(\left[\begin{array}{cccc}{C}_{1,1}& {C}_{1,2}& {C}_{1,3}& {C}_{1,4}\\ {C}_{2,1}& {C}_{2,2}& {C}_{2,3}& {C}_{2,4}\\ {C}_{3,1}& {C}_{3,2}& {C}_{3,3}& {C}_{3,4}\\ {C}_{4,1}& {C}_{4,2}& {C}_{4,3}& {C}_{4,4}\end{array}\right]\right)$ (66)
 > $\mathrm{Define}\left(\right)$
 $\mathrm{Defined objects with tensor properties}$
 $\left\{{{A}}_{{\mathrm{\mu }}}{,}{{C}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}}{,}{{\mathrm{\gamma }}}_{{\mathrm{\mu }}}{,}{{F}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{\mathrm{\sigma }}}_{{\mathrm{\mu }}}{,}{{\partial }}_{{\mathrm{\mu }}}{,}{{g}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{p}}_{{\mathrm{\mu }}}{,}{{\mathrm{\epsilon }}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{X}}_{{\mathrm{\mu }}}{,}{{Z}}_{{\mathrm{\mu }}}\right\}$ (67)
 >
 ${{T}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}}{=}{{C}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}}{-}\frac{{{g}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}}{}{{C}}_{{\mathrm{\mu }}\phantom{{\mathrm{\mu }}}}^{\phantom{{\mathrm{\mu }}}{\mathrm{\mu }}}}{{4}}$ (68)
 > $\mathrm{Define}\left(\right)$
 $\mathrm{Defined objects with tensor properties}$
 $\left\{{{A}}_{{\mathrm{\mu }}}{,}{{C}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}}{,}{{\mathrm{\gamma }}}_{{\mathrm{\mu }}}{,}{{F}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{\mathrm{\sigma }}}_{{\mathrm{\mu }}}{,}{{T}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}}{,}{{\partial }}_{{\mathrm{\mu }}}{,}{{g}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{p}}_{{\mathrm{\mu }}}{,}{{\mathrm{\epsilon }}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{X}}_{{\mathrm{\mu }}}{,}{{Z}}_{{\mathrm{\mu }}}\right\}$ (69)
 > $T\left[\right]$
 ${{T}}_{{\mathrm{μ}}{,}{\mathrm{ν}}}{=}\left(\left[\begin{array}{cccc}\frac{3}{4}{}{C}_{1,1}-\frac{1}{4}{}{C}_{2,2}-\frac{1}{4}{}{C}_{3,3}+\frac{1}{4}{}{C}_{4,4}& {C}_{1,2}& {C}_{1,3}& {C}_{1,4}\\ {C}_{2,1}& \frac{3}{4}{}{C}_{2,2}-\frac{1}{4}{}{C}_{1,1}-\frac{1}{4}{}{C}_{3,3}+\frac{1}{4}{}{C}_{4,4}& {C}_{2,3}& {C}_{2,4}\\ {C}_{3,1}& {C}_{3,2}& \frac{3}{4}{}{C}_{3,3}-\frac{1}{4}{}{C}_{1,1}-\frac{1}{4}{}{C}_{2,2}+\frac{1}{4}{}{C}_{4,4}& {C}_{3,4}\\ {C}_{4,1}& {C}_{4,2}& {C}_{4,3}& \frac{3}{4}{}{C}_{4,4}+\frac{1}{4}{}{C}_{1,1}+\frac{1}{4}{}{C}_{2,2}+\frac{1}{4}{}{C}_{3,3}\end{array}\right]\right)$ (70)
 >
 ${{T}}_{{\mathrm{\alpha }}\phantom{{\mathrm{\alpha }}}}^{\phantom{{\mathrm{\alpha }}}{\mathrm{\alpha }}}{=}{0}$ (71) Automatic formatting of repeated tensor indices and handling of their collisions in products

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

 > $\mathrm{restart};\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathrm{with}\left(\mathrm{Physics}\right):$

Define two tensors

 >
 $\mathrm{Defined objects with tensor properties}$
 $\left\{{{A}}_{{\mathrm{\mu }}}{,}{{B}}_{{\mathrm{\mu }}}{,}{{\mathrm{\gamma }}}_{{\mathrm{\mu }}}{,}{{\mathrm{\sigma }}}_{{\mathrm{\mu }}}{,}{{\partial }}_{{\mathrm{\mu }}}{,}{{g}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{\mathrm{\epsilon }}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}\right\}$ (72)

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

 > $A{\left[\mathrm{mu}\right]}^{2}$
 ${{A}}_{{\mathrm{\mu }}}{}{{A}}_{\phantom{{}}\phantom{{\mathrm{\mu }}}}^{\phantom{{}}{\mathrm{\mu }}}$ (73)
 >
 ${{A}}_{{\mathrm{\mu }}}{}{{B}}_{\phantom{{}}\phantom{{\mathrm{\mu }}}}^{\phantom{{}}{\mathrm{\mu }}}$ (74)

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}}_{\phantom{{}}\phantom{{\mathrm{\mu }}}}^{\phantom{{}}{\mathrm{\mu }}}{}{{B}}_{{\mathrm{\mu }}}$ (75)
 • Automatic handling of collisions of contracted indices in products  Consider two tensorial expressions, say $\mathrm{E__1}$ and $\mathrm{E__2}$, that have the same contracted indices, for example (74) and (75)
 >
 $\mathrm{E__1}{≔}{{A}}_{{\mathrm{\mu }}}{}{{B}}_{\phantom{{}}\phantom{{\mathrm{\mu }}}}^{\phantom{{}}{\mathrm{\mu }}}$ (76)
 >
 $\mathrm{E__2}{≔}{{A}}_{\phantom{{}}\phantom{{\mathrm{\mu }}}}^{\phantom{{}}{\mathrm{\mu }}}{}{{B}}_{{\mathrm{\mu }}}$ (77)

If you multiply $\mathrm{E__1}\cdot \mathrm{E__2}$ there shouldn't be any problem. However, from the point of view of the summation rule for repeated indices the index $\mathrm{μ}$ 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 $\mathrm{μ}$ in $\mathrm{E__2}$ is replaced by $\mathrm{ν}$

 >
 ${{A}}_{{\mathrm{\mu }}}{}{{B}}_{\phantom{{}}\phantom{{\mathrm{\mu }}}}^{\phantom{{}}{\mathrm{\mu }}}{}{{A}}_{\phantom{{}}\phantom{{\mathrm{\nu }}}}^{\phantom{{}}{\mathrm{\nu }}}{}{{B}}_{{\mathrm{\nu }}}$ (78)

This expression now has two pairs of repeated indices and checks out

 > $\mathrm{Check}\left(\right)$
 $\mathrm{The repeated and free indices in the given expression check ok.}$ (79)

Therefore, multiplying it by itself should not be a problem

 > ${2}^{}$
 ${{A}}_{{\mathrm{\mu }}}{}{{B}}_{\phantom{{}}\phantom{{\mathrm{\mu }}}}^{\phantom{{}}{\mathrm{\mu }}}{}{{A}}_{\phantom{{}}\phantom{{\mathrm{\nu }}}}^{\phantom{{}}{\mathrm{\nu }}}{}{{B}}_{{\mathrm{\nu }}}{}{{A}}_{{\mathrm{\alpha }}}{}{{B}}_{\phantom{{}}\phantom{{\mathrm{\alpha }}}}^{\phantom{{}}{\mathrm{\alpha }}}{}{{A}}_{\phantom{{}}\phantom{{\mathrm{\beta }}}}^{\phantom{{}}{\mathrm{\beta }}}{}{{B}}_{{\mathrm{\beta }}}$ (80)
 > $\mathrm{Check}\left(\right)$
 $\mathrm{The repeated and free indices in the given expression check ok.}$ (81)

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

 > $\mathrm{E__1}$
 ${{A}}_{{\mathrm{\mu }}}{}{{B}}_{\phantom{{}}\phantom{{\mathrm{\mu }}}}^{\phantom{{}}{\mathrm{\mu }}}$ (82)
 >
 ${{A}}_{{\mathrm{\mu }}}{}{{A}}_{{\mathrm{\nu }}}{}{{B}}_{\phantom{{}}\phantom{{\mathrm{\nu }}}}^{\phantom{{}}{\mathrm{\nu }}}$ (83)

When introducing replacements to resolve the collision of repeated indices in products, special care is taken such that the introduced indices:

 a are of the same kind as the ones being replaced;
 b were not already present in the expression where they are being introduced;

To prevent the system from introducing a certain index, say $\mathrm{ν}$, before multiplying $\mathrm{E__1}\cdot \mathrm{E__2}$ you can assign it to _Env_Physics_indices_in_use

 >
 ${\mathrm{_Env_Physics_indices_in_use}}{≔}{\mathrm{\nu }}$ (84)

Now you have

 >
 ${{A}}_{{\mathrm{\mu }}}{}{{B}}_{\phantom{{}}\phantom{{\mathrm{\mu }}}}^{\phantom{{}}{\mathrm{\mu }}}{}{{A}}_{\phantom{{}}\phantom{{\mathrm{\alpha }}}}^{\phantom{{}}{\mathrm{\alpha }}}{}{{B}}_{{\mathrm{\alpha }}}$ (85)
 >
 ${\mathrm{_Env_Physics_indices_in_use}}{≔}{\mathrm{\nu }}{,}{\mathrm{\alpha }}$ (86)
 >
 ${{A}}_{{\mathrm{\mu }}}{}{{B}}_{\phantom{{}}\phantom{{\mathrm{\mu }}}}^{\phantom{{}}{\mathrm{\mu }}}{}{{A}}_{\phantom{{}}\phantom{{\mathrm{\beta }}}}^{\phantom{{}}{\mathrm{\beta }}}{}{{B}}_{{\mathrm{\beta }}}$ (87) Tensor symmetries

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.

 > $\mathrm{restart};\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathrm{with}\left(\mathrm{Physics}\right):$
 >
 $\mathrm{Defined objects with tensor properties}$
 $\left\{{{B}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{\mathrm{\gamma }}}_{{\mathrm{\mu }}}{,}{{\mathrm{\sigma }}}_{{\mathrm{\mu }}}{,}{{\partial }}_{{\mathrm{\mu }}}{,}{{g}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{\mathrm{\epsilon }}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}\right\}$ (88)

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

 >
 ${{B}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{-}{{B}}_{{\mathrm{\nu }}{,}{\mathrm{\mu }}}$ (89)
 > $\mathrm{Simplify}\left(\right)$
 ${0}$ (90)

Alternatively, by passing the keyword minimizetensorcomponents the symmetry indicated is automatically taken into account

 >
 $\mathrm{Defined objects with tensor properties}$
 $\left\{{{B}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{\mathrm{\gamma }}}_{{\mathrm{\mu }}}{,}{{\mathrm{\sigma }}}_{{\mathrm{\mu }}}{,}{{\partial }}_{{\mathrm{\mu }}}{,}{{g}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{\mathrm{\epsilon }}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}\right\}$ (91)
 >
 ${0}$ (92)

Consider now a tensor with four indices ${R}_{\mathrm{α},\mathrm{β},\mathrm{μ},\mathrm{ν}}$ which has the symmetries of the Riemann tensor. This tensor is antisymmetric with respect to interchanging the positions of$\mathrm{α}↔\mathrm{β}$ or $\mathrm{μ}↔\mathrm{ν}$, and symmetric with respect to interchanging the positions of the 1st and 2nd pairs of indices$\left[\mathrm{α},\mathrm{β}\right]$ ↔ $\left[\mathrm{μ},\mathrm{ν}\right]$. You can indicate these symmetries by specifying the indices themselves or their numerical position

 >
 $\mathrm{Defined objects with tensor properties}$
 $\left\{{{B}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{\mathrm{\gamma }}}_{{\mathrm{\mu }}}{,}{{\mathrm{\sigma }}}_{{\mathrm{\mu }}}{,}{{R}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{\partial }}_{{\mathrm{\mu }}}{,}{{g}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{\mathrm{\epsilon }}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}\right\}$ (93)

To retrieve the symmetries of a tensor, use Library:-GetTensorSymmetryProperties

 > $\mathrm{Library}:-\mathrm{GetTensorSymmetryProperties}\left(R\right)$
 $\left\{\left[\left[{1}{,}{2}\right]{,}\left[{3}{,}{4}\right]\right]\right\}{,}\left\{\left[{1}{,}{2}\right]{,}\left[{3}{,}{4}\right]\right\}$ (94)

Redoing the definition of ${R}_{\mathrm{α},\mathrm{β},\mathrm{μ},\mathrm{ν}}$, this time using minimizetensorcomponents, allows, among other things, for counting of the number of independent components of R

 >
 $\mathrm{Defined objects with tensor properties}$
 $\left\{{{B}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{\mathrm{\gamma }}}_{{\mathrm{\mu }}}{,}{{\mathrm{\sigma }}}_{{\mathrm{\mu }}}{,}{{R}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}{,}{\mathrm{\alpha }}{,}{\mathrm{\beta }}}{,}{{\partial }}_{{\mathrm{\mu }}}{,}{{g}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{\mathrm{\epsilon }}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}\right\}$ (95)

Out of the ${4}^{4}=256$ components only 21 are independent, due to the symmetries indicated

 > $\mathrm{Library}:-\mathrm{NumberOfIndependentTensorComponents}\left(R\right)$
 ${21}$ (96)

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}_{\mathrm{\alpha },\mathrm{\beta },\mathrm{\mu },\mathrm{\nu }}$, 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

 > $\mathrm{Weyl}\left[\mathrm{definition}\right]$
 ${{C}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}{=}{{R}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}{-}\frac{{{R}}_{{\mathrm{\alpha }}{,}{\mathrm{\mu }}}{}{{g}}_{{\mathrm{\beta }}{,}{\mathrm{\nu }}}}{{2}}{+}\frac{{{R}}_{{\mathrm{\alpha }}{,}{\mathrm{\nu }}}{}{{g}}_{{\mathrm{\beta }}{,}{\mathrm{\mu }}}}{{2}}{+}\frac{{{R}}_{{\mathrm{\beta }}{,}{\mathrm{\mu }}}{}{{g}}_{{\mathrm{\alpha }}{,}{\mathrm{\nu }}}}{{2}}{-}\frac{{{R}}_{{\mathrm{\beta }}{,}{\mathrm{\nu }}}{}{{g}}_{{\mathrm{\alpha }}{,}{\mathrm{\mu }}}}{{2}}{+}\left(\frac{{{g}}_{{\mathrm{\alpha }}{,}{\mathrm{\mu }}}{}{{g}}_{{\mathrm{\beta }}{,}{\mathrm{\nu }}}}{{6}}{-}\frac{{{g}}_{{\mathrm{\alpha }}{,}{\mathrm{\nu }}}{}{{g}}_{{\mathrm{\beta }}{,}{\mathrm{\mu }}}}{{6}}\right){}{{R}}_{{\mathrm{\kappa }}\phantom{{\mathrm{\kappa }}}}^{\phantom{{\mathrm{\kappa }}}{\mathrm{\kappa }}}$ (97)

Converting it to Riemann, without evaluating tensors, and substituting Riemann with R and Weyl with W, you get

 >
 ${{W}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}{=}{{R}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}{-}\frac{{{R}}_{\phantom{{}}\phantom{{\mathrm{\kappa }}}{\mathrm{\alpha }}{,}{\mathrm{\kappa }}{,}{\mathrm{\mu }}}^{\phantom{{}}{\mathrm{\kappa }}\phantom{{\mathrm{\alpha }}{,}{\mathrm{\kappa }}{,}{\mathrm{\mu }}}}{}{{g}}_{{\mathrm{\beta }}{,}{\mathrm{\nu }}}}{{2}}{+}\frac{{{R}}_{\phantom{{}}\phantom{{\mathrm{\kappa }}}{\mathrm{\alpha }}{,}{\mathrm{\kappa }}{,}{\mathrm{\nu }}}^{\phantom{{}}{\mathrm{\kappa }}\phantom{{\mathrm{\alpha }}{,}{\mathrm{\kappa }}{,}{\mathrm{\nu }}}}{}{{g}}_{{\mathrm{\beta }}{,}{\mathrm{\mu }}}}{{2}}{+}\frac{{{R}}_{\phantom{{}}\phantom{{\mathrm{\kappa }}}{\mathrm{\beta }}{,}{\mathrm{\kappa }}{,}{\mathrm{\mu }}}^{\phantom{{}}{\mathrm{\kappa }}\phantom{{\mathrm{\beta }}{,}{\mathrm{\kappa }}{,}{\mathrm{\mu }}}}{}{{g}}_{{\mathrm{\alpha }}{,}{\mathrm{\nu }}}}{{2}}{-}\frac{{{R}}_{\phantom{{}}\phantom{{\mathrm{\kappa }}}{\mathrm{\beta }}{,}{\mathrm{\kappa }}{,}{\mathrm{\nu }}}^{\phantom{{}}{\mathrm{\kappa }}\phantom{{\mathrm{\beta }}{,}{\mathrm{\kappa }}{,}{\mathrm{\nu }}}}{}{{g}}_{{\mathrm{\alpha }}{,}{\mathrm{\mu }}}}{{2}}{+}\left(\frac{{{g}}_{{\mathrm{\alpha }}{,}{\mathrm{\mu }}}{}{{g}}_{{\mathrm{\beta }}{,}{\mathrm{\nu }}}}{{6}}{-}\frac{{{g}}_{{\mathrm{\alpha }}{,}{\mathrm{\nu }}}{}{{g}}_{{\mathrm{\beta }}{,}{\mathrm{\mu }}}}{{6}}\right){}{{R}}_{\phantom{{}}\phantom{{\mathrm{\lambda }}}{\mathrm{\kappa }}{,}{\mathrm{\lambda }}\phantom{{\mathrm{\kappa }}}}^{\phantom{{}}{\mathrm{\lambda }}\phantom{{\mathrm{\kappa }}{,}{\mathrm{\lambda }}}{\mathrm{\kappa }}}$ (98)

Now define ${W}_{\mathrm{\alpha },\mathrm{\beta },\mathrm{\mu },\mathrm{\nu }}$ using this tensorial equation

 >
 $\mathrm{Defined objects with tensor properties}$
 $\left\{{{B}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{\mathrm{\gamma }}}_{{\mathrm{\mu }}}{,}{{\mathrm{\sigma }}}_{{\mathrm{\mu }}}{,}{{R}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}{,}{\mathrm{\alpha }}{,}{\mathrm{\beta }}}{,}{{W}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{\partial }}_{{\mathrm{\mu }}}{,}{{g}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{\mathrm{\epsilon }}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}\right\}$ (99)

While the number of independent components of R is 21, W only has the expected 10 and is traceless

 > $\mathrm{Library}:-\mathrm{NumberOfIndependentTensorComponents}\left(W\right)$
 ${10}$ (100)
 > ${W}_{\phantom{}\phantom{\mathrm{\alpha }}\mathrm{\alpha },\mathrm{\mu },\mathrm{\nu }}^{\phantom{}\mathrm{\alpha }\phantom{\mathrm{\alpha },\mathrm{\mu },\mathrm{\nu }}}$
 ${0}$ (101)
 • 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}_{\mathrm{\alpha },\mathrm{\beta },\mathrm{\mu },\mathrm{\nu }}$ with respect to $\mathrm{α}↔\mathrm{μ}$ and antisymmetrizing the result with respect to $\mathrm{β}\mathit{↔}\mathrm{μ}$, then define a new tensor ${U}_{\mathrm{α},\mathrm{β},\mathrm{μ},\mathrm{ν}}$ using the resulting tensorial expression. Note that ${U}_{\mathrm{α},\mathrm{β},\mathrm{μ},\mathrm{ν}}$  will also have the symmetries and tracelessness of ${W}_{\mathrm{\alpha },\mathrm{\beta },\mathrm{\mu },\mathrm{\nu }}$.

 > $\mathrm{Symmetrize}\left({W}_{\mathrm{α},\mathrm{β},\mathrm{μ},\mathrm{ν}},\left[\mathrm{α},\mathrm{μ}\right]\right)$
 $\frac{{{W}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}}{{2}}{-}\frac{{{W}}_{{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\alpha }}{,}{\mathrm{\nu }}}}{{2}}$ (102)
 > ${U}_{\mathrm{\alpha },\mathrm{\beta },\mathrm{\mu },\mathrm{\nu }}=\mathrm{Antisymmetrize}\left(,\left[\mathrm{β},\mathrm{μ}\right]\right)$
 ${{U}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}{=}\frac{{{W}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}}{{4}}{-}\frac{{{W}}_{{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\alpha }}{,}{\mathrm{\nu }}}}{{2}}{-}\frac{{{W}}_{{\mathrm{\alpha }}{,}{\mathrm{\mu }}{,}{\mathrm{\beta }}{,}{\mathrm{\nu }}}}{{4}}$ (103)
 > $\mathrm{Define}\left(,\mathrm{minimizetensorcomponents}\right)$
 $\mathrm{Defined objects with tensor properties}$
 $\left\{{{B}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{\mathrm{\gamma }}}_{{\mathrm{\mu }}}{,}{{\mathrm{\sigma }}}_{{\mathrm{\mu }}}{,}{{R}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}{,}{\mathrm{\alpha }}{,}{\mathrm{\beta }}}{,}{{U}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{W}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{\partial }}_{{\mathrm{\mu }}}{,}{{g}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{\mathrm{\epsilon }}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}\right\}$ (104)

The number of independent tensor components of ${U}_{\mathrm{\alpha },\mathrm{\beta },\mathrm{\mu },\mathrm{\nu }}$ is

 > $\mathrm{Library}:-\mathrm{NumberOfIndependentTensorComponents}\left(U\right)$
 ${8}$ (105) Substituting tensors and tensor indices

Two common operations with tensorial expressions are substituting tensors and substituting tensor indices. The Physics commands for these purposes are SubstituteTensor and SubstituteTensorIndices.

 >
 > $\mathrm{Define}\left(A,B,C,F,G\right)$
 $\mathrm{Defined objects with tensor properties}$
 $\left\{{A}{,}{B}{,}{C}{,}{F}{,}{G}{,}{{\mathrm{\gamma }}}_{{\mathrm{\mu }}}{,}{{\mathrm{\sigma }}}_{{\mathrm{\mu }}}{,}{{\partial }}_{{\mathrm{\mu }}}{,}{{g}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{\mathrm{\epsilon }}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}\right\}$ (106)
 > $\mathrm{EQ}≔A\left[\mathrm{\mu }\right]=G\left[\mathrm{\nu },\mathrm{\alpha }\right]A\left[\mathrm{\alpha }\right]F\left[\mathrm{\mu },\mathrm{\nu }\right]$
 ${\mathrm{EQ}}{≔}{{A}}_{{\mathrm{\mu }}}{=}{{G}}_{{\mathrm{\nu }}{,}{\mathrm{\alpha }}}{}{{A}}_{\phantom{{}}\phantom{{\mathrm{\alpha }}}}^{\phantom{{}}{\mathrm{\alpha }}}{}{{F}}_{{\mathrm{\mu }}\phantom{{\mathrm{\nu }}}}^{\phantom{{\mathrm{\mu }}}{\mathrm{\nu }}}$ (107)

The repeated and free indices of the left and right-hand sides of this equation are

 > $\mathrm{Check}\left(\mathrm{EQ},\mathrm{all}\right)$
 $\mathrm{The repeated indices per term are:}\left[\left\{\mathrm{...}\right\}{,}\left\{\mathrm{...}\right\}{,}\mathrm{...}\right]\mathrm{, the free indices are:}\left\{\mathrm{...}\right\}$
 $\left(\left[{\varnothing }\right]{,}\left\{{\mathrm{\mu }}\right\}\right){=}\left(\left[\left\{{\mathrm{\alpha }}{,}{\mathrm{\nu }}\right\}\right]{,}\left\{{\mathrm{\mu }}\right\}\right)$ (108)

The easy case: using EQ to substitute $A\left[\mathrm{\mu }\right]$in $A\left[\mathrm{\mu }\right]$ itself

 > $\mathrm{SubstituteTensor}\left(\mathrm{EQ},A\left[\mathrm{\mu }\right]\right)$
 ${{G}}_{{\mathrm{\nu }}{,}{\mathrm{\alpha }}}{}{{A}}_{\phantom{{}}\phantom{{\mathrm{\alpha }}}}^{\phantom{{}}{\mathrm{\alpha }}}{}{{F}}_{{\mathrm{\mu }}\phantom{{\mathrm{\nu }}}}^{\phantom{{\mathrm{\mu }}}{\mathrm{\nu }}}$ (109)

The same operation, but now the free index in the target expression is $\mathrm{\nu }$ instead of $\mathrm{\mu }$

 > $\mathrm{SubstituteTensor}\left(\mathrm{EQ},A\left[\mathrm{\nu }\right]\right)$
 ${{G}}_{{\mathrm{\beta }}{,}{\mathrm{\alpha }}}{}{{A}}_{\phantom{{}}\phantom{{\mathrm{\alpha }}}}^{\phantom{{}}{\mathrm{\alpha }}}{}{{F}}_{{\mathrm{\nu }}\phantom{{\mathrm{\beta }}}}^{\phantom{{\mathrm{\nu }}}{\mathrm{\beta }}}$ (110)

The same operation, but now the target is ${A}_{\phantom{}\phantom{\mathrm{\nu }}}^{\phantom{}\mathrm{\nu }}$

 > $\mathrm{SubstituteTensor}\left(\mathrm{EQ},{A}_{\phantom{}\phantom{\mathrm{\nu }}}^{\phantom{}\mathrm{\nu }}\right)$
 ${{G}}_{{\mathrm{\beta }}{,}{\mathrm{\alpha }}}{}{{A}}_{\phantom{{}}\phantom{{\mathrm{\alpha }}}}^{\phantom{{}}{\mathrm{\alpha }}}{}{{F}}_{\phantom{{}}\phantom{{\mathrm{\nu }}{,}{\mathrm{\beta }}}}^{\phantom{{}}{\mathrm{\nu }}{,}{\mathrm{\beta }}}$ (111)

An example where the index $\mathrm{\nu }$, which is repeated in the right-hand side of EQ, is also repeated in the target expression:

 > $\mathrm{ee}≔A\left[\mathrm{\nu }\right]A\left[\mathrm{\nu }\right]$
 ${\mathrm{ee}}{≔}{{A}}_{{\mathrm{\nu }}}{}{{A}}_{\phantom{{}}\phantom{{\mathrm{\nu }}}}^{\phantom{{}}{\mathrm{\nu }}}$ (112)

The collision of indices is resolved automatically

 > $\mathrm{res}≔\mathrm{SubstituteTensor}\left(\mathrm{EQ},\mathrm{ee}\right)$
 ${\mathrm{res}}{≔}{{G}}_{{\mathrm{\lambda }}{,}{\mathrm{\kappa }}}{}{{A}}_{\phantom{{}}\phantom{{\mathrm{\kappa }}}}^{\phantom{{}}{\mathrm{\kappa }}}{}{{F}}_{{\mathrm{\nu }}\phantom{{\mathrm{\lambda }}}}^{\phantom{{\mathrm{\nu }}}{\mathrm{\lambda }}}{}{{G}}_{{\mathrm{\beta }}{,}{\mathrm{\alpha }}}{}{{A}}_{\phantom{{}}\phantom{{\mathrm{\alpha }}}}^{\phantom{{}}{\mathrm{\alpha }}}{}{{F}}_{\phantom{{}}\phantom{{\mathrm{\nu }}{,}{\mathrm{\beta }}}}^{\phantom{{}}{\mathrm{\nu }}{,}{\mathrm{\beta }}}$ (113)

The repeated and free indices of this result are

 > $\mathrm{Check}\left(\mathrm{res},\mathrm{all}\right)$
 $\mathrm{The repeated indices per term are:}\left[\left\{\mathrm{...}\right\}{,}\left\{\mathrm{...}\right\}{,}\mathrm{...}\right]\mathrm{, the free indices are:}\left\{\mathrm{...}\right\}$
 $\left[\left\{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\kappa }}{,}{\mathrm{\lambda }}{,}{\mathrm{\nu }}\right\}\right]{,}{\varnothing }$ (114)

The functionality of tensor functions is also considered a parameter when substituting tensors. For example, consider the following substitution equation

 >
 $\mathrm{EQ__2}{≔}{{A}}_{{\mathrm{\mu }}}{}\left({X}\right){=}{{B}}_{{\mathrm{\mu }}}{}\left({X}\right)$ (115)

Now substitute in ${A}_{\mathrm{\nu }}\left(Y\right)$

 >
 ${{B}}_{{\mathrm{\nu }}}{}\left({Y}\right)$ (116)

SubstituteTensor also substitutes sub-expressions like algsubs. For example

 > $\mathrm{EQ__3}≔A\left[\mathrm{\mu }\right]\left(X\right)B\left[\mathrm{\nu }\right]\left(Y\right)=G\left[\mathrm{\mu },\mathrm{\nu }\right]\left(X\right)$
 $\mathrm{EQ__3}{≔}{{A}}_{{\mathrm{\mu }}}{}\left({X}\right){}{{B}}_{{\mathrm{\nu }}}{}\left({Y}\right){=}{{G}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{}\left({X}\right)$ (117)

The target expression is

 > $A\left[\mathrm{\alpha }\right]\left(X\right)B\left[\mathrm{\beta }\right]\left(Y\right)A\left[\mathrm{\rho }\right]\left(X\right)B\left[\mathrm{\rho }\right]\left(Y\right)$
 ${{A}}_{{\mathrm{\alpha }}}{}\left({X}\right){}{{B}}_{{\mathrm{\beta }}}{}\left({Y}\right){}{{A}}_{{\mathrm{\rho }}}{}\left({X}\right){}{{B}}_{\phantom{{}}\phantom{{\mathrm{\rho }}}}^{\phantom{{}}{\mathrm{\rho }}}{}\left({Y}\right)$ (118)

When substituting $\mathrm{EQ__3}$ into (118), the sub-expression $A\cdot B$ appears twice, once with repeated indices and once without, and is not part of the indeterminates of (118)

 > $\mathrm{indets}\left(\right)$
 $\left\{{X}{,}{Y}{,}{{A}}_{{\mathrm{\alpha }}}{}\left({X}\right){,}{{A}}_{{\mathrm{\rho }}}{}\left({X}\right){,}{{B}}_{{\mathrm{\beta }}}{}\left({Y}\right){,}{{B}}_{\phantom{{}}\phantom{{\mathrm{\rho }}}}^{\phantom{{}}{\mathrm{\rho }}}{}\left({Y}\right)\right\}$ (119)
 >
 ${{G}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}}{}\left({X}\right){}{{G}}_{{\mathrm{\rho }}\phantom{{\mathrm{\rho }}}}^{\phantom{{\mathrm{\rho }}}{\mathrm{\rho }}}{}\left({X}\right)$ (120)
 • Tensor indices can be substituted in a similar way

Consider the following target tensorial expression

 >
 $\mathrm{ee__1}{≔}{{g}}_{{\mathrm{\alpha }}{,}{\mathrm{\mu }}}{}{{A}}_{\phantom{{}}\phantom{{\mathrm{\mu }}}}^{\phantom{{}}{\mathrm{\mu }}}{}{{g}}_{\phantom{{}}\phantom{{\mathrm{\alpha }}{,}{\mathrm{\nu }}}}^{\phantom{{}}{\mathrm{\alpha }}{,}{\mathrm{\nu }}}{}{{C}}_{{\mathrm{\nu }}{,}{\mathrm{\sigma }}\phantom{{\mathrm{\rho }}}}^{\phantom{{\mathrm{\nu }}}\phantom{{,}{\mathrm{\sigma }}}{\mathrm{\rho }}}$ (121)
 > $\mathrm{Check}\left(\mathrm{ee__1},\mathrm{all}\right)$
 $\mathrm{The repeated indices per term are:}\left[\left\{\mathrm{...}\right\}{,}\left\{\mathrm{...}\right\}{,}\mathrm{...}\right]\mathrm{, the free indices are:}\left\{\mathrm{...}\right\}$
 $\left[\left\{{\mathrm{\alpha }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}\right\}\right]{,}\left\{{\mathrm{\sigma }}{,}{\mathrm{~rho}}\right\}$ (122)

Substitute the repeated index $\mathrm{α}$ that appears in covariant and contravariant forms in $\mathrm{ee__1}$

 >
 ${{g}}_{{\mathrm{\beta }}{,}{\mathrm{\mu }}}{}{{A}}_{\phantom{{}}\phantom{{\mathrm{\mu }}}}^{\phantom{{}}{\mathrm{\mu }}}{}{{g}}_{\phantom{{}}\phantom{{\mathrm{\beta }}{,}{\mathrm{\nu }}}}^{\phantom{{}}{\mathrm{\beta }}{,}{\mathrm{\nu }}}{}{{C}}_{{\mathrm{\nu }}{,}{\mathrm{\sigma }}\phantom{{\mathrm{\rho }}}}^{\phantom{{\mathrm{\nu }}}\phantom{{,}{\mathrm{\sigma }}}{\mathrm{\rho }}}$ (123)

Now substitute the contravariant index a) you don't need to prefix contravariant indices with ~ in the substitution equations; and b) the index $\mathrm{β}$ 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

 >
 ${{g}}_{{\mathrm{\alpha }}{,}{\mathrm{\mu }}}{}{{A}}_{\phantom{{}}\phantom{{\mathrm{\mu }}}}^{\phantom{{}}{\mathrm{\mu }}}{}{{g}}_{\phantom{{}}\phantom{{\mathrm{\alpha }}{,}{\mathrm{\nu }}}}^{\phantom{{}}{\mathrm{\alpha }}{,}{\mathrm{\nu }}}{}{{C}}_{{\mathrm{\nu }}{,}{\mathrm{\sigma }}\phantom{{\mathrm{\beta }}}}^{\phantom{{\mathrm{\nu }}}\phantom{{,}{\mathrm{\sigma }}}{\mathrm{\beta }}}$ (124)

To substitute several indices at once, enclose the substitution equations in a set or a list

 > $\mathrm{SubstituteTensorIndices}\left(\left[\mathrm{\rho }=\mathrm{\beta },\mathrm{\alpha }=\mathrm{\gamma }\right],\mathrm{ee__1}\right)$
 ${{g}}_{{\mathrm{\gamma }}{,}{\mathrm{\mu }}}{&Invis}$