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.

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

1 Answer 1


You can do this with NCCoefficientList as in:

H = C1 b ** a + C2 a ** aj[a] + C3 d ** aj[d]
NCCoefficientList[H, {a, aj[a], b, d, aj[d]}]

which returns

{C1, C2, C3}

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


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.