Feat(API): In simplify first typing then optimize

This commit is contained in:
Bertrand Benjamin 2018-11-21 09:43:35 +01:00
parent 505d2f1c09
commit 5ab5314899
2 changed files with 17 additions and 11 deletions

View File

@ -81,15 +81,20 @@ x^7
(2 + 3) * x + 2
5x + 2
>>> e = Expression.from_str("2x^2+2x+3x")
>>> e = Expression.from_str("1+2x^2+3x+4+5x")
>>> e_simplified = e.simplify()
>>> print(e_simplified)
2x^2 + 5x
2x^2 + 5 + 8x
>>> for s in e_simplified.explain():
... print(s)
2x^2 + 2x + 3x
2x^2 + (2 + 3) * x
2x^2 + 5x
1 + 2x^2 + 3x + 4 + 5x
2x^2 + 3x + 1 + 4 + 5x
3x + 5 + 2x^2 + 5x
2x^2 + 3x + 5x + 5
2x^2 + (3 + 5) * x + 5
2x^2 + 5 + 8x
"""
from .expression import Expression

View File

@ -202,13 +202,14 @@ class Expression(object):
>>> f._ancestor
<Exp: 2 + 12>
"""
if optimize:
opt_exp = self._optimize()
else:
opt_exp = self
typed_exp = self._typing()
typed_exp = opt_exp._typing()
comp_exp = typed_exp._compute()
if optimize:
opt_exp = typed_exp._optimize()
else:
opt_exp = typed_exp
comp_exp = opt_exp._compute()
if typed_exp == comp_exp:
typed_exp.set_ancestor(self._ancestor)