Physics[SortProducts] - sort the operands of the products of a given expression according to an indicated ordering
Calling Sequence
SortProducts(ee, ordering, {totheleft, totheright, useanticommutator, usecommutator, useinert})
Parameters
ee
-
any algebraic expressions containing products with non-commutative operands, or any valid Maple object containing such expressions
ordering
a list indicating the desired ordering for (some or all of) the operands in the products in ee
totheleft = ...
optional, can be true, false, or the string "not given" (default). It indicates where the desired ordering of the operands in products should be placed: to the left when true, to the right when false, or in place when "not given"
totheright = ...
optional, can be true, false, or the string "not given" (default). It indicates where the desired ordering of the operands should be placed: to the right when true, to the left when false, or in place when "not given"
useanticommutator = ...
optional, can be true, false, or the string "not given" (default). It forces reordering any two product operands that do not commute, by using A*B = - B*A + AntiCommutator(A, B), even if the value of AntiCommutator(A, B) is not known to the system.
usecommutator = ...
optional, can be true, false, or the string "not given" (default). It forces reordering any two product operands that do not commute, by using A*B = B*A + Commutator(A, B), even if the value of Commutator(A, B) is not known to the system.
useinert = ...
optional, can be true, false, or the string "not given" (default). It forces using the inert forms %Commutator and %AntiCommutator regardless of whether the value of the corresponding Commutator and AntiCommutator is known to the system.
Description
SortProducts receives an expression involving products and sorts the operands of these products according to the ordering indicated as the second argument, a list containing some or all of the operands of the product. The sorting of operands performed automatically takes into account any algebra rules set using Setup.
By default, the sorting between two operands A and B is performed when the value of their Commutator or AntiCommutator is known to the system (can be resolved). Note that if a Commutator can be resolved, so is the AntiCommutator and viceversa. To have the sorting performed even when the Commutator cannot be resolved, use the options usecommutator or useanticommutator, in which case the output will respectively contain an unresolved (unevaluated) Commutator or AntiCommutator. The options usecommutator and useanticommutator cannot be used simultaneously.
When the options usecommutator or useanticommutator are used, commutators or anticommutators introduced by SortProducts will be expressed using the active Commutator and AntiCommutator commands unless the operands of these commutators or anticommutators involve products, in which case they will be represented using the inert %Commutator or %AntiCommutator commands. This has the purpose of allowing for further manipulations of the output without having these commutators introduced by SortProducts automatically expanded by the corresponding active command (for details on this automatic expansion, see Commutator).
To override that default behavior, you can pass the optional argument useinert, or useinert = true. In that case, all the Commutators and AntiCommutators introduced by SortProducts will be expressed using the inert commands %Commutator or %AntiCommutator, regardless of whether these commutators can be resolved.
Equivalently, passing useinert = false all the Commutators and AntiCommutators introduced by SortProducts will be expressed in active form, using the Commutator or AntiCommutator commands, regardless of whether their operands involve products, in which case their expansion will be automatically performed as explained in the help page for Commutator.
SortProducts sorts the operands of the products 'in place', optionally positioning, when possible, the sorted operands to the left or to the right of the unsorted operands, when respectively passing the optional arguments totheleft or totheright. The option totheright cannot be used simultaneously with either of usecommutator and useanticommutator; so when using this option the sorting of say A and B is performed only if their Commutator can be resolved.
SortProducts is relevant mainly to sort the operands in noncommutative products expressed using the Physics:-`*` product operator, although it can also sort the operands in commutative products expressed with Maple's standard product operator, *. Note that the sorting of operands in commutative products within a sum may be reverted by the Maple kernel.
Examples
with⁡Physics:
Consider the product of the commutative a,b,c,d
P≔a⁢b⁢c⁢d
Reorder the operands c and b "in place".
SortProducts⁡P,c,b
a⁢c⁢b⁢d
Sort the operands b and c and put them to the left, then to the right
SortProducts⁡P,c,b,totheleft
c⁢b⁢a⁢d
SortProducts⁡P,c,b,totheright
a⁢d⁢c⁢b
Set a prefix identifying noncommutative variables and related algebra rules for some of them, such that Z1,Z2,Z3 and Z4 commute between themselves, but none of them commute with Z5.
Setup⁡noncommutativeprefix=Z,%Commutator⁡Z1,Z2=0,%Commutator⁡Z1,Z3=0,%Commutator⁡Z2,Z3=0,%Commutator⁡Z3,Z4=0,%Commutator⁡Z2,Z4=0,%Commutator⁡Z1,Z4=0
algebrarules=Z1,Z2−=0,Z1,Z3−=0,Z1,Z4−=0,Z2,Z3−=0,Z2,Z4−=0,Z3,Z4−=0,noncommutativeprefix=Z
P≔Z1⁢Z2⁢Z3⁢Z4
Sort Z2 and Z3 "in place".
SortProducts⁡P,Z3,Z2
Z1⁢Z3⁢Z2⁢Z4
SortProducts⁡P,Z3,Z2,totheright
Z1⁢Z4⁢Z3⁢Z2
The value of the commutator between Z1 and Z5 is not known to the system, so by default they are not sorted:
SortProducts⁡Z1⁢Z5,Z5,Z1
Z1⁢Z5
Force their sorting using their commutator or anticommutator
SortProducts⁡Z1⁢Z5,Z5,Z1,usecommutator
Z5⁢Z1+Z1,Z5−
expand⁡
SortProducts⁡Z1⁢Z5,Z5,Z1,useanticommutator
−Z5⁢Z1+Z1,Z5+
Enter the product of P with Z5 at the end (so, to the right of P) and sort it with Z5 to the left. This is a case where Z5 does not commute with any of the other operands. Compare the results with and without the option usecommutator,
P≔P⁢Z5
P≔Z1⁢Z2⁢Z3⁢Z4⁢Z5
SortProducts⁡P,Z5,Z1
Z1⁢Z2⁢Z3⁢Z4⁢Z5
SortProducts⁡P,Z5,Z1,usecommutator
Z5⁢Z1⁢Z2⁢Z3⁢Z4−Z5,Z1⁢Z2⁢Z3⁢Z4−
SortProducts⁡P,Z5,Z3,usecommutator
Z1⁢Z2⁢Z5⁢Z3⁢Z4−Z1⁢Z2⁢Z5,Z3⁢Z4−
Note, in the last two examples, the introduction of an inert commutator, displayed with its brackets in grey, using the %Commutator command. You can activate those inert computations using value, in which case that commutator will be expanded because one of its operands is a product:
value⁡
Z1⁢Z2⁢Z5⁢Z3⁢Z4−Z1⁢Z2⁢Z3⁢Z5,Z4−+Z5,Z3−⁢Z4
The input to SortProducts doesn't need to be a product, it could be any algebraic expression, in which case all its products will be sorted. For example,
ee≔Z5+Z1⁢Z52
SortProducts⁡ee,Z5,Z1,usecommutator
Z5+Z5⁢Z1+Z1,Z5−2
Set an algebra rule for the commutator of Z1 and Z5, for example:
Setup⁡%Commutator⁡Z1,Z5=Z6
algebrarules=Z1,Z2−=0,Z1,Z3−=0,Z1,Z4−=0,Z1,Z5−=Z6,Z2,Z3−=0,Z2,Z4−=0,Z3,Z4−=0
P≔Z1⁢Z5
Z5⁢Z1+Z6
The result above got computed using the algebra rule set. In some cases, however, instead of the value of the commutator (algebra rule), it is preferred the actual commutator, unevaluated. For these purposes pass the useinert option
SortProducts⁡P,Z5,Z1,useinert
SortProducts⁡P,Z5,Z1,useanticommutator,useinert
Equivalently, when the value of the commutator is not known to the system and there are products in the operands of the commutators introduced, instead of the default inert representations one may prefer an active representation using the Commutator or AntiCommutator commands. For that purpose pass the option useinert = false
P≔Z2⁢Z3⁢Z5
SortProducts⁡P,Z5,Z2,usecommutator
Z5⁢Z2⁢Z3−Z5,Z2⁢Z3−
SortProducts⁡P,Z5,Z2,usecommutator,useinert=false
Z5⁢Z2⁢Z3−Z2⁢Z5,Z3−−Z5,Z2−⁢Z3
See Also
AntiCommutator, Commutator, Physics, Physics conventions, Physics examples, Physics Updates, Tensors - a complete guide, Mini-Course Computer Algebra for Physicists, Physics[*], Setup, type,commutative
Compatibility
The Physics[SortProducts] command was introduced in Maple 2019.
For more information on Maple 2019 changes, see Updates in Maple 2019.
Download Help Document