I define:
Unprotect[NonCommutativeMultiply];
NonCommutativeMultiply[left___, HoldPattern[Times[u[x_], p : (a[k_] | SuperDagger[a][k_])]],
right___] := u[x] NonCommutativeMultiply[left, p, right]
Protect[NonCommutativeMultiply];
since I want the function u[x_]
to commute with a[k_], SuperDagger[a][k_]
Now if i try
In:= a[k] ** u[k]*a[q]
Out= a[q] a[k] ** u[k] (* which is not the desired output*)
if i try
In:= a[k] ** (u[k] a[q])
Out= a[k] ** a[q] u[k]
which is better but still it's not u[k] a[k] ** a[q]
I can't figure out why my definition isn't working. What am I missing?
a[k] ** (u[k] a[q])
the output placesu[k]
aftera[k] ** a[q]
not before. How should I change it to have the desired output? $\endgroup$ – geom Dec 20 '20 at 12:32orderless
toNonCommutativeMultiply
nothing changes.The order is decided bySort
which orders symbols by their names, and in the event of a tie, by their contexts. Please post your comments as an answer. They are helpful. $\endgroup$ – geom Dec 20 '20 at 13:08