Mathematica Asked on January 9, 2021
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]]
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]
Correct answer by Sjoerd Smit on January 9, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP