answered 0 years ago
like this
A.<a,b> = FreeAlgebra(QQ, 2) f = a + a * b - b * a aa,bb=A.monoid().gens() f.coefficient(aa*bb)