# normal ordering of Bose operators

Suppose I have lot of product terms of Bose operators, e.g:

a a SuperDagger[a] SuperDagger[a] a a SuperDagger[a] SuperDagger[a] SuperDagger[a] SuperDagger[a]  a a a a


and I want to turn them into normal ordering using Boson commutation relations

Writing each term as:

NCM[a, a, SuperDagger[a], SuperDagger[a], a, a, SuperDagger[a], SuperDagger[a], SuperDagger[a], SuperDagger[a],  a, a, a, a]


can be time consuming if you have many terms. Is there a way to work around this point? Can I somehow achieve the normal ordering by something like

f[a a SuperDagger[a] SuperDagger[a] a a SuperDagger[a] SuperDagger[a] SuperDagger[a] SuperDagger[a]  a a a a]


where f does the same thing as NCM?

You can do:

SetAttributes[f, HoldFirst]
f[_[args___]] := NonCommutativeMultiply[args]


Try it out:

a a SuperDagger[a] SuperDagger[a] a a SuperDagger[a] SuperDagger[a] \
SuperDagger[a] SuperDagger[a] a a a a // f


Note that you cannot let Times evaluate at any time because that will re-order the arguments. So you cannot do something like:

expr = a SuperDagger[a] SuperDagger[a] a;
f[expr]
f[Evaluate[expr]]


What you can do:

expr = Inactivate[a SuperDagger[a] SuperDagger[a] a, Times];
f[Evaluate[expr]]


# Edit

Here's another idea:

ClearAll[f]
SetAttributes[f, HoldFirst]
f[expr_] := Block[{Times = NonCommutativeMultiply}, expr]


In this case, the following will also work:

expr := a SuperDagger[a] SuperDagger[a] a;
f[expr]

• Thanks for the answer.I have a question: a a SuperDagger[a] SuperDagger[a] a a SuperDagger[a] SuperDagger[a] SuperDagger[a] SuperDagger[a] a a a a // f  works fine, but I don't have to use Inactivate. Only when I am assigning it to expr I have to use Inactivate? Seems so – geom Dec 7 '20 at 11:45
• @geom Yes, that is correct. The HoldFirst attribute of f prevents Times from evaluating when in the first example. In the second example, Times would evaluate while evaluating expr, so the HoldFirst attribute cannot help you there. I do have another idea, though. Let me update the answer. – Sjoerd Smit Dec 7 '20 at 11:55