 Substitute - Maple Help

Physics[Substitute] - substitute tensor indices, tensorial expressions, non-commutative products possibly involving tensors, combining into one command all of subs, algsubs, SubstituteTensor, SubstituteTensorIndices,  Library:-SubstituteMatrix and Library:-SubstituteOperator Calling Sequence Substitute(EQ, ..., ee, evaluateexpression, ) Parameters

 EQ - a substitution equation, a list or set of them, or a sequence of any of these, typically involving tensor indices or tensors, or noncommutative objects, or sums or products of them, on the left-hand sides ee - the target where the substitutions EQ, ... are to be performed, it is the last argument after the substitution equations; ee can be any Maple object (expression, list, etc.) typically involving tensors or tensorial expressions with free and/or repeated tensor indices and/or noncommutative objects products or powers evaluateexpression - optional, when given, the substitutions in ee are performed and the result fully evaluated - optional, can be any of the options of the commands SubstituteTensor, SubstituteTensorIndices, Library:-SubstituteOperator or the indexing options of the subs command as in Substitute[subs_options](...) Description

 • Substitute substitutes the equation(s) EQ into ee, unifying in one command all of subs, algsubs, SubstituteTensor, SubstituteTensorIndices, Library:-SubstituteMatrix and Library:-SubstituteOperator. In this sense, Substitute performs mathematical substitutions instead of just syntactical ones as subs and eval do. A list of typical examples:
 – If Greek letters are tensor indices, $\mathrm{EQ}≔\mathrm{\mu }=\mathrm{\nu }$ and the target ee is a tensorial expression, the substitution is automatically forwarded to SubstituteTensorIndices and will substitute both covariant ($\mathrm{\mu }$) and contravariant ($\mathrm{~μ}$) indices, and perform the substitution only in tensor indices, not otherwise.
 – If $\mathrm{EQ}$ is a tensorial equation, with or without free indices on the left and right hand sides, the task is automatically forwarded to SubstituteTensor.
 – If $\mathrm{EQ}$ involves Matrix or Vector constructions, the task is automatically forwarded to Library:-SubstituteMatrix.
 – If $\mathrm{EQ}$ involves products, sums or powers, with or without non-commutative objects, the substitution task is automatically forwarded to Library:-SubstituteOperator which combines three different strategies involving algsubs that handles simple cases, simplify/siderels that uses a more thorough approach involving Groebner basis, and an algorithm dedicated to perform substitutions of sub-products of noncommutative products (say $AB$ in $ABC$), as well as sub-sums (say $A+B$ in $A+B+C$).
 • All the optional arguments accepted by SubstituteTensor, SubstituteTensorIndices or Library:-SubstituteOperator can be passed, as such, to Substitute, and the indexing options of the subs command are also understood by Substitute provided you pass them indexing the command, as in Substitute[subs_options](...). Conflicting options - accepted by one command but not by another one - are not a problem: if an option passed is not accepted by the command actually performing the substitution, that option is ignored.
 • The special keyword $\mathrm{evaluateexpression}$ is understood by all the commands used by Substitute; if that option is passed and the command used to perform the action is subs, then subs is used as in subs[eval]. Examples

 > $\mathrm{with}\left(\mathrm{Physics}\right):$
 > $\mathrm{Setup}\left(\mathrm{mathematicalnotation}=\mathrm{true}\right)$
 $\left[{\mathrm{mathematicalnotation}}{=}{\mathrm{true}}\right]$ (1) Substitutions of matrices, sub-products and sub-sums, possibly involving noncommutative objects

 > $\mathrm{eq}≔F+AB\left(x\right)={E}_{j}$
 ${\mathrm{eq}}{≔}{F}{+}{A}{}{B}{}\left({x}\right){=}{{E}}_{{j}}$ (2)
 > $\mathrm{ee}≔AB\left(x\right)C$
 ${\mathrm{ee}}{≔}{A}{}{B}{}\left({x}\right){}{C}$ (3)
 > $\mathrm{Substitute}\left(\mathrm{eq},\mathrm{ee}\right)$
 ${-}{C}{}\left({F}{-}{{E}}_{{j}}\right)$ (4)
 Substitution of matrices and vectors taking mathematical equality into account
 > $\mathrm{eq}≔\mathrm{Matrix}\left(2,\mathrm{symbol}=a\right)=\mathrm{β}+\mathrm{Matrix}\left(2,\mathrm{symbol}=b\right)$
 $\left(\left[\begin{array}{cc}{a}_{1,1}& {a}_{1,2}\\ {a}_{2,1}& {a}_{2,2}\end{array}\right]\right){=}{\mathrm{β}}{+}\left(\left[\begin{array}{cc}{b}_{1,1}& {b}_{1,2}\\ {b}_{2,1}& {b}_{2,2}\end{array}\right]\right)$ (5)
 > $\mathrm{ee}≔\mathrm{Matrix}\left(2,\mathrm{symbol}=a\right)$
 $\left[\begin{array}{cc}{a}_{1,1}& {a}_{1,2}\\ {a}_{2,1}& {a}_{2,2}\end{array}\right]$ (6)
 Although the target expression ee consists of a Matrix and the left hand side of eq is a matrix mathematically equal to ee, each Matrix is an independent object so syntactically they are not equal:
 > $\mathrm{lhs}\left(\mathrm{eq}\right)=\mathrm{ee}$
 $\left(\left[\begin{array}{cc}{a}_{1,1}& {a}_{1,2}\\ {a}_{2,1}& {a}_{2,2}\end{array}\right]\right){=}\left(\left[\begin{array}{cc}{a}_{1,1}& {a}_{1,2}\\ {a}_{2,1}& {a}_{2,2}\end{array}\right]\right)$ (7)
 > $\mathrm{evalb}\left(\right)$
 ${\mathrm{false}}$ (8)
 These cases are handled by Substitute as one would expect, by recognizing the left-hand side of eq as mathematically equal to ee
 > $\mathrm{Substitute}\left(\mathrm{eq},\mathrm{ee}\right)$
 ${\mathrm{β}}{+}\left(\left[\begin{array}{cc}{b}_{1,1}& {b}_{1,2}\\ {b}_{2,1}& {b}_{2,2}\end{array}\right]\right)$ (9)
 Substitute performs the substitution in the presence of Matrix or Vector constructions not just in the natural case above but in general, in all the cases it can handle
 > $\mathrm{eq}≔\mathrm{α}+\mathrm{Matrix}\left(2,2,\left[\left[{a}_{1,1},{a}_{1,2}\right],\left[{a}_{2,1},{a}_{2,2}\right]\right]\right)=\mathrm{β}+\mathrm{Matrix}\left(2,2,\left[\left[{b}_{1,1},{b}_{1,2}\right],\left[{b}_{2,1},{b}_{2,2}\right]\right]\right)$
 ${\mathrm{α}}{+}\left(\left[\begin{array}{cc}{a}_{1,1}& {a}_{1,2}\\ {a}_{2,1}& {a}_{2,2}\end{array}\right]\right){=}{\mathrm{β}}{+}\left(\left[\begin{array}{cc}{b}_{1,1}& {b}_{1,2}\\ {b}_{2,1}& {b}_{2,2}\end{array}\right]\right)$ (10)
 > $\mathrm{Substitute}\left(\mathrm{eq},\mathrm{ee}\right)$
 ${-}{\mathrm{α}}{+}{\mathrm{β}}{+}\left(\left[\begin{array}{cc}{b}_{1,1}& {b}_{1,2}\\ {b}_{2,1}& {b}_{2,2}\end{array}\right]\right)$ (11)
 Setup some non-commutative operands
 > $\mathrm{Setup}\left(\mathrm{quantumoperators}=\left\{A,B,C,E,F\right\}\right):$
 Some typical examples not handled by subs, eval or algsubs
 > $\mathrm{eq}≔F+AB\left(x\right)={E}_{j}$
 ${\mathrm{eq}}{≔}{F}{+}{A}{}{B}{}\left({x}\right){=}{{E}}_{{j}}$ (12)
 > $\mathrm{ee}≔AB\left(x\right)C$
 ${\mathrm{ee}}{≔}{A}{}{B}{}\left({x}\right){}{C}$ (13)
 > $\mathrm{Substitute}\left(\mathrm{eq},\mathrm{ee}\right)$
 $\left({-}{F}{+}{{E}}_{{j}}\right){}{C}$ (14)
 > $\mathrm{ee}≔{ⅇ}^{\mathrm{λ}ABC}B{ⅇ}^{-\mathrm{λ}ABC}$
 ${\mathrm{ee}}{≔}{{ⅇ}}^{{\mathrm{\lambda }}{}{A}{}{B}{}{C}}{}{B}{}{{ⅇ}}^{{-}{\mathrm{\lambda }}{}{A}{}{B}{}{C}}$ (15)
 > $\mathrm{Substitute}\left(BC=F,\mathrm{ee}\right)$
 ${{ⅇ}}^{{\mathrm{\lambda }}{}{A}{}{F}}{}{B}{}{{ⅇ}}^{{-}{\mathrm{\lambda }}{}{A}{}{F}}$ (16)
 > $\mathrm{ee}≔{{∫}}_{-\mathrm{∞}}^{\mathrm{∞}}A\left(t\right){ⅇ}^{-\frac{\mathrm{λ}A\left(t\right)B\left(t\right)C\cdot 1}{\mathrm{ℏ}}}\mathrm{Ket}\left(\mathrm{ψ},t\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{ⅆ}t$
 ${\mathrm{Int}}{}\left({\mathrm{*}}{}\left({A}{}\left({t}\right){,}{\mathrm{exp}}{}\left({-}\frac{{\mathrm{λ}}{}{\mathrm{*}}{}\left({A}{}\left({t}\right){,}{B}{}\left({t}\right){,}{C}\right)}{{\mathrm{\hslash }}}\right){,}{\mathrm{Ket}}{}\left({\mathrm{ψ}}{,}{t}\right)\right){,}{t}{=}{-}{\mathrm{∞}}{..}{\mathrm{∞}}\right)$ (17)
 > $\mathrm{Substitute}\left(A\left(t\right)B\left(t\right)=\frac{F\left(t\right)\cdot 1}{\mathrm{λ}},\mathrm{ee}\right)$
 ${\mathrm{Int}}{}\left({\mathrm{*}}{}\left({A}{}\left({t}\right){,}{\mathrm{exp}}{}\left({-}\frac{{\mathrm{*}}{}\left({F}{}\left({t}\right){,}{C}\right)}{{\mathrm{\hslash }}}\right){,}{\mathrm{Ket}}{}\left({\mathrm{ψ}}{,}{t}\right)\right){,}{t}{=}{-}{\mathrm{∞}}{..}{\mathrm{∞}}\right)$ (18)
 > $\mathrm{ee}≔{\sum }_{n=0}^{\mathrm{∞}}\phantom{\rule[-0.0ex]{5.0px}{0.0ex}}\frac{{\left(\mathrm{λ}{f}_{n}\left(A\right){g}_{n}\left(B\right){h}_{n}\left(C\right)\right)}^{n}\cdot 1}{n!}$
 ${\mathrm{ee}}{≔}{\sum }_{{n}{=}{0}}^{{\mathrm{\infty }}}{}\frac{{\left({\mathrm{\lambda }}{}{{f}}_{{n}}{}\left({A}\right){}{{g}}_{{n}}{}\left({B}\right){}{{h}}_{{n}}{}\left({C}\right)\right)}^{{n}}}{{n}{!}}$ (19)
 > $\mathrm{Substitute}\left({g}_{n}\left(B\right){h}_{n}\left(C\right)=\frac{{F}_{n}\cdot 1}{\mathrm{λ}},\mathrm{ee}\right)$
 ${\sum }_{{n}{=}{0}}^{{\mathrm{\infty }}}{}\frac{{\left({{f}}_{{n}}{}\left({A}\right){}{{F}}_{{n}}\right)}^{{n}}}{{n}{!}}$ (20)
 > $\mathrm{ee}≔BA{B}^{2}\mathrm{Ket}\left(A,\mathrm{α}\right)$
 ${\mathrm{ee}}{≔}{B}{}{A}{}{{B}}^{{2}}{}{\mathrm{Ket}}{}\left({A}{,}{\mathrm{α}}\right)$ (21)
 > $\mathrm{Substitute}\left(B\mathrm{Ket}\left(A,\mathrm{α}\right)=\mathrm{Ket}\left(C,\mathrm{α}\right),\mathrm{ee}\right)$
 ${B}{}{A}{}{B}{}{\mathrm{Ket}}{}\left({C}{,}{\mathrm{α}}\right)$ (22)
 • Clear quantum operators to proceed with examples in the next sections
 > $\mathrm{Setup}\left(\mathrm{clear},\mathrm{quantumoperators}\right)$
 $\left[{\mathrm{quantumoperators}}{=}{\mathrm{none}}\right]$ (23) Substituting tensorial sub-expressions

 > $\mathrm{Define}\left(A,B,C,F,G\right):$
 $\mathrm{Defined objects with tensor properties}$ (24)
 > $\mathrm{EQ}≔{A}_{\mathrm{μ}}={G}_{\mathrm{ν},\mathrm{α}}{A}_{\mathrm{α}}{F}_{\mathrm{μ},\mathrm{ν}}$
 ${\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 }}}$ (25)
 The repeated and free indices of the lhs and rhs of this substitution equation eq
 > $\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)$ (26)
 The easy case
 > $\mathrm{Substitute}\left(\mathrm{EQ},{A}_{\mathrm{μ}}\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 }}}$ (27)
 Now the free index in the target expression is now not $\mathrm{mu}$ but $\mathrm{nu}$
 > $\mathrm{Substitute}\left(\mathrm{EQ},{A}_{\mathrm{ν}}\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 }}}$ (28)
 Distinction between covariant and contravariant indices
 > $\mathrm{Substitute}\left(\mathrm{EQ},{A}_{\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 }}}$ (29)
 The index $\mathrm{nu}$ found repeated in the rhs of the substitution equation eq also appears repeated in the following target expression
 > $\mathrm{ee}≔{A}_{\mathrm{ν}}{A}_{\mathrm{ν}}$
 ${\mathrm{ee}}{≔}{{A}}_{{\mathrm{\nu }}}{}{{A}}_{\phantom{{}}\phantom{{\mathrm{\nu }}}}^{\phantom{{}}{\mathrm{\nu }}}$ (30)
 > $\mathrm{res}≔\mathrm{Substitute}\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 }}}$ (31)
 The repeated and free indices of this result
 > $\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 }$ (32)
 Functionality is also taken as parameters (only when the lhs is a Tensor function)
 > $\mathrm{Substitute}\left({A}_{\mathrm{μ}}\left(X\right)={B}_{\mathrm{μ}}\left(X\right),{A}_{\mathrm{ν}}\left(Y\right)\right)$
 ${{B}}_{{\mathrm{\nu }}}{}\left({Y}\right)$ (33)
 Substituting in sub-expressions like algsubs
 > $\mathrm{EQ2}≔{A}_{\mathrm{μ}}\left(X\right){B}_{\mathrm{ν}}\left(Y\right)={G}_{\mathrm{μ},\mathrm{ν}}\left(X\right)$
 ${\mathrm{EQ2}}{≔}{{A}}_{{\mathrm{\mu }}}{}\left({X}\right){}{{B}}_{{\mathrm{\nu }}}{}\left({Y}\right){=}{{G}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{}\left({X}\right)$ (34)
 > $\mathrm{ee2}≔{A}_{\mathrm{α}}\left(X\right){B}_{\mathrm{β}}\left(Y\right){A}_{\mathrm{ρ}}\left(X\right){B}_{\mathrm{ρ}}\left(Y\right)$
 ${\mathrm{ee2}}{≔}{{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)$ (35)
 When substituting EQ2 into ee2, the sub-expression A . B appears twice, and not in the indets (indeterminates) of ee2:
 > $\mathrm{indets}\left(\mathrm{ee2}\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\}$ (36)
 > $\mathrm{Substitute}\left(\mathrm{EQ2},\mathrm{ee2}\right)$
 ${{G}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}}{}\left({X}\right){}{{G}}_{{\mathrm{\rho }}\phantom{{\mathrm{\rho }}}}^{\phantom{{\mathrm{\rho }}}{\mathrm{\rho }}}{}\left({X}\right)$ (37)
 Set a kind of letter to represent spinorindices and define a tensor with mixed spacetime and spinor indices
 > $\mathrm{Setup}\left(\mathrm{spinorindices}=\mathrm{lowercaselatin_is}\right)$
 $\left[{\mathrm{spinorindices}}{=}{\mathrm{lowercaselatin_is}}\right]$ (38)
 > $\mathrm{Define}\left({T}_{\mathrm{μ},i,j}\right)$
 $\mathrm{Defined objects with tensor properties}$
 $\left\{{B}{,}{C}{,}{{A}}_{{\mathrm{\mu }}}{,}{{\mathrm{\gamma }}}_{{\mathrm{\mu }}}{,}{{F}}_{{\mathrm{\mu }}\phantom{{\mathrm{\nu }}}}^{\phantom{{\mathrm{\mu }}}{\mathrm{\nu }}}{,}{{G}}_{{\mathrm{\nu }}{,}{\mathrm{\alpha }}}{,}{{\mathrm{\sigma }}}_{{\mathrm{\mu }}}{,}{{T}}_{{\mathrm{\mu }}{,}{i}{,}{j}}{,}{{\partial }}_{{\mathrm{\mu }}}{,}{{g}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{\mathrm{\epsilon }}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}\right\}$ (39)
 Substitutions in doubly indexed Dirac matrices
 > $\mathrm{Substitute}\left({{\mathrm{Dgamma}}_{\mathrm{μ}}}_{i,j}={T}_{\mathrm{μ},i,j},{{\mathrm{Dgamma}}_{\mathrm{~alpha}}}_{\mathrm{~k},m}\right)$
 ${{T}}_{\phantom{{}}\phantom{{\mathrm{\alpha }}{,}{k}}{m}}^{\phantom{{}}{\mathrm{\alpha }}{,}{k}\phantom{{m}}}$ (40)
 When the free indices of left and right hand sides of a substitution equation are different, the substitution is halted and a related error message is displayed
 > $\mathrm{Substitute}\left({{\mathrm{Dgamma}}_{\mathrm{μ}}}_{i,j}=1,{{\mathrm{Dgamma}}_{\mathrm{~alpha}}}_{\mathrm{~k},m}\right)$
 Substitutions of that kind could however be intentional; in those situations you can use the option disregardfreeindices
 > $\mathrm{Substitute}\left({{\mathrm{Dgamma}}_{\mathrm{μ}}}_{i,j}=1,{{\mathrm{Dgamma}}_{\mathrm{~alpha}}}_{\mathrm{~k},m},\mathrm{disregardfreeindices}\right)$
 ${1}$ (41) Substitutions of tensor indices

 Define a couple of arbitrary spacetime tensors for exploration purposes
 > $\mathrm{Define}\left(A,B\right)$
 $\mathrm{Defined as tensors}$
 $\left\{{B}{,}{C}{,}{{A}}_{{\mathrm{\mu }}}{,}{{\mathrm{\gamma }}}_{{\mathrm{\mu }}}{,}{{F}}_{{\mathrm{\mu }}\phantom{{\mathrm{\nu }}}}^{\phantom{{\mathrm{\mu }}}{\mathrm{\nu }}}{,}{{G}}_{{\mathrm{\nu }}{,}{\mathrm{\alpha }}}{,}{{\mathrm{\sigma }}}_{{\mathrm{\mu }}}{,}{{T}}_{{\mathrm{\mu }}{,}{i}{,}{j}}{,}{{\partial }}_{{\mathrm{\mu }}}{,}{{g}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}{,}{{\mathrm{\epsilon }}}_{{\mathrm{\alpha }}{,}{\mathrm{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}}\right\}$ (42)
 Enter, for example, this tensorial expression, with a contravariant free index $\mathrm{\rho }$
 > ${\mathrm{g_}}_{\mathrm{α},\mathrm{μ}}{A}_{\mathrm{~mu}}{\mathrm{g_}}_{\mathrm{~alpha},\mathrm{~nu}}{B}_{\mathrm{ν},\mathrm{σ},\mathrm{~rho}}$
 ${{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 }}}{}{{B}}_{{\mathrm{\nu }}{,}{\mathrm{\sigma }}\phantom{{\mathrm{\rho }}}}^{\phantom{{\mathrm{\nu }}}\phantom{{,}{\mathrm{\sigma }}}{\mathrm{\rho }}}$ (43)
 To check the repeated and free indices in an expression use Check
 > $\mathrm{Check}\left(,\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\}$ (44)
 So (3) has $\mathrm{\alpha }$ and the contravariant $\mathrm{\rho }$ as free indices. Substitute now $\mathrm{\alpha }=\mathrm{\beta }$: the standard subs command will only substitute the covariant $\mathrm{\alpha }$
 > $\mathrm{subs}\left(\mathrm{α}=\mathrm{β},\right)$
 ${{g}}_{{\mathrm{\beta }}{,}{\mathrm{\mu }}}{}{{A}}_{\phantom{{}}\phantom{{\mathrm{\mu }}}}^{\phantom{{}}{\mathrm{\mu }}}{}{{g}}_{\phantom{{}}\phantom{{\mathrm{\alpha }}{,}{\mathrm{\nu }}}}^{\phantom{{}}{\mathrm{\alpha }}{,}{\mathrm{\nu }}}{}{{B}}_{{\mathrm{\nu }}{,}{\mathrm{\sigma }}\phantom{{\mathrm{\rho }}}}^{\phantom{{\mathrm{\nu }}}\phantom{{,}{\mathrm{\sigma }}}{\mathrm{\rho }}}$ (45)
 Consequently, the resulting expression is not equivalent to (3): it now has four free indices
 > $\mathrm{Check}\left(,\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{\mu }}{,}{\mathrm{\nu }}\right\}\right]{,}\left\{{\mathrm{\beta }}{,}{\mathrm{\sigma }}{,}{\mathrm{~alpha}}{,}{\mathrm{~rho}}\right\}$ (46)
 To substitute both covariant and contravariant repeated indices obtaining an expression equivalent to original one use
 > $\mathrm{Substitute}\left(\mathrm{α}=\mathrm{β},\right)$
 ${{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 }}}{}{{B}}_{{\mathrm{\nu }}{,}{\mathrm{\sigma }}\phantom{{\mathrm{\rho }}}}^{\phantom{{\mathrm{\nu }}}\phantom{{,}{\mathrm{\sigma }}}{\mathrm{\rho }}}$ (47)
 > $\mathrm{Check}\left(,\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{\beta }}{,}{\mathrm{\mu }}{,}{\mathrm{\nu }}\right\}\right]{,}\left\{{\mathrm{\sigma }}{,}{\mathrm{~rho}}\right\}$ (48)
 Substitute now the contravariant $\mathrm{\rho }$ by $\mathrm{\tau }$; the standard subs command will fail because contravariant indices are prefixed by ~, so this returns (3) as given
 > $\mathrm{subs}\left(\mathrm{ρ}=\mathrm{β},\right)$
 ${{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 }}}{}{{B}}_{{\mathrm{\nu }}{,}{\mathrm{\sigma }}\phantom{{\mathrm{\rho }}}}^{\phantom{{\mathrm{\nu }}}\phantom{{,}{\mathrm{\sigma }}}{\mathrm{\rho }}}$ (49)
 To make it work with subs you would need to substitute ~rho = ~beta instead. Using Substitute you get the desired result regardless of this subtlety
 > $\mathrm{Substitute}\left(\mathrm{ρ}=\mathrm{β},\right)$
 ${{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 }}}{}{{B}}_{{\mathrm{\nu }}{,}{\mathrm{\sigma }}\phantom{{\mathrm{\beta }}}}^{\phantom{{\mathrm{\nu }}}\phantom{{,}{\mathrm{\sigma }}}{\mathrm{\beta }}}$ (50)
 > $\mathrm{Check}\left(,\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{~beta}}\right\}$ (51)
 To substitute several indices at once, enclosing or not the substitution equations in a set or a list
 > $\mathrm{Substitute}\left(\mathrm{ρ}=\mathrm{β},\mathrm{α}=\mathrm{gamma},\right)$
 ${{g}}_{{\mathrm{\gamma }}{,}{\mathrm{\mu }}}{}{{A}}_{\phantom{{}}\phantom{{\mathrm{\mu }}}}^{\phantom{{}}{\mathrm{\mu }}}{}{{g}}_{\phantom{{}}\phantom{{\mathrm{\gamma }}{,}{\mathrm{\nu }}}}^{\phantom{{}}{\mathrm{\gamma }}{,}{\mathrm{\nu }}}{}{{B}}_{{\mathrm{\nu }}{,}{\mathrm{\sigma }}\phantom{{\mathrm{\beta }}}}^{\phantom{{\mathrm{\nu }}}\phantom{{,}{\mathrm{\sigma }}}{\mathrm{\beta }}}$ (52)
 After substituting, tensors are re-evaluated; in this example, $\mathrm{\nu }$ becomes 1 and the normalized form of g_ is presented with it in the first place, so switching places with $\mathrm{\mu }$
 > ${\mathrm{g_}}_{\mathrm{μ},\mathrm{ν}}$
 ${{g}}_{{\mathrm{\mu }}{,}{\mathrm{\nu }}}$ (53)
 > $\mathrm{Substitute}\left(\mathrm{ν}=1,\right)$
 ${{g}}_{{1}{,}{\mathrm{\mu }}}$ (54)
 > $\mathrm{Substitute}\left(\mathrm{ν}=1,\mathrm{μ}=1,\right)$
 ${-1}$ (55)
 To avoid this evaluation of the tensors of the tensorial expression use evaluatetensor = false
 > $\mathrm{Substitute}\left(\mathrm{ν}=1,\mathrm{μ}=1,,\mathrm{evaluatetensor}=\mathrm{false}\right)$
 ${{g}}_{{1}{,}{1}}$ (56) See Also Compatibility

 • The Physics[Substitute] command was introduced in Maple 2023.