I compute a product of Bose operators and turn it into normal ordering using Boson commutation relations, e.g:

c1 * SuperDagger[a] ** SuperDagger[a] ** a ** a + 
c2 * SuperDagger[a] ** SuperDagger[a] ** SuperDagger[a] ** a ** a ** a

and generally more terms. In the above c1, c2 are scalars while a, SuperDagger[a] are the Bose operators.

I can convert it to a more readable form by adding

/.NonCommutativeMultiply[a___] :> Infix[NonCommutativeMultiply[a],"\[InvisibleTimes]"]

at the end of the evaluation command, which makes the ** symbol invisible (output is not displayed correctly here, sorry).

I would like to know whether I can make such expressions more readable by having in the output the various terms in the form SuperDagger[a]^3 a^3 and NOT like SuperDagger[a] SuperDagger[a] SuperDagger[a] a a a

Also how can I isolate specific powers e.g SuperDagger[a]^2 a^2 in a long expression involving many different powers of SuperDagger[a]^n a^n and get their display only, e.g:

(3 * c1 + 5 * c0 + 7 * c6) SuperDagger[a] ** SuperDagger[a] ** a ** a

Collect doesn't do the trick.

  • $\begingroup$ True, I will change it to the original output. $\endgroup$
    – geom
    Commented Dec 5, 2020 at 21:18

1 Answer 1


Would this work?

expr = c1*SuperDagger[a] ** SuperDagger[a] ** a ** a + 
        c2*SuperDagger[a] ** SuperDagger[a] ** SuperDagger[a] ** a ** a ** a

collectPowers[expr_] := 
    {NonCommutativeMultiply[x_, x_] :> x^2,
     NonCommutativeMultiply[Power[x_, i_], x_] :> Power[x, i + 1]}


(* Out: c1 (SuperDagger[a])^2 ** a^2 + c2 (SuperDagger[a])^3 ** a^3 *)
  • $\begingroup$ It is useful, but in longer expressions where you have more coefficients it does not produce e.g (c1 + 2 c2 + 5 c3^3) (SuperDagger[a])^2 ** a^2. It produces each term separately and you have to track all terms one by one. $\endgroup$
    – geom
    Commented Dec 6, 2020 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.