
# Sorting can be done with or without taking into account the 
# numbers used to label dummy indices. 

A_{?}::SelfCommuting.

obj:=  A_{d3 d2 d1} A_{d7 d8 a1};
# @prodsort!(%){IgnoreNumbers};
# tst1:= A_{d7 d8 a1} A_{d3 d2 d1} - @(obj):
# @collect_terms!(%);
# @assert(tst1);

@prodsort!(obj);
tst2:= A_{d3 d2 d1} A_{d7 d8 a1} - @(obj):
@collect_terms!(%);
@assert(tst2);

# Test 2: Inheritance
@reset.
\Gamma_{#}::GammaMatrix. 
\psi::Spinor.
D_{#}::Derivative.
\bar{#}::DiracBar.
obj2:= \bar{\psi} * \Gamma_{m n p} * D_{p}{\psi};
@prodsort!(%);
tst2:= \bar{\psi} * \Gamma_{m n p} * D_{p}{\psi} - @(obj2);
@collect_terms!(%);
@assert(tst2);

# Test 3: Powers.
@reset.
{ y, y**n?, x, x**n? }::SortOrder.
obj3:= x**4 y**4;
@prodsort!(%);
tst3:= y**4 x**4 - @(obj3);
@collect_terms!(%);
@assert(tst3);

@reset.
F_{a b}::AntiSymmetric.
F1_{a b}::AntiSymmetric.
obj4:= F1_{a b}F_{c d}:
@prodsort!(%);

# Test 4: sorting by index position
#
@reset.
{a,b}::Indices(position=fixed).
{ n^a, n_a }::SortOrder.
obj4:= n_a n_b n^a;
@prodsort!(%);
tst4:= n^a n_a n_b - @(obj4);
@collect_terms!(%);
@assert(tst4);

# Note: sorting by index name is not supported; the two
# patterns in the SortOrder declaration below are identical,
# so that when n_a is searched in the list, it is matched
# against n_b and given position=0, not position=1.
#
@reset.
{ n_b, n_a }::SortOrder.
n_a n_b;
@prodsort!(%);

