Revision history [back]

coefficient() with composite variable

Say I have something like this:

var('a','b','c')
test=b*a + c*a + 3*a + b + c


I can find that the coefficient of 'a' is (b+c+3) using:

test.coefficient(a,1)


However, I am interested in find the coefficient of $ab$ (which in this case would just be $1$). I tried

test.coefficient(a*b,1)


but it just returns zero. Is something like this possible?