ContractIndices - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Tensor[ContractIndices] - contract the indices of a tensor

Calling Sequences

ContractIndices(T, Indices1)

ContractIndices(T, S, Indices2)

Parameters

T         - a tensor

S         - (optional) a tensor

Indices1  - a list of pairs of integers $\left[\left[{i}_{1},{i}_{2}\right],\left[{i}_{3},{i}_{4}\right],...\right]$ referring to the arguments of T which are to be contracted

Indices2  - a list of pairs of integers $\left[\left[{i}_{1},{i}_{2}\right],\left[{i}_{3},{i}_{4}\right],...\right]$ referring to the arguments of T and S which are to be contracted

Description

 • With the first calling sequence, ContractIndices(T, Indices) will contract from $T$ each pair of indices in the list Indices = $\left[\left[{i}_{1},{i}_{2}\right],\left[{i}_{3},{i}_{4}\right],...\right]$. Each index pair must refer to indices of different valence, for example, if ${i}_{1}$ is a contravariant index, then ${i}_{2}$ must be a covariant index. If $T$ is of type $\left(\genfrac{}{}{0}{}{{r}}{{s}}\right)$ (contravariant rank $r$ and covariant rank $s$) and the list Indices1 contains $k$ index pairs, then ContractIndices(T, Indices1) will return a tensor of type $\left(\genfrac{}{}{0}{}{{r}{-}{k}}{{s}{-}{k}}\right)$.
 • With the second calling sequence, ContractIndices(T, S, Indices), where Indices = $\left[\left[{i}_{1},{i}_{2}\right],\left[{i}_{3},{i}_{4}\right],...\right]$, will contract the ${i}_{1}$ index of $T$ with the ${i}_{2}$ index $S$, the ${i}_{3}$ index of $T$ with the ${i}_{4}$ index $S$ and so on. Each index pair must refer to indices of different valence. If $T$ is of type $\left(\genfrac{}{}{0}{}{r}{s}\right)$, of type $\left(\genfrac{}{}{0}{}{p}{q}\right)$, and if the list Indices2 contains $k$ index pairs, then ContractIndices(T, Indices2) will return a tensor of type $\left(\genfrac{}{}{0}{}{r+p-k}{s+q-k}\right)$.
 • This command is part of the DifferentialGeometry:-Tensor package, and so can be used in the form ContractIndices(...) only after executing the command with(DifferentialGeometry) and with(Tensor) in that order. It can always be used in the long form DifferentialGeometry:-Tensor:-ContractIndices.

Examples

 > $\mathrm{with}\left(\mathrm{DifferentialGeometry}\right):$$\mathrm{with}\left(\mathrm{Tensor}\right):$

Example 1.

