answered 2025-01-07 13:41:41 +0200
like this
A.<a,b> = FreeAlgebra(QQ, 2) f = a + a * b - b * a aa,bb=A.monoid().gens() f.coefficient(aa*bb)