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, <other options>)
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
<other options>
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, EQ≔μ=ν and the target ee is a tensorial expression, the substitution is automatically forwarded to SubstituteTensorIndices and will substitute both covariant (μ) and contravariant (~μ) indices, and perform the substitution only in tensor indices, not otherwise.
If 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 EQ involves Matrix or Vector constructions, the task is automatically forwarded to Library:-SubstituteMatrix.
If 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 A⁢B in A⁢B⁢C), 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 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
with⁡Physics:
Setup⁡mathematicalnotation=true
mathematicalnotation=true
Substitutions of matrices, sub-products and sub-sums, possibly involving noncommutative objects
eq≔F+A⁢B⁡x=Ej
ee≔A⁢B⁡x⁢C
Substitute⁡eq,ee
−C⁢F−Ej
Substitution of matrices and vectors taking mathematical equality into account
eq≔Matrix⁡2,symbol=a=β+Matrix⁡2,symbol=b
eq≔=β+
ee≔Matrix⁡2,symbol=a
ee≔
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:
lhs⁡eq=ee
=
evalb⁡
false
These cases are handled by Substitute as one would expect, by recognizing the left-hand side of eq as mathematically equal to ee
β+
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
eq≔α+Matrix⁡2,2,a1,1,a1,2,a2,1,a2,2=β+Matrix⁡2,2,b1,1,b1,2,b2,1,b2,2
eq≔α+=β+
−α+β+
Setup some non-commutative operands
Setup⁡quantumoperators=A,B,C,E,F:
Some typical examples not handled by subs, eval or algsubs
Ej−F⁢C
ee≔exp⁡λ⁢A⁢B⁢C⁢B⁢exp⁡−λ⁢A⁢B⁢C
ee≔ⅇλ⁢A⁢B⁢C⁢B⁢ⅇ−λ⁢A⁢B⁢C
Substitute⁡B⁢C=F,ee
ⅇλ⁢A⁢F⁢B⁢ⅇ−λ⁢A⁢F
ee≔Int⁡A⁡t⁢exp⁡−λ⁢A⁡t⁢B⁡t⁢C⋅1ℏ⁢Ket⁡ψ,t,t=−∞..∞
ee≔∫−∞∞A⁡t⁢ⅇ−λ⁢A⁡t⁢B⁡t⁢Cℏ⁢ψtⅆt
Substitute⁡A⁡t⁢B⁡t=F⁡t⋅1λ,ee
∫−∞∞A⁡t⁢ⅇ−F⁡t⁢Cℏ⁢ψtⅆt
ee≔Sum⁡λ⁢fn⁡A⁢gn⁡B⁢hn⁡Cn⋅1n!,n=0..∞
ee≔∑n=0∞⁡λ⁢fn⁡A⁢gn⁡B⁢hn⁡Cnn!
Substitute⁡gn⁡B⁢hn⁡C=Fn⋅1λ,ee
∑n=0∞⁡fn⁡A⁢Fnnn!
ee≔B⁢A⁢B2⁢Ket⁡A,α
ee≔B⁢A⁢B2⁢Aα
Substitute⁡B⁢Ket⁡A,α=Ket⁡C,α,ee
B⁢A⁢B⁢Cα
Clear quantum operators to proceed with examples in the next sections
Setup⁡clear,quantumoperators
quantumoperators=none
Substituting tensorial sub-expressions
Define⁡A,B,C,F,G:
Defined objects with tensor properties
EQ≔Aμ=Gν,α⁢Aα⁢Fμ,ν
EQ≔Aμ=Gν,α⁢A⁢α⁢α⁢Fμνμν
The repeated and free indices of the lhs and rhs of this substitution equation eq
Check⁡EQ,all
The repeated indices per term are: ...,...,..., the free indices are: ...
∅,μ=α,ν,μ
The easy case
Substitute⁡EQ,Aμ
Gν,α⁢A⁢α⁢α⁢Fμνμν
Now the free index in the target expression is now not mu but nu
Substitute⁡EQ,Aν
Gβ,α⁢A⁢α⁢α⁢Fνβνβ
Distinction between covariant and contravariant indices
Substitute⁡EQ,A~nu
Gβ,α⁢A⁢α⁢α⁢F⁢ν,β⁢ν,β
The index nu found repeated in the rhs of the substitution equation eq also appears repeated in the following target expression
ee≔Aν⁢Aν
ee≔Aν⁢A⁢ν⁢ν
res≔Substitute⁡EQ,ee
res≔Gλ,κ⁢A⁢κ⁢κ⁢Fνλνλ⁢Gβ,α⁢A⁢α⁢α⁢F⁢ν,β⁢ν,β
The repeated and free indices of this result
Check⁡res,all
α,β,κ,λ,ν,∅
Functionality is also taken as parameters (only when the lhs is a Tensor function)
Substitute⁡Aμ⁡X=Bμ⁡X,Aν⁡Y
Bν⁡Y
Substituting in sub-expressions like algsubs
EQ2≔Aμ⁡X⁢Bν⁡Y=Gμ,ν⁡X
ee2≔Aα⁡X⁢Bβ⁡Y⁢Aρ⁡X⁢Bρ⁡Y
ee2≔Aα⁡X⁢Bβ⁡Y⁢Aρ⁡X⁢B⁢ρ⁢ρ⁡Y
When substituting EQ2 into ee2, the sub-expression A . B appears twice, and not in the indets (indeterminates) of ee2:
indets⁡ee2
X,Y,Aα⁡X,Aρ⁡X,Bβ⁡Y,B⁢ρ⁢ρ⁡Y
Substitute⁡EQ2,ee2
Gα,β⁡X⁢Gρρρρ⁡X
Set a kind of letter to represent spinorindices and define a tensor with mixed spacetime and spinor indices
Setup⁡spinorindices=lowercaselatin_is
spinorindices=lowercaselatin_is
Define⁡Tμ,i,j
B,C,Aμ,γμ,Fμνμν,Gν,α,σμ,Tμ,i,j,∂μ,gμ,ν,εα,β,μ,ν
Substitutions in doubly indexed Dirac matrices
Substitute⁡Dgammaμi,j=Tμ,i,j,Dgamma~alpha~k,m
T⁢α,km⁢α,km
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
Substitute⁡Dgammaμi,j=1,Dgamma~alpha~k,m
Free indices on both sides of the equation are different: found i,j,μ on the left-hand side and ∅ on the right-hand side
Error, (in Physics:-SubstituteTensor) free indices on both sides of the equation are different
Substitutions of that kind could however be intentional; in those situations you can use the option disregardfreeindices
Substitute⁡Dgammaμi,j=1,Dgamma~alpha~k,m,disregardfreeindices
1
Substitutions of tensor indices
Define a couple of arbitrary spacetime tensors for exploration purposes
Define⁡A,B
Defined as tensors
Enter, for example, this tensorial expression, with a contravariant free index ρ
g_α,μ⁢A~mu⁢g_~alpha,~nu⁢Bν,σ,~rho
gα,μ⁢A⁢μ⁢μ⁢g⁢α,ν⁢α,ν⁢Bν,σρν,σρ
To check the repeated and free indices in an expression use Check
Check⁡,all
α,μ,ν,σ,~ρ
So (3) has α and the contravariant ρ as free indices. Substitute now α=β: the standard subs command will only substitute the covariant α
subs⁡α=β,
gβ,μ⁢A⁢μ⁢μ⁢g⁢α,ν⁢α,ν⁢Bν,σρν,σρ
Consequently, the resulting expression is not equivalent to (3): it now has four free indices
μ,ν,β,σ,~α,~ρ
To substitute both covariant and contravariant repeated indices obtaining an expression equivalent to original one use
Substitute⁡α=β,
gβ,μ⁢A⁢μ⁢μ⁢g⁢β,ν⁢β,ν⁢Bν,σρν,σρ
β,μ,ν,σ,~ρ
Substitute now the contravariant ρ by τ; the standard subs command will fail because contravariant indices are prefixed by ~, so this returns (3) as given
subs⁡ρ=β,
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
Substitute⁡ρ=β,
gα,μ⁢A⁢μ⁢μ⁢g⁢α,ν⁢α,ν⁢Bν,σβν,σβ
α,μ,ν,σ,~β
To substitute several indices at once, enclosing or not the substitution equations in a set or a list
Substitute⁡ρ=β,α=γ,
gγ,μ⁢A⁢μ⁢μ⁢g⁢γ,ν⁢γ,ν⁢Bν,σβν,σβ
After substituting, tensors are re-evaluated; in this example, ν becomes 1 and the normalized form of g_ is presented with it in the first place, so switching places with μ
g_μ,ν
gμ,ν
Substitute⁡ν=1,
gμ,1
Substitute⁡ν=1,μ=1,
g1,1
Note the result above is not fully evaluated; in that sense, Substitute, the same as SubstituteTensorIndices, follows the design of subs. To have results fully evaluated, pass the keyword evaluateexpression
Substitute⁡ν=1,μ=1,,evaluateexpression
−1
See Also
algsubs, Check, eval, eval, g_, indets, Physics, Physics conventions, Physics examples, Physics Updates, Tensors - a complete guide, Mini-Course Computer Algebra for Physicists, Physics:-Library, subs, SubstituteTensor, SubstituteTensorIndices
Compatibility
The Physics[Substitute] command was introduced in Maple 2023.
For more information on Maple 2023 changes, see Updates in Maple 2023.
Download Help Document