First create a 4 dimensional manifold $M$ and define a type $\left(\genfrac{}{}{0}{}{2}{3}\right)$ tensor $T$ on $M$.

 > $\mathrm{DGsetup}\left(\left[x,y,z,w\right],M\right):$
 M > $T≔\mathrm{evalDG}\left(a\left(\left(\left(\mathrm{D_x}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{D_x}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{dz}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{dx}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{dz}+b\left(\left(\left(\mathrm{D_x}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{D_z}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{dz}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{dx}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{dw}\right)$
 ${T}{:=}{a}{}{\mathrm{D_x}}{}{\mathrm{D_x}}{}{\mathrm{dz}}{}{\mathrm{dx}}{}{\mathrm{dz}}{+}{b}{}{\mathrm{D_x}}{}{\mathrm{D_z}}{}{\mathrm{dz}}{}{\mathrm{dx}}{}{\mathrm{dw}}$ (2.1)

Contract the 1st and 4th indices of $T$.

 M > $\mathrm{ContractIndices}\left(T,\left[\left[1,4\right]\right]\right)$
 ${a}{}{\mathrm{D_x}}{}{\mathrm{dz}}{}{\mathrm{dz}}{+}{b}{}{\mathrm{D_z}}{}{\mathrm{dz}}{}{\mathrm{dw}}$ (2.2)

Contract the 1st and 4th indices and the 2nd and 3rd indices of $T$.

 M > $\mathrm{ContractIndices}\left(T,\left[\left[1,4\right],\left[2,3\right]\right]\right)$
 ${b}{}{\mathrm{dw}}$ (2.3)

Example 2.

Define two rank 3 tensors $T$ and $S$.

 M > $T≔\mathrm{evalDG}\left(a\left(\mathrm{dx}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{D_z}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{D_y}+b\left(\mathrm{dx}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{D_x}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{D_x}+c\left(\mathrm{dw}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{D_w}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{D_z}\right)$
 ${T}{:=}{b}{}{\mathrm{dx}}{}{\mathrm{D_x}}{}{\mathrm{D_x}}{+}{a}{}{\mathrm{dx}}{}{\mathrm{D_z}}{}{\mathrm{D_y}}{+}{c}{}{\mathrm{dw}}{}{\mathrm{D_w}}{}{\mathrm{D_z}}$ (2.4)
 M > $S≔\mathrm{evalDG}\left(d\left(\mathrm{D_x}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{D_z}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{dy}+e\left(\mathrm{D_y}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{D_x}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{dz}+f\left(\mathrm{D_w}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{D_w}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{dw}\right)$
 ${S}{:=}{d}{}{\mathrm{D_x}}{}{\mathrm{D_z}}{}{\mathrm{dy}}{+}{e}{}{\mathrm{D_y}}{}{\mathrm{D_x}}{}{\mathrm{dz}}{+}{f}{}{\mathrm{D_w}}{}{\mathrm{D_w}}{}{\mathrm{dw}}$ (2.5)

Form the tensor product $T\otimes S$ and contract the 1st index of $T$ against the 1st index of $S$.

 M > $\mathrm{ContractIndices}\left(T,S,\left[\left[1,1\right]\right]\right)$
 ${b}{}{d}{}{\mathrm{D_x}}{}{\mathrm{D_x}}{}{\mathrm{D_z}}{}{\mathrm{dy}}{+}{a}{}{d}{}{\mathrm{D_z}}{}{\mathrm{D_y}}{}{\mathrm{D_z}}{}{\mathrm{dy}}{+}{c}{}{f}{}{\mathrm{D_w}}{}{\mathrm{D_z}}{}{\mathrm{D_w}}{}{\mathrm{dw}}$ (2.6)

Form the tensor product $T\otimes S$ and contract the 1st index of $T$ against the 1st index of $S$ and the 2nd index of $T$ against the 3rd index of $S$.

 M > $\mathrm{ContractIndices}\left(T,S,\left[\left[1,1\right],\left[2,3\right]\right]\right)$
 ${c}{}{f}{}{\mathrm{D_z}}{}{\mathrm{D_w}}$ (2.7)

Example 3.

Define a type $\left(\genfrac{}{}{0}{}{1}{3}\right)$ tensor $T$ and evaluate it on the1-form ${\mathrm{α}}_{}$ and the vectors $X,Y,Z$.

 M > $T≔\mathrm{evalDG}\left(a\left(\left(\mathrm{D_x}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{dx}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{dz}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{dy}+b\left(\left(\mathrm{D_y}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{dx}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{dx}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{dz}+c\left(\left(\mathrm{D_w}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{dx}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{dy}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{dz}\right)$
 ${T}{:=}{a}{}{\mathrm{D_x}}{}{\mathrm{dx}}{}{\mathrm{dz}}{}{\mathrm{dy}}{+}{b}{}{\mathrm{D_y}}{}{\mathrm{dx}}{}{\mathrm{dx}}{}{\mathrm{dz}}{+}{c}{}{\mathrm{D_w}}{}{\mathrm{dx}}{}{\mathrm{dy}}{}{\mathrm{dz}}$ (2.8)
 M > $\mathrm{\alpha }≔\mathrm{evalDG}\left(\mathrm{dx}-\mathrm{dy}+\mathrm{dz}-3\mathrm{dw}\right)$
 ${\mathrm{α}}{:=}{\mathrm{dx}}{-}{\mathrm{dy}}{+}{\mathrm{dz}}{-}{3}{}{\mathrm{dw}}$ (2.9)
 M > $X≔\mathrm{D_x}:$$Y≔\mathrm{D_y}:$$Z≔\mathrm{D_z}:$
 M > $\mathrm{ContractIndices}\left(T,\left(\left(\mathrm{\alpha }\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}X\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}Y\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}&t\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}Z,\left[\left[1,1\right],\left[2,2\right],\left[3,3\right],\left[4,4\right]\right]\right)$
 ${-}{3}{}{c}$ (2.10)