2017-08-10 63 views
2

sympy(版本1.1.1)文件collect_const说,使用Numbers=False选项,“不收集浮动或理性”。这使得你认为有理数通常由collect_const收集,但他们似乎并不为:sympy收集合理collect_const

>>> 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 

我这么想吗?

预先感谢。

回答

1

我觉得有点错误。参数Numbers似乎不适用于算术运算符“/”。从你的例子:

>>> 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 

它似乎并不影响表达。然而,如果我们改变“/ 2”,“0.5×”的结果是完全不同的:

>>> 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) 

无论如何,我已经在Github创建Issue