user600942 user600942 - 1 year ago 61
Python Question

Does sympy v1.0 factor give the wrong answer with (2*4) + (2*4)/(2 + x)?

Using python 3.5.1 64 bit on windows 8.1, I have installed sympy, 1.0.

Running interactively

from sympy import *
p = symbols('p')
factor('8 + 8/(2+p)')

result is
8*(p + 3)/(p + 2)

If I go to running sympy 0.7.6 and python 2.7.5 and enter the same equation and hit the evaluate button, I get the right answer.

8 + 8/(2+p)

There is no reduction. Why am I getting the wrong answer with Python 3.5.1 and sympy 1.0?


You are not getting the wrong answer. All that sympy.factor ensures is that a polynomial is factored into irreducible fractions over the rationals.

Notice that

enter image description here

So the form given by factor in version 1.0 is correct, and represents an irreducible fraction over the rationals.

Update : I ran your code on SymPy Live and you get the exact same fraction when using factor, without the 8 factored out. They are the same. Note as Steven Rumbalski said, that evaluating and factoring are two different things.