On SymPy 0.7.5 (Python 2.7.8-64-bit). I'm unable to get the constant term from an expression when the constant term is zero or absent (an absent constant is the same of a zero constant, right?).
I can get the constant term from an expression with expr.coeff(x, 0)
. E.g.:
isympy ## Load sympy etc...
(x + 3).coeff(x, 0) #-> 3 ok
(x).coeff(x, 0) #-> 0 ok
(4*x**2 + 3*x).coeff(x, 0) #-> 0 ok
Now, how can I get 0 in these cases?
(4*x).coeff(x, 0) #-> 4
(4*x**2).coeff(x, 0) #-> 4 why not 0?!
I'm sure this has been asked & documented before but I can't find the answer at least without some awkward workaround. Thanks Dario
Edit Full output from interactive session:
python
Python 2.7.8 (default, Sep 14 2014, 18:20:38)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import sympy
>>>
>>> x= sympy.symbols('x')
>>> (4*x).coeff(x, 0)
4
>>> sympy.__version__
'0.7.5'
Solution: Upgrade to sympy 0.7.6. Unless I was doing something silly it appears this was a bug 0.7.5.
python
Python 2.7.8 (default, Sep 14 2014, 18:20:38)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sympy
>>> x= sympy.symbols('x')
>>> (4*x).coeff(x, 0)
0
>>> sympy.__version__
'0.7.6'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With