The following code, returns 0, for the collection of two operators a and ad that do not commute.
from sympy.physics.quantum import Commutator, Dagger
from sympy import collect
from sympy.physics.quantum.boson import BosonOp
a = BosonOp("a")
ad = Dagger(a)
print(collect(a*ad-ad*a,a))
One can check that these operators are non-commutative by the following lines
print(a.is_commutative)
print(ad.is_commutative)
returning False.
Can also reproduce with a, b = symbols('a b', commutative=False).
>>> a, b = symbols('a b', commutative=False)
>>> collect(a*b + b*a, a)
2*a*b
It's not clear to me what a non-commutative analogue of collect should do. The free (non-commutative, unital) ring on one generator isn't nearly as well-behaved as a polynomial ring. Would it be best to simply reject attempted collection of powers of non-commutative variables, and make note of this in the documentation?
Giving an error would be better than giving a wrong result.
Most helpful comment
Can also reproduce with
a, b = symbols('a b', commutative=False).