Ich habe vor kurzem beginnen, Sympy verwenden, und von Anfang an verhält es sich seltsam aus meiner Sicht.Sympy vereinfachen Logik
Betrachten Sie zwei Polynome, fx und tn_shifted von einer Variablen. Ich subtrahiere eins voneinander, um das Polynom p2 zu erhalten. Dann führe ich eine Vereinfachung durch und bekomme einen völlig anderen Ausdruck, wie unten gezeigt.
import sympy as spy
from sympy import Symbol
x = Symbol('x')
a, b = 1, 3
n = 3
tn = lambda x: x**3 - 3*x
fx = spy.simplify(x**3 - 2*x**2 + x + 1)
tn_shifted = (b - a)**n/(2**(2*n - 1)) * tn((2*x - (b + a))/(b - a))
tn_shifted = spy.simplify(tn_shifted)
p2_ethalon = fx - tn_shifted
print(fx - p2_ethalon - tn_shifted)
p2_simplified = spy.simplify(fx - tn_shifted)
print(fx - p2_simplified - tn_shifted)
p2_expanded = spy.expand(fx - tn_shifted)
print(fx - p2_expanded - tn_shifted)
print(p2_ethalon - p2_simplified)
Hier ein Ausgang:
0
0.25*x**3 - 1.5*x**2 + 3.0*x - 0.25*(x - 2)**3 - 2.0
0.25*x**3 - 1.5*x**2 + 3.0*x - 0.25*(x - 2)**3 - 2.0
0.25*x**3 - 1.5*x**2 + 3.0*x - 0.25*(x - 2)**3 - 2.0
Sympy kommt mit anaconda für Python 3.5 unter OS X Yosemite Hier pip show sympy
Info
Name: sympy
Version: 0.7.6.1
Summary: Computer algebra system (CAS) in Python
Home-page: http://sympy.org
Author: SymPy development team
Author-email: [email protected]
License: BSD
Location: /Users/cnst/anaconda/lib/python3.5/site-packages
So gibt es ein Bug oder Sympy hat etwas nichttriviale Logik, wenn es den Ausdruck vereinfacht?