2

I have the following snippet of code

import sympy

a = sympy.symbols('a')
b = sympy.symbols('b')
c = sympy.symbols('c')

print((a*b).coeff(c,0))
print((a*b).as_independent(c)[0])

I don't understand why the two print statements print different output. According to the documentation of coeff:

You can select terms independent of x by making n=0; in this case
expr.as_independent(x)[0] is returned (and 0 will be returned instead
of None):

>>> (3 + 2*x + 4*x**2).coeff(x, 0)
3

Is this a bug in sympy, or do I miss something?

G. W.
  • 21
  • 2

1 Answers1

2

It's a bug. I have a pull request fixing it here.

asmeurer
  • 86,894
  • 26
  • 169
  • 240