I am trying to use a new Physics:-Library:-SortProducts command. However it doesn't work in my case.
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)
z := A*ap.am.ap.am+B*ap.am.ap.am+C*ap.am.ap.am:
z := SortProducts(z, [ap, am], useanticommutator);
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.am+x2*ap.am -> (x1+x2)*ap.am
Is there such possibility?