# Collecting coefficients of non-commutative products from an expression

I am trying to manipulate a Hamiltonian with non-commutative operators, $$a_j,a_j^\dagger$$. After some algebra using NCAlgebra package in Mathematica, I have an expression like, $$H = C_1 (b**a) + C_2 (a**a^\dagger) + C_3 (d^\dagger d) + \cdots$$ How do I extract/collect coefficients like $$C_1,C_2$$? I have tried NCCollect[H, b**a], but it does not give me the desired answer $$C_1$$? I am new to this and appreciate any help. Thank you.

• Welcome to the Mathematica Stack Exchange. This question lacks a minimal working example. Please paste (enough) Mma code that replicates your problem.
– Syed
Oct 18, 2021 at 20:33
• Maybe NCCoefficientList[expr, {a, b}]? Oct 19, 2021 at 17:16
• Thank you @march and @Syed. It turns out, there was a simple solution. The commandCoefficient[expr, SuperStar[b1] ** b2] did the job. Oct 19, 2021 at 19:07

You can do this with NCCoefficientList as in:
H = C1 b ** a + C2 a ** aj[a] + C3 d ** aj[d]

Note that you have to add also aj[a] and aj[d] to the list of variables.