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

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Physics : SortProducts

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

withPhysics:

Consider the product of the commutative a,b,c,d

Pabcd

Pabcd

(1)

Reorder the operands c and b "in place".

SortProductsP,c,b

acbd

(2)

Sort the operands b and c and put them to the left, then to the right

SortProductsP,c,b,totheleft

cbad

(3)

SortProductsP,c,b,totheright

adcb

(4)

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.

Setupnoncommutativeprefix=Z,%CommutatorZ1,Z2=0,%CommutatorZ1,Z3=0,%CommutatorZ2,Z3=0,%CommutatorZ3,Z4=0,%CommutatorZ2,Z4=0,%CommutatorZ1,Z4=0

algebrarules=Z1,Z2=0,Z1,Z3=0,Z1,Z4=0,Z2,Z3=0,Z2,Z4=0,Z3,Z4=0,noncommutativeprefix=Z

(5)

PZ1Z2Z3Z4

PZ1Z2Z3Z4

(6)

Sort Z2 and Z3 "in place".

SortProductsP,Z3,Z2

Z1Z3Z2Z4

(7)

SortProductsP,Z3,Z2,totheright

Z1Z4Z3Z2

(8)

The value of the commutator between Z1 and Z5 is not known to the system, so by default they are not sorted:

SortProductsZ1Z5,Z5,Z1

Z1Z5

(9)

Force their sorting using their commutator or anticommutator

SortProductsZ1Z5,Z5,Z1,usecommutator

Z5Z1+Z1,Z5

(10)

expand

Z1Z5

(11)

SortProductsZ1Z5,Z5,Z1,useanticommutator

Z5Z1+Z1,Z5+

(12)

expand

Z1Z5

(13)

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,

PPZ5

PZ1Z2Z3Z4Z5

(14)

SortProductsP,Z5,Z1

Z1Z2Z3Z4Z5

(15)

SortProductsP,Z5,Z1,usecommutator

Z5Z1Z2Z3Z4Z5,Z1Z2Z3Z4

(16)

SortProductsP,Z5,Z3,usecommutator

Z1Z2Z5Z3Z4Z1Z2Z5,Z3Z4

(17)

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

Z1Z2Z5Z3Z4Z1Z2Z3Z5,Z4+Z5,Z3Z4

(18)

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,

eeZ5+Z1Z52

eeZ5+Z1Z52

(19)

SortProductsee,Z5,Z1,usecommutator

Z5+Z5Z1+Z1,Z52

(20)

Set an algebra rule for the commutator of Z1 and Z5, for example:

Setup%CommutatorZ1,Z5=Z6

algebrarules=Z1,Z2=0,Z1,Z3=0,Z1,Z4=0,Z1,Z5=Z6,Z2,Z3=0,Z2,Z4=0,Z3,Z4=0

(21)

PZ1Z5

PZ1Z5

(22)

SortProductsP,Z5,Z1

Z5Z1+Z6

(23)

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

SortProductsP,Z5,Z1,useinert

Z5Z1+Z1,Z5

(24)

SortProductsP,Z5,Z1,useanticommutator,useinert

Z5Z1+Z1,Z5+

(25)

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

PZ2Z3Z5

PZ2Z3Z5

(26)

SortProductsP,Z5,Z2,usecommutator

Z5Z2Z3Z5,Z2Z3

(27)

SortProductsP,Z5,Z2,usecommutator,useinert=false

Z5Z2Z3Z2Z5,Z3Z5,Z2Z3

(28)

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