2

Sympy (ver. 1.1.1) documentation of collect_const says that using the Numbers=False option, "no Float or Rational will be collected". This makes you think that rationals are normally collected by collect_const, but they don't seem to be:

>>> from sympy import *
>>> x, y, z = symbols('x y z')
>>> collect_const(2*x - 2*y - 2*z, 2)
2*(x - y - z)
>>> collect_const(x/2 - y/2 - z/2, 1/2)
x/2 - y/2 - z/2

Am I missing something?

Thank in advance.

mmj
  • 5,514
  • 2
  • 44
  • 51

1 Answers1

1

I think is a little bug. The argument Numbers doesn't seem to work well with the arithmetic operator "/". From your example:

>>> from sympy import *
>>> x, y, z = symbols('x y z')
>>> collect_const(x/2 - y/2 - z/2, 1/2, Numbers=False)
x/2 - y/2 - z/2
>>> collect_const(x/2 - y/2 - z/2, 1/2, Numbers=True)
x/2 - y/2 - z/2

It doesn't seem to affect the expression. However, if we change "/2" for ".5*" the result is quite different:

>>> collect_const(.5*x - .5*y - .5*z, 1/2, Numbers=False)
.5*x - .5*y - .5*z
>>> collect_const(.5*x - .5*y - .5*z, 1/2, Numbers=True)
.5*(x - y - z)

Anyway, I've created an Issue on Github.

mforpe
  • 1,549
  • 1
  • 12
  • 22