2017-08-10 26 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