diff --git a/mapytex/calculus/API/__init__.py b/mapytex/calculus/API/__init__.py index 6c50b5b..837d669 100644 --- a/mapytex/calculus/API/__init__.py +++ b/mapytex/calculus/API/__init__.py @@ -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 diff --git a/mapytex/calculus/API/expression.py b/mapytex/calculus/API/expression.py index 01b91fa..90c7f21 100644 --- a/mapytex/calculus/API/expression.py +++ b/mapytex/calculus/API/expression.py @@ -202,13 +202,14 @@ class Expression(object): >>> f._ancestor """ - 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)