# sort_product

Sort factors in a product

Sort factors in a product, taking into account
any `SortOrder`

properties. Also takes into account
commutativity properties, such as `SelfCommuting`

. If no sort
order is given, it first does a lexographical sort based on the name
of the factor, and if two names are identical, does a sort based on
the number of children and (if this number is equal) a lexographical
comparison of the names of the children. Symbols starting with a backslash
(greek letters etc.) get sorted to the right of roman letters.
The simplest sort is illustrated below,ex := C B A D;
sort_product(_);

\(\displaystyle{}C B A D\)

\(\displaystyle{}A B C D\)

We can declare the objects to be anti-commuting, which then leads to

{A, B, C, D}::AntiCommuting.
ex := C B A D;
sort_product(_);

\(\displaystyle{}C B A D\)

\(\displaystyle{}-A B C D\)

For indexed objects, the anti-commutativity of components is indicated
using the

`SelfAntiCommuting`

property,\psi_{m}::SelfAntiCommuting.
ex := \psi_{n} \psi_{m} \psi_{p};
sort_product(_);

\(\displaystyle{}\psi_{n} \psi_{m} \psi_{p}\)

\(\displaystyle{}-\psi_{m} \psi_{n} \psi_{p}\)

Finally, the lexographical sort order can be overridden by using
the

`SortOrder`

property,{D, C, B, A}::SortOrder.
{A, B, C, D}::AntiCommuting.
ex := C B A D;
sort_product(_);

\(\displaystyle{}C B A D\)

\(\displaystyle{}-D C B A\)