Question: The problem with SortProducts from Physics package

Hi.
I am trying to use a new Physics:-Library:-SortProducts command. However it doesn't work in my case.

restart; 
with(Physics);
with(Library);
Setup(mathematicalnotation = true);
Physics:-Setup(anticommutativeprefix = psi);

for i to 4 do
ap[i] := Creation(psi, i, notation = explicit);
am[i] := Annihilation(psi, i, notation = explicit)
end do;

z := A*ap[2].am[2].ap[1].am[1]+B*ap[1].am[1].ap[2].am[2]+C*ap[3].am[3].ap[4].am[4]:
z := SortProducts(z, [ap, am], useanticommutator);

Result:



Besides that I need to sort over the index of creation/annihilation operators. So that to derive something like that:

z=...+x1*ap[i1]. ... .ap[in].am[j1]. ... .am[jn]+...

where i1<i2<...<in, j1<j2<...<jn. Reverse order will be Ok too.

Also I need to collect terms with the same operator part: that is

x1*ap[3].am[4]+x2*ap[3].am[4] -> (x1+x2)*ap[3].am[4]

Is there such possibility?

Thank you.

Please Wait...