diff --git a/mapytex/calculus/API/__init__.py b/mapytex/calculus/API/__init__.py index 1b31d7d..7b77ce3 100644 --- a/mapytex/calculus/API/__init__.py +++ b/mapytex/calculus/API/__init__.py @@ -93,6 +93,19 @@ x^7 5 + 2x^2 + (3 + 5) * x 5 + 2x^2 + 8x +>>> e = Expression.from_str("(2x+3)^2") +>>> e_simplified = e.simplify() +>>> e_simplified + +>>> for s in e_simplified.explain(): +... print(s) +(2x + 3)^2 +(2x + 3)(2x + 3) +2x * 2x + 2x * 3 + 3 * 2x + 3 * 3 +2 * 2 * x^(1 + 1) + 3 * 2 * x + 3 * 2 * x + 9 +6x + 6x + 4x^2 + 9 +(6 + 6) * x + 4x^2 + 9 +12x + 4x^2 + 9 """ diff --git a/mapytex/calculus/API/expression.py b/mapytex/calculus/API/expression.py index 315b303..722d414 100644 --- a/mapytex/calculus/API/expression.py +++ b/mapytex/calculus/API/expression.py @@ -198,10 +198,10 @@ class Expression(object): :example: >>> e = Expression.from_str("2x", typing=False) - >>> print(e._tree.map_on_leaf(type)) + >>> print(e._tree.map_on_leaf(lambda x: type(x).__name__)) * - > - > + > MOnumber + > MOstr >>> typed_e = e._typing() >>> print(type(typed_e._tree)) @@ -210,21 +210,28 @@ class Expression(object): >>> e = Expression.from_str("2x+3+4/5", typing=False) - >>> print(e._tree.map_on_leaf(type)) + >>> print(e._tree.map_on_leaf(lambda x: type(x).__name__)) + > + | > * - | | > - | | > - | > + | | > MOnumber + | | > MOstr + | > MOnumber > / - | > - | > + | > MOnumber + | > MOnumber + >>> typed_e = e._typing() - >>> print(typed_e._tree.map_on_leaf(type)) + >>> print(e._tree.map_on_leaf(lambda x: type(x).__name__)) + - > - > + > + + | > * + | | > MOnumber + | | > MOstr + | > MOnumber + > / + | > MOnumber + | > MOnumber """ try: return Expression(self._tree.apply(typing)) diff --git a/mapytex/calculus/API/renders.py b/mapytex/calculus/API/renders.py index 7c87144..828206c 100644 --- a/mapytex/calculus/API/renders.py +++ b/mapytex/calculus/API/renders.py @@ -16,7 +16,7 @@ def _txt(mo_tree): """ txt render for MOs or Trees""" try: return tree2txt(mo_tree) - except AttributeError: + except ValueError: pass try: @@ -28,7 +28,7 @@ def _tex(mo_tree): """ Tex render for MOs or Trees""" try: return tree2tex(mo_tree) - except AttributeError: + except ValueError: pass try: diff --git a/mapytex/calculus/API/tokens/__init__.py b/mapytex/calculus/API/tokens/__init__.py index d9a6b43..6876a8f 100644 --- a/mapytex/calculus/API/tokens/__init__.py +++ b/mapytex/calculus/API/tokens/__init__.py @@ -10,7 +10,7 @@ Tokens represents MathObject at API level """ -from ...core.MO.mo import MO, MOnumber, MOstr +from ...core.MO import MO, MOnumber, MOstr from ...core.MO.fraction import MOFraction from ...core.MO.monomial import MOstrPower, MOMonomial from ...core.MO.polynomial import MOpolynomial diff --git a/mapytex/calculus/API/tokens/number.py b/mapytex/calculus/API/tokens/number.py index 6cb497d..1c37949 100644 --- a/mapytex/calculus/API/tokens/number.py +++ b/mapytex/calculus/API/tokens/number.py @@ -11,8 +11,7 @@ Tokens representing interger and decimal """ from .token import Token -from ...core.MO import MO -from ...core.MO.mo import MOnumber +from ...core.MO import MO, MOnumber from ...core.MO.fraction import MOFraction from decimal import Decimal as _Decimal